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
bellardinabellardina 

redirecting to a particular page on-click of a custom button

there is an application(custom object).there are 2 record types for an application.I want to create a custom button on detail page on application which when clicked changes the record type of application.How to do this?

MattLacey.ax1065MattLacey.ax1065

I'd suggest just having the record type field on the top of the page layout would be the more sensible option - basically no effort but will give you the same results!

 

Otherwise you could probably copy the target of the "Change Record Type" link displayed on that field, and use it as the target URL for a custom button. 

Abrar Ul HaqAbrar Ul Haq

Yes you can use custom button but Is it necessary for you to use custom button. Because Matt suggested right solution. But if its is necessary then you can use below code.

 

In the Custom Button:

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

var idToUpdate= "{!Opportunity.Id}";
var RecordTypeFrom = "{!Opportunity.RecordType}";
if (RecordTypeFrom == 'ABC') {
RecordTypeTo = '012A0000000PfII';
} else if (RecordTypeFrom == 'XYZ') {
RecordTypeTo = '012A0000000Pfuu';
}

 

var result = sforce.apex.execute(

"ClassName", // class
"MethodName", // method
{OppId : idToUpdate, RecordTypeId : RecordTypeTo});

 

Then after that you have to update Opportunity record in the Apex WebService Class.