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
Robert Robinson 17Robert Robinson 17 

Java Script issue - referencing record type

Java Script issue - referencing record type
I am following up after a consultant that used JavaScript to direct users to 1 of 2 record types from an Account Related List. I have added a 3rd record type, and am trying to create a button that references the JavaScript. Here is the code that I am working with:
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/31.0/apex.js")} 

var opportunity = new sforce.SObject('Opportunity'); 

opportunity.Name = 'Do Not Delete'; 
opportunity.AccountId = '{!Account.Id}'; 
opportunity.RecordTypeId = '{!$Setup.Opportunity_Record_Type_Ids__c.Record_Type_3__c}';
opportunity.StageName = 'Quote in Progress'; 



var closeDate = new Date('{!TODAY()}'); 
closeDate.setMonth(closeDate.getMonth()+6); 
opportunity.CloseDate = closeDate; 

var result = sforce.connection.create([opportunity]); 

if(result[0].success == 'true'){ 
var serverPrefix = '{!$Setup.Server_Prefix__c.Server_Prefix__c}'; 
var oppId = result[0].id; 
parent.window.location.href = 'https://' + serverPrefix + '.salesforce.com/' + oppId; 

else{ 
alert('Record creation failed - please notify system administrator'); 
}

The bold, italicized area is where the error is. The error message is:
<span class="errorStyle">Error: Field Record_Type_3__c does not exist. Check spelling.</span>

Record Type 3 does exist, and the spelling is correct. Is there someplace else that I need to define the "Record_Type_3" field? Thanks.
Ramesh DRamesh D
@Robert,

Yes you must define it under SETUP-->Custom Settings-->Opportunity Record Type Ids 

Your consultant  has created custom settings to maintain all recordtypes under opportunity and  $Setup provides access to retrive Custom Setting

I hope you find the above solution helpful. If it does mark as best answer to help others too.
Thanks,
Ramesh D
Robert Robinson 48Robert Robinson 48
Thank you so much. That was spot on!
Robert Robinson 48Robert Robinson 48
I don't see the Button for "Best answer" here. Will continue to look.
Ramesh DRamesh D
@robert when go to my answer and mouse over next to Flag 
User-added image
Robert Robinson 48Robert Robinson 48
This one has been solved, but there is no Best Answer option. Not sure why.