+ Start a Discussion
Jeff C.ax327Jeff C.ax327 

Custom "New" button that pre-selects the RecordType

We have several RecordTypes for our Contacts.  For our "Study Contact" page layout, all the appropriate detail fields are there, and we have a related list that shows Contacts that the current Contact has referred to us.  I want to hide the default New button on this related list and replace it with a "New Referral" button.  Clicking the "New Referral" button should invoke the New action, but set the RecordType to "Study Contact" behind the scenes and bypass the "Select Contact Record Type" page.
 
I have looked everywhere for examples, and managed to put together the following... but it still shows the "Select Contact Record Type" page.   I am putting the RecordType parameter in the parameter array and also including it directly on the URL just in case....  Help?
 
Code:
//First construct the new URL
var newUrl = "{!URLFOR( $Action.Contact.NewContact, null,
[RecordType=Contact.RecordType,
CF00N70000002GKJz_lkid=Contact.Id,
con4_lkid=Account.Id,
retURL=$Request.retURL], true)}&RecordType={!Contact.RecordType}";
//Then redirect the user to it
window.parent.location.replace(newUrl);

This is run in an Execute Javascript button.
I have tried putting the RecordTypeId value in there directly too (rather than use Contact.RecordType), but to no avail.
I'm also trying to automatically link the new Contact with the referrer Contact, and trying to pre-populate the Account ID.
 
Thank you for your help,
Jeff

 
Nazeer AhamedNazeer Ahamed

RecordType=yourRecordTypeId

Find RecordTypeId in URL, https://na5.salesforce.com/setup/ui/recordtypefields.jsp?id=0127X0400909X60&type=Account&setupid=AccountRecords

Jeff C.ax327Jeff C.ax327

Thank you for your reply, Nazzy.
I have discovered that using the URLFOR( ) function on the $Action.Contact.NewContact action does not work no matter which parameters I try.  The URL that is returned by the function is a direct reference to the "Select Contact Record Type" page, and if I try to send the RecordTypeId in the id parameter for that page, I receive the "Insufficient Privileges" message.

I have figured out the solution to what I've been trying to accomplish and am posting it here so that it might help others who are attempting similar functionality.

Again, the goal was to create a list button on a related list of contacts (children of the parent contact currently in detail view) and force the RecordTypeId so that the "Select Contact Record Type" page would not be displayed.  Secondly, I wanted to pre-populate the Account and the ReferredBy__c (parent contact lookup field) with those of the parent contact.

I was initially using a Javascript On Click button, which is what I had to do to get the Cookbook example code to work.  Now, however, I am using a URL button instead.  After examining the URL and HTML source of a default "new contact" page, I was able to override all of the values in question.  Here is the URL with the appropriate merge fields:

/003/e?ent=Contact&RecordType={! Contact.RecordTypeId }&CF00N70000002GKJz_lkid={! Contact.Id }&CF00N70000002GKJz={! Contact.Name }&con4_lkid={! Account.Id }&con4={! Account.Name }&con19street=&con19city=&con19state=&con19zip=&con10=&con14=&retURL=%2F{! Contact.Id }

Let me explain what all of this is for (and ask questions for things that I do not fully understand).

/003/e?     -- "003" is apparently the id for the Contact object and the /e puts the page in edit mode

ent=Contact     -- this seems to be another contact entity reference, but everything seems to still work if I remove it from the parameter list.  Is this important?

RecordType={! Contact.RecordTypeId }     -- forcing the RecordTypeId

CF00N70000002GKJz_lkid={! Contact.Id }   -- hidden lkid field for RefferredBy__c contact reference

CF00N70000002GKJz={! Contact.Name }      -- textbox that displays the name of the ReferredBy contact

con4_lkid={! Account.Id }     -- hidden lkid field for the Account reference

con4={! Account.Name }        -- textbox that displays the name of the Account

con19street=     -- by pre-populating the Account, the address fields and phone numbers etc. from the account are carried forward into the new contact.  I do not want this, so I have to clear those textboxes by overriding their values with blanks.  Is there an easier way to accomplish this?

con19city=     -- clearing field...
con19state=    -- clearing field...
con19zip=      -- clearing field...

con19country=  -- if I try to clear this field, none of the other fields are cleared anymore. (?)  So, I have to leave this parameter out, which means that if the Account.Country field has a value it is carried forward into the new contact. This isn't a huge problem, but I wish it wouldn't do that.  Anyone know why this is?

con10=  -- clearing the Phone field
con11=  -- clearing the Fax field
con14=  -- clearing the Other Phone field

retURL=%2F{! Contact.Id }     -- setting the return URL to the parent contact page


Hope this helps someone, and I hope folks can help answer some of my questions.  I sort of feel like a hack, figuring all this stuff out in this manner.  Is there a document anywhere that explains little gems like "003" is for Contact, and "00T" is for Task, and the "ent" parameter is for xyz, etc. ?  Or is that sort of thing only realized by this trial and error method?

Thanks everybody,
Jeff

beenerbeener
It helped me thanks :-)
Roslyn McGintyRoslyn McGinty

This thread was excellent and helped me resolve a similar issue.

 

Thanks everyone!

 

:smileyvery-happy:

davidhbarberdavidhbarber

Jeff C. - Fantastic post.  Thanks for the solution and extra step of explaining the components in great detail.  I was starting to go down the Trigger route out of pure frustration.

 

Here is a site I've found useful and I "figure these things out" as best I can as well.  This particular page lists the Object specific URL's.

 

http://salesforce.phollaio.com/2007/01/11/salesforces_url_structure/

 

Now, if anyone knows a definitive document mapping the "conX" fields per Object, THAT would be supremely helpful.

pupilstuffpupilstuff

great work Jeff..but I have one small issue

 

I want to use {!Case.RecordTypeId} , on the list button but that button on different object layout and that object have field product type which value are simmilar to record type of Case.

for exmaple ..prodcut type have values A, B, C on after clicking the button the page layout of 'A' type should open and I have case record of A,B,C type

 

https://s13.salesforce.com/500/ecas53=Incident&ent=Case&nooverride=1&RecordType={!Case.RecordTypeId};

 

but here record type would be null so need to pass product type here ..is it poosible

sean.gorman@ipc.comsean.gorman@ipc.com

Great post.

 

Points to note: if you're using a custom field, you can get the ID of the field from the setup page by clicking the field and copying the GUID. Also - one thing I missed was putting CF in front of the field names... Works wonderfully.

 

 

/a1C/e?ent=01IM00000004sJH&RecordType=012M00000008kIl&CF00NM0000000ZI5s={!Opportunity.Name}&CF00NM0000000ZI5s_lkid={!Opportunity.Id}&retURL=%2F{!Opportunity.Id}

 

Rajkumar Gaikwad1Rajkumar Gaikwad1
You need to pass string instead standard action in target attribute of URLFOR().
Here instead $Action.Contact.NewContact provide '/003/e?' (003 for contact) if you want to escape record type then '/003/e?&RecordType=Id_of_record_type'
 
Ben Merton 17Ben Merton 17
I am creating an app to be used in a managed package, so I won't be able to use the record type id. Is there any way to do this by matching the record type text NAME with the child record type NAME?  If the same record type names are used in the parent and the child, can one refer to the parent to drive opening the same child record type?
{tushar-sharma}{tushar-sharma}
Now URL hack is supported in Lightning Experience. You can set record type as well. Check below post for detail and code sample: 
https://newstechnologystuff.com/2020/06/03/salesforce-url-hack-in-lightning/