14 件の回答
Hi Kev,trigger UpdateAccountLookup on Opportunity (before insert) {Set<id> setSiteids=new set<id>();map<Id, String> mapsiteIdToopptId = new map<Id, String>();Map<Id, String> mapOpptIdToAccId = new Map<Id, String>();list<account> acclst = new list<account>(); For(Opportunity o : trigger.new){ setSiteids.add(o.site__c); mapsiteIdToopptId.put(o.site__c, o.OpptId); } for(Site__c objSite : [Select Id , Account__c from Site__c where Id IN :setSiteids ]) { mapOpptIdToAccId.put(mapsiteIdToopptId.get(objSite.Id), objSite.AccountId); } for(Opportunity 0 : trigger.new) { 0.AccountId = mapOpptIdToAccId.get(0.Id); }}Your code will be like this..you will first get all siteIds from Opportunity and then you can get the account Id from Site and then you cna prepare a map opptId to accountId and assign the accountID to Opportunityplease provide the proper field API name and chck with this code it will work..Please implement and let me know if it helps you..P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.Thanks,SandeepSalesforce Certified Developer