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
ericmonteericmonte 

Javascript Query Custom Button

hey all i need help on getting one of my javascript button to work properly, can someone help me out?? All i am trying to do is redirect a button to new Contact Record page and setting the Record Type Id. I figured out how to query the recordType, but I can't seem to figure it out how to add it to the URL without hardcoding the RecordTypeId. Any input?

 

 

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}

var leadRec = sforce.connection.query("select id, Name from RecordType where SObjectType = 'Contact' and Name = 'Standard Contact'");
 
parent.window.location = "003/e?{!$Label.LeadContactField}={!Lead.Name}&{!$Label.LeadContactField}_lkid={!Lead.Id}&retURL={!Lead.Id}&RecordType="+leadRec.id +"&ent=Contact"

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox
Sorry, try "leadRec.records.Id" instead. I forgot that they are wrapped into a results object.

All Answers

sfdcfoxsfdcfox
It's "Id", not "id" (capital "i"). JavaScript is case sensitive.
ericmonteericmonte
nope still no go...

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}

var leadRec = sforce.connection.query("select Id, Name from RecordType where SObjectType = 'Contact' and Name = 'Standard Contact'");

parent.window.location = "003/e?{!$Label.LeadContactField}={!Lead.Name}&{!$Label.LeadContactField}_lkid={!Lead.Id}&retURL={!Lead.Id}&RecordType="+leadRec.Id+"&ent=Contact"
sfdcfoxsfdcfox
Sorry, try "leadRec.records.Id" instead. I forgot that they are wrapped into a results object.
This was selected as the best answer
ericmonteericmonte
thanks that worked.