function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SaintMichaelSaintMichael 

getting created record id

I want to use my CMSForce form to create a new record.

Is there anyway for me to get the Id for the just created record?

 

Im thinking use CMSForce for the 'basic' form fields then forward the Id to another page with

more custom form items to finish the process.

Best Answer chosen by Admin (Salesforce Developers) 
David VPDavid VP

You're very close to the solution !

The only problem is that you're modifying the code in the wrong place (FormController is for inclusion of forms on external sites).

 

Put your code in the RenderFormComponentController class and you should be good to go.

All Answers

SaintMichaelSaintMichael

I looked at the source code and I see the FormController class has a saveObject method.

In that method there is a reference to the return url field called Return_URL__c.

 

I am getting the record id of the created object using:

 

insert sobjectInstance;
String id = sobjectInstance.Id;

 

I tried appending this id to the return url, but it doesnt work.

Seems the only place I can affect the return url string is

by editing the the 'Return Url' field in the web form editor.

 

Why I am not able to modify the return url in the FormController class?

Is there anyway for me to programmatically modify the return url, on the fly?

 

 

Here is what I would like to try:

 

 

String result = sobjectInstance.Id;
String retUrl = form.Return_URL__c+'recid='+result;

or

String result = sobjectInstance.Id;
String retUrl = form.Return_URL__c+'recid='+result;
PageReference pr =  new PageReference(retUrl);  

pr.getParameters().put('recid',result);

//then 

return pr;

 

 

 

David VPDavid VP

You're very close to the solution !

The only problem is that you're modifying the code in the wrong place (FormController is for inclusion of forms on external sites).

 

Put your code in the RenderFormComponentController class and you should be good to go.

This was selected as the best answer
SaintMichaelSaintMichael

David, whew!

Thank you! Thought I was losing it there for a bit.

 

I'm like "If I edit and changes don't show, I must be way off!" lol

 

:manhappy: