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
FinneyFinney 

Button to change record type

Hi

 

I have 2 record types on Account

 

For Example

 

1) Live Prospect

2) Dead Prospect

 

I want to have a button on the live prospect, which when pressed turns the Live prospect record type to a dead prospect.

 

I want to name the button as KILL. So when the KILL button is pressed, LIVE record type should change to DEAD 

 

Can anyone please help me with the code for the button .

 

Thanks

 

Finney 

Best Answer chosen by Admin (Salesforce Developers) 
FinneyFinney

Hi SFDC@Fuj

 

Thanks a lot for your help.

 

With a bit of customisation it worked.

 

{! 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('{!Account.RecordType}' == 'Live Prospect')
{
sforce.connection.sessionid = '{!GETSESSIONID()}';
var account = new sforce.SObject("Account");
account.id='{!Account.Id}';
account.RecordTypeId =records[0].Id;
var result = sforce.connection.update([account]);
}
}
catch (ex)
{
alert(ex);
}
if (result[0].success=='false') {
alert(result[0].errors.message);
} else {
location.reload(true);
}

 

Kind Regards

 

Finney

All Answers

SFDC@FujSFDC@Fuj

Hi,

 

Set the Behavior 'Execute javascript ' and Content Source 'On Click Java Script' for Kill button. Use the following code as a reference.

 

{! REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
var recordtype= sforce.connection.query("select name, id from recordtype where name='Dead prospect'");
var records = recordtype.getArray("records");
try
{
    if('{!Account.RecordType}' == 'Live prospect')
    {
        sforce.connection.sessionid = '{!GETSESSIONID()}';
        var account = new sforce.SObject("Account");
        account.id='{!Account.Id}';
        account.name='hello121';
        account.RecordTypeId =records[0].Id;
        var result = sforce.connection.update([account]);
    }
}
catch (ex)
{
    alert(ex);
}

 

Did this answer Help you? If not, let me know the issue.

 

 

 

 

FinneyFinney

Hi SFDC@Fuj

 

Thanks a lot for your help.

 

With a bit of customisation it worked.

 

{! 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('{!Account.RecordType}' == 'Live Prospect')
{
sforce.connection.sessionid = '{!GETSESSIONID()}';
var account = new sforce.SObject("Account");
account.id='{!Account.Id}';
account.RecordTypeId =records[0].Id;
var result = sforce.connection.update([account]);
}
}
catch (ex)
{
alert(ex);
}
if (result[0].success=='false') {
alert(result[0].errors.message);
} else {
location.reload(true);
}

 

Kind Regards

 

Finney

This was selected as the best answer