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
GobbledigookGobbledigook 

Passing Parameters with URLFOR for Standard Page.New

Hello all,

 

I am working on an Object and I've added a Custom Button to a page layout that will redirect to another Standard Page Layout of a Custom Object.  I'm trying to figure out a way to autopopulate the fields (using the [Param = "value"]) in Reference to the fields from the previous page. 

 

SO this is what I want:

1. User is on Page1  (From here we'll call it "First")

2. User clicks Custom Button to be sent to Page2 ("Second")  using URLFOR in a standard Formula field (I'm trying to do this WITHOUT using Visualforce)

3. Second.Summary__c is pre-populated with First.Summary__c. 

 

Here is my Code, the Second page is loading correctly, but the parameter is not passing.

 

 

{!URLFOR($Action.Second.New,   $ObjectType.Second ,  [ Second.Summary__c  =  First.Summary__c],false  )}

 

Any ideas?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SteveBowerSteveBower

Just to clarify, you want a button on the first custom object that will create a new instance of the second custom object.  At the same time it will pass some custom field values to the newly created record.

 

If that's all you want, define a button on the first record as such:

 

(In this example, I have two custom objects, A and B, both with an X1 field.)

 

/a0R/e?00N60000001qVKk= {!A__c.X1__c}&save=1

 

where:

 

a0R is the three letter prefix for the B custom object.

00N60000001qVKk is the HTML Id of the X1 <input> tag when you inspect the HTML of a standard B Edit page.

 

Best, Steve.

 

 

All Answers

ca_peterson_oldca_peterson_old

Sadly there's no supported way to do this. Got confirmation over twitter from a number of people including a PM from salesforce: http://twitter.com/#!/mtbclimber/status/28725080349

SteveBowerSteveBower

Just to clarify, you want a button on the first custom object that will create a new instance of the second custom object.  At the same time it will pass some custom field values to the newly created record.

 

If that's all you want, define a button on the first record as such:

 

(In this example, I have two custom objects, A and B, both with an X1 field.)

 

/a0R/e?00N60000001qVKk= {!A__c.X1__c}&save=1

 

where:

 

a0R is the three letter prefix for the B custom object.

00N60000001qVKk is the HTML Id of the X1 <input> tag when you inspect the HTML of a standard B Edit page.

 

Best, Steve.

 

 

This was selected as the best answer
dwatsondwatson

URLFOR() doesn't convert fields on an object to the custom field ID used to reference the input area in the HTML.  You would need to replace Second.Summary__c with the ID in the <input> tag you find in the HTML for it to work.  

GobbledigookGobbledigook

Thanks for your replies. 

 

That workaround is just ugly.  Especially since you'd have to reference the Ids of each custom field of the custom object. 

 

The thing that's really bugging me about such an ugly workaround is that it actually exists in standard functionality.  For example, when someone clicks a New Contact off of a related account, the Account field is pre-populated.  This is exactly what I'm looking for, but with custom objects.  The fact that it's not available when it's done for multiple other instances around the CRM is just odd.   Not to mention the fact that URLFOR accepts parameters to be passed through.  It just doesn't DO anything with them, unless you use a direct Id reference, which is fragile at best. 

 

The fact that URLFOR was released about 60% complete is kind of entertaining, though.

 

Edit:  After looking at it again, it looks like the Standard Functionality isn't really that standard at all; it was done via Visualforce.  So Mr. Developer... how were you able to get this done?  It'd be interesting to see an official workaround that was done. 

dwatsondwatson

URLFOR() does convert object references to be relative to your organization.  So $Action.Second.New is relative depending on whatever object ID it gets when it's installed in your org.  But maybe that's the 60% you are referring to.  

 

You can use merge fields as the parameters passed in URLFOR(), which also means you can use custom settings.   That would allow you to at least set the custom setting to a field ID appropriate for your org.  Then just have the params in URLFOR() reference that custom setting.  (Note currently you have to make the custom setting public if your package is managed).  At least then no modifications are needed to be made to the button or wherever you use URLFOR().