You need to sign in to do that
Don't have an account?

How to set Case record type?
The Case object for has a standard field for 'Type' (in the code below, this is represented by 'Case.Type'). The Case object also has a 'Case Type' standard field, which identifies the case record.
Right now I my conditionals are based on the 'Type' field, but I want them to be based on the 'Case Type' record field (I want to populate the body based on the record type). My goal is to do this without hardcoding a record identifier, which to my understanding, is bad practice as it is not always consistent across Dev/Production environments.
My code is as follows:
public class myControllerExtention2 { private Case cas; private string EmailBody, Subject; //Define default values String defaultEmailBody = ''; String defaultSubject = ''; //Instantiate Visualforce standard controller public myControllerExtention2(ApexPages.StandardController stdController) { //Instantiate case record this.cas= (case)stdController.getRecord(); //SOQL query cas = [SELECT Type FROM Case where Id =: cas.Id]; //Case record type conditionals If (cas.Type=='AAA') { emailBody = 'AAA body content'; subject = 'AAA subject'; } If (cas.Type=='BBB') { emailBody = 'BBB body content'; subject = 'BBB subject'; } If (cas.Type=='CCC') { emailBody = 'CCC Body'; subject = 'CCC subject'; } } //Accessor methods public string GetEmailBody() { If (emailBody == NULL) { return defaultEmailBody; } Else { return emailBody; } } public string GetSubject() { If (subject == NULL) { return defaultSubject; } Else { return subject; } } }
Still, you can use custom setting to remove all harding coding.
Like
You can create a custom setting with fields:
Type Name, Email Subject, Email Body
new, in your class, hit a SOQLQuery to find the appropriate record
[Select Email Subject, Body from Custom_Setting__c where Name =: Case.Type];
Now set the email subjetc and body
Let me explain better - Forget about all code example above, I am not concerned about changing the email body/header. Say all I want to do is change the record type of a case record, How would I do this?
Better example:
case.RecordTypeId = rT.Id;