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
AbAb 

Change record type when a picklist value is choson

Hello,

I have a customPicklist__c with value XYZ, PQR
When XYZ is chosen i want the reccordtype of ObjecCustom changes to Recordtype.Name=Name
,how can i achieve it ?
thank you
Best Answer chosen by Ab
AbhishekAbhishek (Salesforce Developers) 
click setup--> create --> objects --> Section_2_Balance_Sheet_c --> scroll down to "Record Type Section" --> you will find two record type that you have created, click the record type name you want to update the pick list value --> in "Picklists Available for Editing" section you will find Type__c --> click "Edit" ,update the pick list value.

For further suggestions, you can refer to this discussion (https://salesforce.stackexchange.com/questions/27658/picklist-value-available-for-selection-on-change-of-record-type)

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.

All Answers

Abhishek BansalAbhishek Bansal
Hi Sandrine,

You can change the record type of the record in the trigger. Please find the code snippet below:
trigger updateRecordType on CustomObject__c (before update) {
	for(CustomObject__c custObj : trigger.new) {
		if(custObj.customPicklist__c != trigger.oldMap.get(custObj.Id).customPicklist__c && custObj.customPicklist__c == 'XYZ') {\
            //user developer name of record type in place of Developer_Name
			custObj.RecordTypeId = Schema.SObjectType.CustomObject__c.getRecordTypeInfosByName().get('Developer_Name').getRecordTypeId();
		}
	}
}

Please replace the object and field names with the actual API names and take care of the syntax error.
Let me know if you need any further help on this.

Thanks,
Abhishek Bansal.
AbhishekAbhishek (Salesforce Developers) 
click setup--> create --> objects --> Section_2_Balance_Sheet_c --> scroll down to "Record Type Section" --> you will find two record type that you have created, click the record type name you want to update the pick list value --> in "Picklists Available for Editing" section you will find Type__c --> click "Edit" ,update the pick list value.

For further suggestions, you can refer to this discussion (https://salesforce.stackexchange.com/questions/27658/picklist-value-available-for-selection-on-change-of-record-type)

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.
This was selected as the best answer