You need to sign in to do that
Don't have an account?
imishra
Stop redirecting visualforce page if error is there.-urgent
Hi,
I have an object Closure(Custom Object) which is child of Opportunity.
I have a roll up summary field on Opportunity to count the no of closure and based on that a trigger which prevents a user to create more than one closure per opportunity and i have an error message on the trigger.
After saving the closure for the 1st time it should redirect to Opportunity record, but for second time on save, it should display the error message.
My save code is:
public PageReference saveAndReturn(){
PageReference cancel = controller.cancel();
controller.save();
return cancel;
}
Please help me to get this.
Thanks,
Ipsita
I have an object Closure(Custom Object) which is child of Opportunity.
I have a roll up summary field on Opportunity to count the no of closure and based on that a trigger which prevents a user to create more than one closure per opportunity and i have an error message on the trigger.
After saving the closure for the 1st time it should redirect to Opportunity record, but for second time on save, it should display the error message.
My save code is:
public PageReference saveAndReturn(){
PageReference cancel = controller.cancel();
controller.save();
return cancel;
}
Please help me to get this.
Thanks,
Ipsita
I m not sure how you implemented your SAVE method.. but if its throwing the error on saving second time , then you can do this
I guess i was not clear with my requirement.
On save it is getting redirected.
But i want to stop the redirection if there is any error message on the page.
While creating the second record, it should disply the error message, but it is getting redirected there also. So for the second record i want to stop this redirection.
You can achieve that by this way.
public PageReference/Void/sobject getmethod(){
pageReference page = new pageReferece('\apex\------');
try
{
//////////////save code
}
catch(Exception e){
ApexPages.addMessages(e);
}
return ApexPages.hasMessages() ? null : page/URL/Record;
}
If error occurs in try then catch block will add the error message in VF page.
In return we are returning the pageReference if page is not having any messages.
Mark this as solution if you got an answer,
Thanks,
Praveen Murugesan
On click of this, it should redirect me to the opportunity detail page.
Please reply. Its very urgent.
Sry for the delay. Yes you need to create
public PageReference saveAndReturn(){
PageReference cancel;
try
{
cancel = controller.cancel();
controller.save();
}
catch(Exception e){
ApexPages.addMessages(e);
}
return ApexPages.hasMessages() ? null : cancel; // Here we are returning to cancel if there is no error message.
}
}