+ Start a Discussion
mallikharjunarao gundamallikharjunarao gunda 

triggers change the recordowner if deacivate the user

hai hall
i have a customer__c and payment__c objects ,payment__c has lookup to customer__c.
here customer__c object having a one record and payment__c having a ten records out of ten records six records having one user and four records having another user .  all tese records associate to the  customer__C .if i deactive the customer__c record ownerid ,those whose records will be higher in payment__c object that user can be assigned to the customer__c objectrecord

i wrote code something 
trigger userchange on User (after update) {    
    list<customer__c> cust=[select id, first_name__c from customer__c where first_name__c='chanda shekar'];
    list<user> u=[select id from user];
    List<Id>ids=new list<Id>();
    map<Id, list<payment__c>> getRecords=new map<Id, list<payment__C>>();
    Map<Id,Customer__C> customerMap=new Map<Id,Customer__C>([select id,ownerId ,(select id,ownerId from Payments__r) from Customer__c where ownerId in:Trigger.Newmap[0].Id]);
    Map<Id,List<Payment__c> > cusMap=new Map<Id,List<Payment__c>();
    for(Id id:customerMap.keySet()){
        for(Payment__c p:customerMap.get(id).payments__r){
            if(cusMap.keySet().contains(p.ownerId)){
                
            }
        }
    }
    
    }
sfdcLionsfdcLion
Can you please help understand your problem statement in detail ?
 
mallikharjunarao gundamallikharjunarao gunda
here how we can compare higher records owner in the payment__c object
 
Rohit Sharma 66Rohit Sharma 66
Can u please help me understand the condition "if i deactive the customer__c record ownerid ,those whose records will be higher in payment__c object that user can be assigned to the customer__c objectrecord".
How to identify "records will be higher in payment__c object".