You need to sign in to do that
Don't have an account?
Save and Redirect If No PageMessages
I'm a newbie to controllers but I compiled the following controller from various posts on the board, to use on a custom object on a force.com site. After the user clicks a command button to save the form, I want SF to check for errors (using the <apex:PageMessages /> tag) and if no errors, save the form and redirect to www.tarl.com. If there are errors, then I want the standard error messages to show and stay on the page.
The controller fails the deployment and I don't know enough about controllers to identify the problem. If someone could please help me, I would greatly appreciate it...and Kudos!
Thank you in advance!
public class SaveAndRedirectController { public ApexPages.StandardController controller; public SaveAndRedirectController(ApexPages.StandardController controller) { this.controller = controller; } public PageReference SaveAndRedirect() { try { this.controller.Save(); } catch(DmlException ex){ //this catches the errors and ensures they register on the page ApexPages.addMessages(ex); } //if there's an error message, perform a refresh // if not, redirect to google.com if (ApexPages.hasMessages()) { return null; } else { return new PageReference('http://www.tarl.com'); } } }
The problem is that no exception will be thrown using StandardController.save(). Instead, you have to check its return value:
HI
You need to write test class for deployment and code coverage should be 75%
I am sharing some link about test class,please go through it .
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_test.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_example.htm
http://boards.developerforce.com/t5/Apex-Code-Development/Test-Class-for-a-StandardController-Extension/td-p/189828
When your code coverage will be more then 75% then you can definitely deploy your class
If this post answers your question please mark it asl solved and give kudos for this post
Thanks
Thank you sfdcfox, but that failed also. Here is my complete code.
Sorry, change save() to saveAndRedirect(), that should be okay.
Sorry, but that failed also. It is at 71% coverage. Any other ideas?
asish1989, I have created several extensions to sort tables and grab small sets of data and I have never had to create a test class for them to deploy properly. The inbound change set runs the test and it deploys automatically.