You need to sign in to do that
Don't have an account?
Asel Vazir 1
Trying to copy custom fields' values from related list on the same custom fields on Opportunity object
I looked for similar topics and used some best answers to modify my code, but it is still not populating the custom fields on Opportunity every time the custom fields on related list Property are entered. Please help me to resolve the issue.
Here is the class:
And my trigger:
Here is the class:
public with sharing class PropertyEscrowContactOnExchange { public static void copyPropertyEscrowAddressOnExchange(List<Property__c> propList) { Set<String> oppIds = new Set<String>(); for (Property__c prop : propList) { oppIds.add(prop.Id); } List<Opportunity> opportunities = [SELECT Id, Name, Escrow_Company__c, Escrow_Address__c, Escrow_City__c, Escrow_State__c, Escrow_Zip_Code__c FROM Opportunity WHERE Id IN : oppIds]; Map<String, Opportunity> oppByStrings = new Map<String, Opportunity>(); for(Opportunity o : opportunities){ oppByStrings.put(o.Escrow_Company__c + o.Escrow_Address__c + o.Escrow_City__c + o.Escrow_State__c+ o.Escrow_Zip_Code__c, o); } for (Property__c p : propList) { Opportunity o = oppByStrings.get(p.Id); if (o == null && oppByStrings.containsKey(p.Id) && oppByStrings.get(p.Id).Properties__r.size()>0) { p.Escrow_Company__c = o.Escrow_Company__c; p.Escrow_Address__c = o.Escrow_Address__c; p.Escrow_City__c = o.Escrow_City__c; p.Escrow_State__c = o.Escrow_State__c; p.Escrow_Zip_Code__c = o.Escrow_Zip_Code__c; } } }
And my trigger:
trigger copyPropEscrowAddressOnExchange on Property__c (after insert, after update) { if (Trigger.isInsert || Trigger.isUpdate){ PropertyEscrowContactOnExchange.copyPropertyEscrowAddressOnExchange(Trigger.new); }
Please update your code in Apex class line #6, 7, 8 as below: