We suggest one solution whenever you faced the below mentioned same type issue, it will help you to finish your work fastly.
Issue: One object is created/updated , contains some fields value automatically updated to another object without a relationship. Is it possible? yes, possible. Other one object (3rd object) relationship with the above-asked objects.
For Example – Any customer account created/updated, if it relates to vehicle object (parent – lookup field), then automatically update customer name into property object (relationship with vehicle).
Code :-
public void multipleupdate(Map<Id,Customer__c> testNewMap){
Map<Id, Customer__c> cusmaps= new Map<Id, Customer__c>();
for (Customer__c c: testNewMap.values()){
if (c.Vehicle__c != null) {
cusmaps.put(c.Vehicle__c, c);
}
}
List<Property__c> res=new List<Property__c>();
for(Property__c pro:[select id,Vehicle__c, Latest_Customer__c from Property__c where Vehicle__c in : cusmaps.keySet()]){
pro.Latest_Customer__c = cusmaps.get(pro.Vehicle__c).name;
res.add(pro);
}
update res;// if you need for insertion purpose apply this – insert res;
}
We are the ISV Partners and Please reach us for custom development => www.merfantz.com
———————————- We Are Really Happy To Helping You ——————————–