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
Iman NazarianIman Nazarian 

Record type change with OnClick button

Hi everyone

I am trying to change the record type of my case with the click of a button. The id of the record type I would like to change to is 012550000000AS0. I have this peace of code, it does not work currently... I get an error message saying "Unexpected token case"

{! REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
var recordtype= sforce.connection.query("select name, id from recordtype where name='Dead'");
var records = recordtype.getArray("records");
try
{
 if('{!Case.RecordType}' == 'Live Prospect')
{
sforce.connection.sessionid = '{!GETSESSIONID()}';
var account = new sforce.SObject("Case");
account.id='{!Case.Id}';
account.RecordTypeId =records[0].Id;
var result = sforce.connection.update([case]);
}
}
catch (ex)
{
alert(ex);
}
if (result[0].success=='false') {
alert(result[0].errors.message);
} else {
location.reload(true);
}
Andy BoettcherAndy Boettcher
Instead of using this OnClick JS, I would advise you spin up a Visualforce Page and Apex Controller to do this work for you - much greater level of control and "debug-ability".  Your users will still achieve the "one click RT change", but you will have a much cleaner implementation.

That - or you can create a checkbox on the Case that says "Dead" - and then have workflow fire to change the RecordType based on that checkbox being on.  That is a zero-code solution, but a two-click (check, save) for the user.