You need to sign in to do that
Don't have an account?
SFDC Lightning 18
Need help on trigger for mass uploaded, for single record trigger is working fine.
Hi, I need to update the trigger for mass update when opportunity created new record there are some lookup fileds (opp.Client__c = p.Client__c) are mapped. I am using data loader to update opportunity records, but lookup's fields not updating.Please check the below code.Thanks Advanced.
Trigger UpdateAccLookups on Opportunity (before insert, before update) { Set<Id> ProjectIds = new Set<Id>(); for (Opportunity o : trigger.new) { ProjectIds.add(o.Project__c); } Map<Id, Project__c> ProjectMap = new Map<Id, Project__c>(); list<Project__c> Projects = new list<Project__c>(); Projects = [Select Id, Name,Remarks__c,Main_Contractor__c,Client__c,Architect_Consultant__c,Facade_Consultant__c,Country__c,City__c,Other_City__c from Project__c where Id IN : ProjectIds]; for (Opportunity opp : trigger.new) { for(project__C p : Projects){ opp.Main_Contractor__c = p.Main_Contractor__c; opp.Client__c = p.Client__c; opp.AccountID = p.Client__c; opp.Architect_Consultant__c = p.Architect_Consultant__c; opp.Facade_Consultant__c = p.Facade_Consultant__c; opp.Country__c = p.Country__c; opp.City__c= p.City__c; opp.Other_City__c = p.Other_City__c; } } }
All Answers
Apex trigger UpdateAccLookups caused an unexpected exception, contact your administrator: UpdateAccLookups: execution of BeforeInsert caused by: System.DmlException: Upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Opportunity Name, Opportunity Stage, Opportunity Close Date]: [Opportunity Name, Opportunity Stage, Opportunity Close Date]: Trigger.UpdateAccLookups: line 30, column 1
00:53:49.0 (16906851)|USER_DEBUG|[28]|DEBUG|oppToUpdate====(Opportunity:{Id=null, Main_Contractor__c=null, Client__c=0011D00000M1MV8QAN, AccountId=0011D00000M1MV8QAN, Architect_Consultant__c=null, Facade_Consultant__c=null, Country__c=UAE, City__c=Abu Dhabi, Other_City__c=null})
Lookup fields are Client__c,Architect_Consultant__c Facade_Consultant__c etc.
When i create child record under parent the trigger is working fine, it's mapping all the lookup fields, but I have excel file to upload records in opportunity, at that time the trigger lookup, not mapping correct with parent lookups, its mismatching values for mass insert in opportunity.