+ Start a Discussion

Updating record type of a related object



I am trying to update the record type of child objects.  These need to be updated when the payment (parent) is set to a specific status of "reversed" this should update my child object "commissions" to a record type of returns.  It saves and compiles but does not seem to fire and I cannot figure out why!  Help me Obi Wan, your my only hope....


trigger CommsReturn on pymt__PaymentX__c (after insert, after update) {
    List<pymt__PaymentX__c> updatePayList = new List<pymt__PaymentX__c>();
    RecordType ReturnRT = [Select Id From RecordType Where Name = 'Returns'];
    RecordType CommRT2 = [Select Id From RecordType Where Name = 'Commissions'];
    //Loop through the case and update the account with appropriate category
    set<ID> PayIds = new set<ID>();
    for( pymt__PaymentX__c p1 : Trigger.New){
        if(p1.Id != null) 
        list<Commission__c> csList = [select Payment_ID__c, RecordTypeId  from Commission__c where Payment_ID__c = : PayIds];
        map<Id, pymt__PaymentX__c> PayUpdates = new map<ID, pymt__PaymentX__c>();
        for(Commission__c cs : csList){
            pymt__PaymentX__c pmt = PayUpdates.get(cs.Payment_ID__c);
            if(pmt == null)
                pmt = new pymt__PaymentX__c(Id = cs.Payment_ID__c);

            if(pmt.pymt__Status__c != 'Reversed')
                cs.RecordType = ReturnRT ;
                cs.RecordType =CommRT2 ;

            PayUpdates.put(cs.Payment_ID__c, pmt);
        update PayUpdates.Values();