You need to sign in to do that
Don't have an account?
Matt Cooper 7
Apex Trigger to Update Record Type Based on Field Value
I have been working on building a trigger that would allow my users to use a single Intake Form which would then change the record type based on the values they provide on the Intake Form page layout. Basically, people can come in and make selections based on their circumstances. Those selections will determine which type of record type the record should be. Below is the code that I have been working on that does not seem to be working.
Any help would be great! Thanks!
trigger IntakeFormTrigger on Apttus__APTS_Agreement__c (after insert, before update) { // Get a list of record types. Map<ID,RecordType> typeMap = New Map<ID,RecordType>([Select ID, DeveloperName From RecordType Where sObjectType = 'Apttus__APTS_Agreement__c']); for (Apttus__APTS_Agreement__c agmt : trigger.new) { // If the Record Type = Intake Form if (agmt.RecordType.DeveloperName == 'Intake Form') { // And the Agreement Category on the record =TEST if (agmt.Apttus__Agreement_Category__c == 'TEST') { // Then automatically change the Record Type to TEST Agreements. agmt.RecordType = typeMap.get('TEST Agreements'); } } } }
Any help would be great! Thanks!
Try just using the RecordTypeId instead of RecordType.DeveloperName eg: