0

I have two record types on Opportunity. Stage 1 and Stage 2. I would like to use a custom button to update an opportunity Record Type from Stage 1 to Stage 2 and open the current opportunity in edit mode at the same time (CurrentRecordID/e).

Record Type Stage 2 is associated with Page Layout Stage 2 so I would like the fields on page layout stage 2 to be displayed on edit mode after the button is clicked. Any ideas?

1 Answer 1

1

Here you go. Please note you need the change the code with the correct record type names and objects. I have written the code as per my convenience. I am using Lead here instead of Opportunity.

As soon as the recordtype changes, it open up it in the edit mode and the page layout looks different since you already set the page layout assignment.

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

var update_obj = new sforce.SObject("Lead");

var recordtypes = sforce.connection.query("SELECT Id, Name from RecordType WHERE SobjectType = 'Lead'").getArray("records");
var current_typename = '{!Lead.RecordType}';
var recid = '{!Lead.Id}';
update_obj.Id = recid; 

for(var i=0;i<recordtypes.length;i++){
if(current_typename == 'Stage 1' && recordtypes[i].Name == 'Stage 2'){
update_obj.RecordTypeId = recordtypes[i].Id;
}
}

var objs = [];
objs.push(update_obj);

var result = sforce.connection.update(objs);
if(result.success = 'true'){
parent.frames.location.replace("/"+recid+"/e?retURL=%2F"+recid+"");
}else{
alert('Anything u want');
}
1
  • Just replace Lead by Opportunity with correct record type names. May 28, 2015 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.