You need to sign in to do that
Don't have an account?
XIO
Apex Trigger to update Lookup field from a text field in Opportunity
Hello,
I have a basic trigger that needs to update a lookup field (Discount_code_LU__c). I'm just trying to map the lookup field with the text field (Discount_code__c). The lookup field (Discount_code_LU__c) is related to the Product object. Any assistance will be greatly appreciated!
Thank you!!
I have a basic trigger that needs to update a lookup field (Discount_code_LU__c). I'm just trying to map the lookup field with the text field (Discount_code__c). The lookup field (Discount_code_LU__c) is related to the Product object. Any assistance will be greatly appreciated!
Thank you!!
trigger UpdateOpportunityProduct on Opportunity (before insert){ for(Opportunity opp:Trigger.new) { opp.Discount_code_LU__c = opp.Discount_code__c ; } }
Based on that below is the code. I couldn't compile the code. Please review and change the field names as required.
All Answers
Based on that below is the code. I couldn't compile the code. Please review and change the field names as required.
PRABHAKARAN CHOCKALINGAM if Multiple Discount code for multiple object then it will update only the recent record right?
Set<String> accoutOrgNames = new Set<String>();
for(Account l : myLeads){
if(l.SAP_Sales_Org__c == null){
l.SAP_Sales_Org__c = null;
} else {
accoutOrgNames.add(l.SAP_Sales_Org__c);
}
}
Map<String,Id> OrgNameToId = new Map<String,Id>();
for( SAP_Sales_Org__c c : [SELECT ID, Sales_Org_Code__c FROM SAP_Sales_Org__c WHERE Sales_Org_Code__c IN :accoutOrgNames ]){
OrgNameToId.put(c.Sales_Org_Code__c,c.id);
}
for(Account l : myLeads){
if(l.SAP_Sales_Org__c != null){
l.SAPSalesOrg__c = OrgNameToId.get(l.SAP_Sales_Org__c);
}
}
}