You need to sign in to do that
Don't have an account?
Help with adding validation in a Apex page
public pagereference save1(){ if(vac.Advertise__c == true){ list<RPaaS_Stage_Library__c> lib = [select id from RPaaS_Stage_Library__c where RpaasVacancy__c =:vac.id and category__c='Qualifying']; if(!(lib.size()>0)) ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'There are no qualifying stages on this job. Therefore job cannot be advertised.')); list<RPaaS_Stage_Library__c> lib1 = [select id,StageName__c from RPaaS_Stage_Library__c where RpaasVacancy__c =:vac.id ]; system.debug('++++'+lib1.size()+'$$$$'+lib1); set<string>libstring=new set<string>(); for(RPaaS_Stage_Library__c s:lib1){ libstring.add(s.StageName__c ); } if(libstring.size()<4){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'One of the qualifying stages are missing please check all 4 qualifying stages are added for this job.')); } } upsert vac; pagereference page = new pagereference('/apex/RPaaSVacancyTab'); page.setRedirect(true); return page;
I have to make the custom error messages appear in the top of the screen if there is records in the object RPaaS_Stage_Library__c related to its master record from the object RpaasVacancy__c.. I have to display the second error if the sring set libstring does not have 4 values in it. If it meets these two criteries we have to upsert a master list and do page redirection to a specific page listed in the code. I am unable to make the error messages appear in the click of the button . and dml upsert also not done aong with page redirection if the criteria meets. I checked the conditions given for error messages it is working fine if i use that in other componets say Apex action support event in a check box...but i dont know how to do this with a button action please help...please note that this entire operation of error checking have to be done if the check box is true.
if(vac.Advertise__c == true)
If it is not true then i have to just upsert the record.
I used method chaning concept to solve this posted below the code for reference
I forgot to instanciate the page reference variable and later I passed its null value in error statements.Using the combinations of various if else conditions I am able to acheive this. Thank you folks
All Answers
Hi,
Check that you have a apex:message in your origin visualforce page. Then try adding something like this after
return null will display again your visual force and add message to it
Antoine
ur using if loop to throw error but to show them it has to be page reference do like this
if(error){
add page message;
return null;
}
else{
logig
return actual page ref
}
use else if for multiple conditions or errors
Can we do this use mehod chaining....i have created three different methods each for displaying error, upserting record and page redirection respectively like this.method name but still nt working. Can u provide me with the working code. thanks in Advance.
I used method chaning concept to solve this posted below the code for reference
I forgot to instanciate the page reference variable and later I passed its null value in error statements.Using the combinations of various if else conditions I am able to acheive this. Thank you folks