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

Updating record type based on field
Hello,
I am trying to make a commission__c record change record type, if a field is equal to a value. Any help here would be awesome! This is what I have so far
trigger updaterecordtype on Commission__c (after insert) {
RecordType rt = [select Id,Name from RecordType where Name = 'Refunds' and SobjectType = 'Commission__c'];
for(Commission__c c =[select Id, RecordTypeId from Commission__c Where Payment_Id__c ='Refund'];
c.RecordTypeId=rt;)
update c;
}
Modify like this
trigger updaterecordtype on Commission__c (before insert) {
RecordType rt = [select Id,Name from RecordType where Name = 'Refunds' and SobjectType = 'Commission__c'];
for(Commission__c c Trigger.new){
if(c.Payment_Id__c == 'Refund'){
c.RecordTypeId=rt;
}
}
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Thank you for your feedback!
I still receive errors however
Compile Error: Illegal assignment from SOBJECT:RecordType to Id at line 5 column 1
Any thoughts?
Hello,
I was able to try to get my information a bit tightened up. The fields I am running my if statement against are cross object formulas, and since order of operations says otherwise they may not be able to update correctly. Here is where my code is now.
trigger updaterecordtype on Commission__c (after insert) {
List<Commissionable_User__c> cu=[select id, Payment_Type__c from Commissionable_User__c limit 1];
List<Commission__c> c=[select id, PaymentId__c,RecordTypeId from Commission__c limit 1 ];
RecordType rt2 = [select Id,Name from RecordType where Name = 'Returns' and SobjectType = 'Commission__c'];
if(cu[0].Payment_Type__c == 'Refund'){
c[0].RecordType=rt2;
insert c;
}
}