You need to sign in to do that
Don't have an account?
Kon Dele
Issue with Field Populating Trigger
I have a custom field Sales Request that has 2 look up fields to Quote and Opportunity objects.
I'm trying to write a trigger that populates the Opportunity field when a Sales Request is created, but haven't been successful.
Any ideas on how to tweak my trigger below? Thanks!
I'm trying to write a trigger that populates the Opportunity field when a Sales Request is created, but haven't been successful.
Any ideas on how to tweak my trigger below? Thanks!
trigger SalesRequestPopulateOpp on Sales_Request__c(Before Insert,Before Update) { List<Id> qIds = new List<Id>(); for(Sales_Request__c sr:trigger.new){ if(sr.Quote__r.Id!=null){ qIds.add(sr.Quote__r.Id); } } Map<Id,Quote> qMap = new Map<Id,Quote>([select id,Opportunity.Name from Quote where id in:qIds]); for(Sales_Request__c srq :Trigger.new){ if(!qMap.IsEmpty()){ srq.Opportunity__c=qMap.get(srq.Quote__r.Id).Opportunity.Name; } } }
You should use: srq.Opportunity__c=qMap.get(srq.Quote__r.Id).OpportunityId;
instead of
srq.Opportunity__c=qMap.get(srq.Quote__r.Id).Opportunity.Name;
try the below code.