Mergefield syntax to dynamically populate SObject Id (recordtype selection page redirect)

  • 1
  • Question
  • Updated 5 years ago
  • Answered
I am implementing a redirect action from a table component that will take the user to the recordtype selection page in order to create a new object with standard SFDC UI. I have constructed the below Url and it works fine.

Question: Is there any mergefield syntax that I can use to avoid hardcoding the SObject Id in the Url, otherwise this adds a cumbersome manual step during migration to replace the Id based on the target org. (Note, this is not an Id of a given record, but an Id of the SObject itself)

/setup/ui/recordtypeselect.jsp?ent=01IG0000001s8EL&retURL=%2F{{Model.KeyPrefix}}%2Fo
&save_new_url=%2F{{Model.KeyPrefix}}%2Fe%3FretURL=%2F{{Model.KeyPrefix}}%2Fo

Decoded Url:
/setup/ui/recordtypeselect.jsp?ent=01IG0000001s8EL&retURL=/{{Model.KeyPrefix}}/o
&save_new_url=/{{Model.KeyPrefix}}/e?retURL=/{{Model.KeyPrefix}}/o

Thanks in advance.
Photo of AndreyVol

AndreyVol

  • 450 Points 250 badge 2x thumb

Posted 5 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 48,984 Points 20k badge 2x thumb
Hi Andrey,

Unfortunately, SObject Ids are not exposed anywhere in Salesforce's API, so there's no merge variable we can provide which will allow this to be possible.

However, there is a workaround. If you create a very basic Visualforce Page, you can leverage the Visualforce $Action global variable to generate this URL. You can then point to this URL from your Table redirect Action, e.g.

1. Create a VF page named "NewTechReviewRedirect", with its body equal to


<apex:page action="{!URLFOR($Action.ISV_Tech_Review__c.New)}"/>


(using the API name of your object, of course)

2. Use this URL in your Table redirect action:

URL: "/apex/NewTechReviewRedirect"

Assuming that your ISV Tech Review object has RecordTypes, and that the user does not have a default Record Type selected, this should send you to the RecordType Selection step first, and then to the corresponding object's New page.
Photo of AndreyVol

AndreyVol

  • 450 Points 250 badge 2x thumb
Thanks Zach, I will try this workaround.