+ Start a Discussion
ZimmerZimmer 

Button to update Record Type ID

I would like to create a button that changes the record type of a case . 

 

I have tried writing the javascript and scoured the web, but still cannot get it to work.  My code will update other fields if modified but not the recordtypeid.  Any suggestions?

 

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

var undocase= new sforce.SObject("Case");
undocase.id = "{!Case.Id}";
undocase.RecordType = "01240000000QFLB";

var result = sforce.connection.update([undocase]);

if (result[0].getBoolean("success"))
{
    // Refresh window
    window.location.reload();
}
else
{
    alert("Error saving case");
}

Ritesh AswaneyRitesh Aswaney

Try RecordTypeId

undocase.RecordTypeId = "01240000000QFLB";

ZimmerZimmer

I have tried both recordtype and recordtypeid,  neither one leads  to a record type change on the record.

sham_1sham_1

Do you have a workflow or Apex trigger, written which might be resetting the recordType value

Pradeep_NavatarPradeep_Navatar

I guess you have not created any record type in case object so first you need to create record type then before updating the

record type you just query that record type then update in case object.

 

Find below a sample code:

 

RecordType RT = [select id from RecordType where name='CaseRecType' and SobjectType ='Case' limit 1];

Case cs = [Select id, RecordTypeId from Case limit 1];

cs.RecordTypeId = RT.id;

update cs;