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
RHILLRHILL 

Passing fields through URL past the record type.

I want to carry fields from a parent object to the child object when the user clicks the new button.
 
I have created a URL to update the code.  I put it on a seperate button called update and it works after the record has been created but now I want it to work when a new one is created.
 
What code do I use to override the next step of selecting the proper record type? 
 
I want the user to still select the record type then when they get to the edit screen have the fields populated.
Greg HGreg H
You can override the New button with an sControl.  The user will be prompted to select a recordtype prior to your sControl being run.  You should still be able to pass the parameters you need in the URL. Just make sure you include the parameter "&nooverride=1" as this will prevent your sControl from infinitely looping.
-greg
RHILLRHILL

Thanks for the reply, but still not working properly

 

Here is the URL "new" button override

https://na2.salesforce.com/{!Comp_Pricing__c.Id}/e?retURL=%2F{!Comp_Pricing__c.Id}

&CF00N40000001VEFB={!Asset.Account}
&CF00N40000001VEFB_Lkid={!Asset.AccountId}
&CF00N40000001VEPp={!Product2.Name}
&CF00N40000001VEPp_lkid={!Product2.Id}
&nooverride=1

What it does is enter a new screen within a screen...and not pass the data through

 

 

 

KringoKringo
I had been looking for a way to do this as well. Unfortunately I never found one that did exactly what I wanted.

I settled for making a button for each record type. Then created buttons on the page I wanted to create the record from. These buttons  fired a specific scontrol that set the record type and filled in the necessary information.

It does work quite well as it eliminates the record select screen and presents the record type choices side by side on the related list.
RHILLRHILL

Kringo,

 

I tried doing that as well but found no success.  Could you please share the code you used on the buttons to pass through the record type?  Was it a URL or HTML code?

 

Rob

Greg HGreg H
You can pass the recordtype value to bypass the recordtype selection screen but if you want to append multiple values after the recordtype selection you can do something like this:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
 <title>Button Override</title>
<script language="JavaScript" type="text/javascript">
<!--
//initiates the page
function pInit() {
 var url = parent.location.href; //URL accessing sControl
 url += "&000000000000000={!Object.Field1}"; //append a parameter
 url += "&000000000000001={!Object.Field2}"; //append a parameter
 url += "&nooverride=1"; //pass nooverride parameter to prevent infinite reloading of page
 parent.location.href = url; //pass full URL to page (refresh)
}
//-->
</script>
</head>
<body onload="pInit()">
<div>Loading...</div>
</body>
</html>

Hope this can assist you further,
-greg
RHILLRHILL

That was the magic I was looking for, worked perfectly.

Thanks all for your help

Saurabh DhobleSaurabh Dhoble

For anyone coming across this, you can refer to this post to get a better understanding of how the URL is getting constructed.

NeilJWNeilJW
Here is an answer to the original question without using an s-control. It involves URL encoding but the trick is only specific parts of the URL need to be URL encoded. 

In order to have the user first go to the record type selection page  you must direct the user to the page with your URL:

/setup/ui/recordtypeselect.jsp? // This is the URL portion needed to tell salesforce to go to the record type selector page.

ent=Contact //ent is the parameter needed to tell salesforce which object we are selecting record type for. For standard objects you can put the object name. For custom objects you can put the objects SF ID in place of the word Contact.

&retURL=%2Fa1PK0000001SIr5 //This is the id of the record to return to if the user cancels from the record type selection page. Note that there is a %2F in front of the ID. The  %2F is the URL code for /.

&save_new_url=%2Fa0A%2Fe%3F //This is the place to go if the user clicks save. It is URL encoded and is the equivalent of /a0A/e?. In other words the edit page for the new record which is where we want them to go after choosing the record type.

Then we need to add some additional parameters that get passed to the edit page. This is all also part of the "save_new_url" and as such needs to be URL encoded with the exception of the field references that you want Salesforce to calculate and then pass through.

%26CF00NA0000001Zlbs%3D{!Account.Name} // The %26 is the equivalent of &. Then we have CF to indicate we are passing an ID for a field. Then we have the field ID. Then we have the %3D which is the equivalent of =. Last we have the reference to the field we want to pass. Note that the field is NOT url encoded because we want the value to be calculated and then passed to the edit page. If we try to URL encode that value it will pass the text "!Account.Name" which is not what we want. This value is actually what is displayed on screen in the box but we also need the ID to be passed to create the link.

%26CF00NA0000001Zlbs_lkid%3D{!Account.Id} // Again we have %26 for &, CF to indicate field, the field ID, but then we have _lkid. This indicates that we are passing in the ID to the indicated field. The previous parameter passed the display on screen name while this one is passing the ID to create the actual link. Then again the %3D for = and the NOT URL encoded reference to the Account id.

%26retURL%3D{!Account.Id} // For a proper URL we should also pass in what to do when the user has finished editing. We have 3 primary options: retURL, saveURL, cancelURL. I'm a little fuzzy on what retURL does but it seems to be a catch all for what happens when the user leaves the current page without specifically directing salesforce where to go next. The retURL will direct the user to the ID for whatever object is specified.

%26saveURL%3D{!Account.Id} // The saveURL specifies what to do on save only. If not specified it seems the retURL will be used if available. 

%26cancelURL%3D{!Account.Id} // The cancelURL specifies what to do on cancel only. If not specified it seems the retURL will be used if available.

There is a handy tool at this site to help with encoding/decoding URL data:
http://meyerweb.com/eric/tools/dencoder/
{tushar-sharma}{tushar-sharma}
Now URL hack is supported in Lightning Experience. You can Set recordType and other fields (Date, DateTime), Clone record as well. Check below post for detail and code sample: 
https://newstechnologystuff.com/2020/06/03/salesforce-url-hack-in-lightning/