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
Newbie10Newbie10 

Help with onclick Javascript on custom detail button to update record type

Below is my code to update a record when a button is clicked.

Its giving me a error

Faultcode soap env client unexpected element urn partner soap sforce.com done during simple deserialization

 

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")} //adds the proper code for inclusion of AJAX toolkit

var lead_record = new sforce.SObject("Lead"); //creating sobject to hold the values of lead record that this code will ultimately update
lead_record.id = "{!Lead.Id}";
var recTypeName = "Deal Record Type";
var recordType = sforce.connection.query("Select ID, Name From RecordType WHERE Name = 'Deal Registration Record Type'" );
lead_record.RecordTypeId = recordType ;
result = sforce.connection.update([lead_record]); //push the updated records back to Salesforce
alert("Please complete further information on your deal"); //alert the user that their Lead is now able to be edited as a Deal
window.location.reload(); //refresh the page

Best Answer chosen by Admin (Salesforce Developers) 
Marko LamotMarko Lamot

var recordType = sforce.connection.query("Select ID, Name From RecordType WHERE Name = 'Deal Registration Record Type'" );

 

 var records = recordType.getArray("records");

 

 

lead_record.RecordTypeId = records[0].ID ;