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
Arun AdepuArun Adepu 

change user to one object from another object based on records

hi every one,

       i have requirement like this two objects are custom objects one is customer another one is payment. i created look up relationship in payment object i.e customer. then i created 10 records for payment with two different users. X user has 6 records in payment with xxx customer and Y user has 4 records with xxx customer. whenever i deactivate the owner of customer record then in payment who has more records of user should be the owner of that customer record... i am phasing this issue since last one week please resolve this...
@Karanraj@Karanraj
You have to write trigger code in a user object to get the list of customer records assigned to that user and then for those account record you will query payment object records to identify the user who owns more payment record. The main logic is to identify the user who owns more payment record which is the child of the customer record.

Example query

The below query will return owner Id who owns more contact record in your org
List<AggregateResult> contactOwnerGroup = [SELECT Count(Id),OwnerId  FROM Contact group by OwnerID order by count(id) Limit 1];
system.debug('Top Owner of Contact Object' + contactOwnerGroup[0].OwnerId);
For your example try the below query, you may have to update the proper API name of an object to return the result.
List<AggregateResult> contactOwnerGroup = [SELECT Count(Id),OwnerId  FROM Payment__c where customer__c ='00000000' group by OwnerID order by count(id) Limit 1];