You need to sign in to do that
Don't have an account?
theitdeptrocks
How to create a record and grab the new record ID
I am creating a questionnaire in which a record is created after the completion of page one. Upon clicking "Next" the record is checked for validation errors, if none it saves and if there are then the page displays those erros. On multiple page questionnaires, I'm not sure how to grab the ID of the record created on page one so it can be updated with the responses from questions located on page 2.
Here is the code I am using:
public PageReference doSave() { try { this.ctr.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('url of page 2'); } }
Any ideas?
using the above example, your page Refrence would look like this:
All Answers
After insert the object you can grab the ID with object.Id
Ant then you can give that Id to the second page for example with GET
Hope this helps,
Bruno
using the above example, your page Refrence would look like this:
Thanks to both of you. It is working for me.
Hi all,
i get the following exception
below is the code that i am writing
Please help me solve the issue.
Hi Giribabu,
The exception thrown has to do with that field level-security.
You have to access through your org to that objects field properties
"9. Go to Setup > Customize, select a tab, click Fields, select a field, and click View FieldAccessibility to check the field accessibility to verify that all field access settings are correct."
https://na1.salesforce.com/help/doc/en/salesforce_pagelayouts_cheatsheet.pdf
There you can find some more information.
Hope this helps,
Bruno