Add Custom Error Message to VF Page
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I am trying to add a custom error message to a VF page. My controller saves, but when I save my VF page without the checkbox field being checked, it saves anyway and bypasses the error condition in my controller. What am I doing wrong?
VF Page:
<apex:page standardController="Quote__c" extensions="QuoteExtController">
<apex:messages/>
<apex:form >
<apex:commandButton value="Save" action="!save"/>
<apex:pageblock>
Quote Name: <apex:InputField value="!Quote__c.Name"/>
Quote Check: <apex:InputField value="!Quote__c.Must_Be_Checked__c"/>
</apex:pageblock>
</apex:form>
</apex:page>
Controller Extension:
public with sharing class QuoteExtController
private quote__c quote;
public QuoteExtController(ApexPages.StandardController stdController)
this.quote = (Quote__c)stdController.getRecord();
public PageReference onSave()
if(quote.Must_Be_Checked__c==TRUE)
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Check field');
ApexPages.addMessage(myMsg);
return null;
else if (quote.Id != null)
insert quote;
return null;
visualforce controller-extension
add a comment |Â
up vote
1
down vote
favorite
I am trying to add a custom error message to a VF page. My controller saves, but when I save my VF page without the checkbox field being checked, it saves anyway and bypasses the error condition in my controller. What am I doing wrong?
VF Page:
<apex:page standardController="Quote__c" extensions="QuoteExtController">
<apex:messages/>
<apex:form >
<apex:commandButton value="Save" action="!save"/>
<apex:pageblock>
Quote Name: <apex:InputField value="!Quote__c.Name"/>
Quote Check: <apex:InputField value="!Quote__c.Must_Be_Checked__c"/>
</apex:pageblock>
</apex:form>
</apex:page>
Controller Extension:
public with sharing class QuoteExtController
private quote__c quote;
public QuoteExtController(ApexPages.StandardController stdController)
this.quote = (Quote__c)stdController.getRecord();
public PageReference onSave()
if(quote.Must_Be_Checked__c==TRUE)
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Check field');
ApexPages.addMessage(myMsg);
return null;
else if (quote.Id != null)
insert quote;
return null;
visualforce controller-extension
1
I would advise<apex:pageMessages/>
â gNerb
Aug 14 at 15:13
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am trying to add a custom error message to a VF page. My controller saves, but when I save my VF page without the checkbox field being checked, it saves anyway and bypasses the error condition in my controller. What am I doing wrong?
VF Page:
<apex:page standardController="Quote__c" extensions="QuoteExtController">
<apex:messages/>
<apex:form >
<apex:commandButton value="Save" action="!save"/>
<apex:pageblock>
Quote Name: <apex:InputField value="!Quote__c.Name"/>
Quote Check: <apex:InputField value="!Quote__c.Must_Be_Checked__c"/>
</apex:pageblock>
</apex:form>
</apex:page>
Controller Extension:
public with sharing class QuoteExtController
private quote__c quote;
public QuoteExtController(ApexPages.StandardController stdController)
this.quote = (Quote__c)stdController.getRecord();
public PageReference onSave()
if(quote.Must_Be_Checked__c==TRUE)
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Check field');
ApexPages.addMessage(myMsg);
return null;
else if (quote.Id != null)
insert quote;
return null;
visualforce controller-extension
I am trying to add a custom error message to a VF page. My controller saves, but when I save my VF page without the checkbox field being checked, it saves anyway and bypasses the error condition in my controller. What am I doing wrong?
VF Page:
<apex:page standardController="Quote__c" extensions="QuoteExtController">
<apex:messages/>
<apex:form >
<apex:commandButton value="Save" action="!save"/>
<apex:pageblock>
Quote Name: <apex:InputField value="!Quote__c.Name"/>
Quote Check: <apex:InputField value="!Quote__c.Must_Be_Checked__c"/>
</apex:pageblock>
</apex:form>
</apex:page>
Controller Extension:
public with sharing class QuoteExtController
private quote__c quote;
public QuoteExtController(ApexPages.StandardController stdController)
this.quote = (Quote__c)stdController.getRecord();
public PageReference onSave()
if(quote.Must_Be_Checked__c==TRUE)
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Check field');
ApexPages.addMessage(myMsg);
return null;
else if (quote.Id != null)
insert quote;
return null;
visualforce controller-extension
edited Aug 14 at 15:14
gNerb
4,689533
4,689533
asked Aug 14 at 14:58
J. Neilan
5091621
5091621
1
I would advise<apex:pageMessages/>
â gNerb
Aug 14 at 15:13
add a comment |Â
1
I would advise<apex:pageMessages/>
â gNerb
Aug 14 at 15:13
1
1
I would advise
<apex:pageMessages/>
â gNerb
Aug 14 at 15:13
I would advise
<apex:pageMessages/>
â gNerb
Aug 14 at 15:13
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
5
down vote
accepted
Your command button is calling the standard controller save. You need to use your custom action in the save button, shown below:
<apex:commandButton value="Save" action="!onSave"/>
Thanks, that was the issue. I knew it was going to be some dumb error on my part.
â J. Neilan
Aug 14 at 15:45
2
I've been there too - sometimes you just need an extra set of eyes!
â battery.cord
Aug 14 at 17:01
add a comment |Â
up vote
0
down vote
It's because you're using Quote__c
in your page, and not your quote
page property.
Change your VF markup to use this:
<apex:pageblock >
Quote Name: <apex:InputField value="!quote.Name"/>
Quote Check: <apex:InputField value="!quote.Must_Be_Checked__c"/>
</apex:pageblock>
And finally, make sure you're calling your custom onSave
method and not the standard Save method.
2
That call toaddFields
is not valid syntax.Quote__c
andQuote
as shown here are referring to the same object instance, which should have those fields populated due to their use in the body of the Visualforce page.
â David Reed
Aug 14 at 15:15
I agree it's kinda weird that they are using a custom object for quote but I don't think that's the root of the issue and there very well may be a reason for it. I'd advise sticking to the topic at hand.
â gNerb
Aug 14 at 15:16
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
Your command button is calling the standard controller save. You need to use your custom action in the save button, shown below:
<apex:commandButton value="Save" action="!onSave"/>
Thanks, that was the issue. I knew it was going to be some dumb error on my part.
â J. Neilan
Aug 14 at 15:45
2
I've been there too - sometimes you just need an extra set of eyes!
â battery.cord
Aug 14 at 17:01
add a comment |Â
up vote
5
down vote
accepted
Your command button is calling the standard controller save. You need to use your custom action in the save button, shown below:
<apex:commandButton value="Save" action="!onSave"/>
Thanks, that was the issue. I knew it was going to be some dumb error on my part.
â J. Neilan
Aug 14 at 15:45
2
I've been there too - sometimes you just need an extra set of eyes!
â battery.cord
Aug 14 at 17:01
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
Your command button is calling the standard controller save. You need to use your custom action in the save button, shown below:
<apex:commandButton value="Save" action="!onSave"/>
Your command button is calling the standard controller save. You need to use your custom action in the save button, shown below:
<apex:commandButton value="Save" action="!onSave"/>
answered Aug 14 at 15:07
battery.cord
6,25951742
6,25951742
Thanks, that was the issue. I knew it was going to be some dumb error on my part.
â J. Neilan
Aug 14 at 15:45
2
I've been there too - sometimes you just need an extra set of eyes!
â battery.cord
Aug 14 at 17:01
add a comment |Â
Thanks, that was the issue. I knew it was going to be some dumb error on my part.
â J. Neilan
Aug 14 at 15:45
2
I've been there too - sometimes you just need an extra set of eyes!
â battery.cord
Aug 14 at 17:01
Thanks, that was the issue. I knew it was going to be some dumb error on my part.
â J. Neilan
Aug 14 at 15:45
Thanks, that was the issue. I knew it was going to be some dumb error on my part.
â J. Neilan
Aug 14 at 15:45
2
2
I've been there too - sometimes you just need an extra set of eyes!
â battery.cord
Aug 14 at 17:01
I've been there too - sometimes you just need an extra set of eyes!
â battery.cord
Aug 14 at 17:01
add a comment |Â
up vote
0
down vote
It's because you're using Quote__c
in your page, and not your quote
page property.
Change your VF markup to use this:
<apex:pageblock >
Quote Name: <apex:InputField value="!quote.Name"/>
Quote Check: <apex:InputField value="!quote.Must_Be_Checked__c"/>
</apex:pageblock>
And finally, make sure you're calling your custom onSave
method and not the standard Save method.
2
That call toaddFields
is not valid syntax.Quote__c
andQuote
as shown here are referring to the same object instance, which should have those fields populated due to their use in the body of the Visualforce page.
â David Reed
Aug 14 at 15:15
I agree it's kinda weird that they are using a custom object for quote but I don't think that's the root of the issue and there very well may be a reason for it. I'd advise sticking to the topic at hand.
â gNerb
Aug 14 at 15:16
add a comment |Â
up vote
0
down vote
It's because you're using Quote__c
in your page, and not your quote
page property.
Change your VF markup to use this:
<apex:pageblock >
Quote Name: <apex:InputField value="!quote.Name"/>
Quote Check: <apex:InputField value="!quote.Must_Be_Checked__c"/>
</apex:pageblock>
And finally, make sure you're calling your custom onSave
method and not the standard Save method.
2
That call toaddFields
is not valid syntax.Quote__c
andQuote
as shown here are referring to the same object instance, which should have those fields populated due to their use in the body of the Visualforce page.
â David Reed
Aug 14 at 15:15
I agree it's kinda weird that they are using a custom object for quote but I don't think that's the root of the issue and there very well may be a reason for it. I'd advise sticking to the topic at hand.
â gNerb
Aug 14 at 15:16
add a comment |Â
up vote
0
down vote
up vote
0
down vote
It's because you're using Quote__c
in your page, and not your quote
page property.
Change your VF markup to use this:
<apex:pageblock >
Quote Name: <apex:InputField value="!quote.Name"/>
Quote Check: <apex:InputField value="!quote.Must_Be_Checked__c"/>
</apex:pageblock>
And finally, make sure you're calling your custom onSave
method and not the standard Save method.
It's because you're using Quote__c
in your page, and not your quote
page property.
Change your VF markup to use this:
<apex:pageblock >
Quote Name: <apex:InputField value="!quote.Name"/>
Quote Check: <apex:InputField value="!quote.Must_Be_Checked__c"/>
</apex:pageblock>
And finally, make sure you're calling your custom onSave
method and not the standard Save method.
edited Aug 14 at 15:25
answered Aug 14 at 15:07
Jason Benkert
1,229720
1,229720
2
That call toaddFields
is not valid syntax.Quote__c
andQuote
as shown here are referring to the same object instance, which should have those fields populated due to their use in the body of the Visualforce page.
â David Reed
Aug 14 at 15:15
I agree it's kinda weird that they are using a custom object for quote but I don't think that's the root of the issue and there very well may be a reason for it. I'd advise sticking to the topic at hand.
â gNerb
Aug 14 at 15:16
add a comment |Â
2
That call toaddFields
is not valid syntax.Quote__c
andQuote
as shown here are referring to the same object instance, which should have those fields populated due to their use in the body of the Visualforce page.
â David Reed
Aug 14 at 15:15
I agree it's kinda weird that they are using a custom object for quote but I don't think that's the root of the issue and there very well may be a reason for it. I'd advise sticking to the topic at hand.
â gNerb
Aug 14 at 15:16
2
2
That call to
addFields
is not valid syntax. Quote__c
and Quote
as shown here are referring to the same object instance, which should have those fields populated due to their use in the body of the Visualforce page.â David Reed
Aug 14 at 15:15
That call to
addFields
is not valid syntax. Quote__c
and Quote
as shown here are referring to the same object instance, which should have those fields populated due to their use in the body of the Visualforce page.â David Reed
Aug 14 at 15:15
I agree it's kinda weird that they are using a custom object for quote but I don't think that's the root of the issue and there very well may be a reason for it. I'd advise sticking to the topic at hand.
â gNerb
Aug 14 at 15:16
I agree it's kinda weird that they are using a custom object for quote but I don't think that's the root of the issue and there very well may be a reason for it. I'd advise sticking to the topic at hand.
â gNerb
Aug 14 at 15:16
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f228859%2fadd-custom-error-message-to-vf-page%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
I would advise
<apex:pageMessages/>
â gNerb
Aug 14 at 15:13