Add Custom Error Message to VF Page

The name of the pictureThe name of the pictureThe name of the pictureClash 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;








share|improve this question


















  • 1




    I would advise <apex:pageMessages/>
    – gNerb
    Aug 14 at 15:13
















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;








share|improve this question


















  • 1




    I would advise <apex:pageMessages/>
    – gNerb
    Aug 14 at 15:13












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;








share|improve this question














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;










share|improve this question













share|improve this question




share|improve this question








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












  • 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










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"/>





share|improve this answer




















  • 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

















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.






share|improve this answer


















  • 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










  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "459"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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"/>





share|improve this answer




















  • 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














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"/>





share|improve this answer




















  • 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












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"/>





share|improve this answer












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"/>






share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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












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.






share|improve this answer


















  • 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










  • 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














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.






share|improve this answer


















  • 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










  • 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












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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 14 at 15:25

























answered Aug 14 at 15:07









Jason Benkert

1,229720




1,229720







  • 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










  • 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




    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







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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

Confectionery