You need to sign in to do that
Don't have an account?
Cory Payne
Help with Trigger to copy Opportunity picklist value into Opportunity lookup field
Hello, total coding noob and trying to simply copy an Opportunity picklist value to a lookup field that is on the same Opportunity; the lookup is to a custom object called Warehouse__c. I've scoured the forums for coding examples and thought I found what I needed but I am getting an error message in the Apex Trigger editor.
Source field is Opportunity.FMAV_Selling_Office__c (picklist)
Destination field is Opportunity.Selling_Office__c which is a lookup to a custom object Warehouse__c
Picklist values exactly match record names on Warehouse object.
Here is what I have so far?
Trigger GrabReference on Opportunity (before insert, before update)
{ for (Opportunity dp: trigger.new) {
if(Opportunity.FMAV_Selling_Office__c != null) {
//queries for 1 record's ID, being the record ID where the dpas.Name field is the same as the dp.picklist field that fired the trigger
List<Warehouse__c> dpas = new List<Warehouse__c>();
dpas = [Select Id from Warehouse__c WHERE Warehouse__c.Name = :Opportunity.FMAV_Selling_Office__c ORDER BY Id LIMIT 1];
// and if we got back anything...
if (dpas.size() > 0){
//set your dp.reference field equal to the returned record's ID
Opportunity.Selling_Office__c = dpas[0].Id;
}
}
}
}
Help?
Source field is Opportunity.FMAV_Selling_Office__c (picklist)
Destination field is Opportunity.Selling_Office__c which is a lookup to a custom object Warehouse__c
Picklist values exactly match record names on Warehouse object.
Here is what I have so far?
Trigger GrabReference on Opportunity (before insert, before update)
{ for (Opportunity dp: trigger.new) {
if(Opportunity.FMAV_Selling_Office__c != null) {
//queries for 1 record's ID, being the record ID where the dpas.Name field is the same as the dp.picklist field that fired the trigger
List<Warehouse__c> dpas = new List<Warehouse__c>();
dpas = [Select Id from Warehouse__c WHERE Warehouse__c.Name = :Opportunity.FMAV_Selling_Office__c ORDER BY Id LIMIT 1];
// and if we got back anything...
if (dpas.size() > 0){
//set your dp.reference field equal to the returned record's ID
Opportunity.Selling_Office__c = dpas[0].Id;
}
}
}
}
Help?
All Answers
Test