You need to sign in to do that
Don't have an account?
Swapnil Patne
Trigger to auto populate lookup field on opportunity product lineitem
Hi,
I hope someone can help me with this-
Auto populate a custom lookup field "Account_Name__C " on opportunity product lineitem with an "Account Name" from the opportunity object or possibliy from Account Object itself, needs to happen when a user selects the opportunity product and saves the record.
Please can someone advise?
Thanks,
Swapnil
I hope someone can help me with this-
Auto populate a custom lookup field "Account_Name__C " on opportunity product lineitem with an "Account Name" from the opportunity object or possibliy from Account Object itself, needs to happen when a user selects the opportunity product and saves the record.
Please can someone advise?
Thanks,
Swapnil
trigger updateOLI on OpportunityLineItem (after insert) {
List<OpportunityLineItem> OpportunitiesToUpdate = new List<OpportunityLineItem>();
for(OpportunityLineItem OLI : [Select Id, Opportunity.Account.Id From OpportunityLineItem Where Id IN : trigger.newMap.keyset()]) {
OLI.Account_Name__c = OLI.Opportunity.Account.Id;
OpportunitiesToUpdate.add(OLI);
}
if(!OpportunitiesToUpdate.isEmpty())
update OpportunitiesToUpdate;
If the "Account_Name__c" field is just a Text field and you just wanted to store the Account Name of the Opportunity in there, then better to Opt for a formula field instead the trigger as @gm_sfdc_powerde suggested.
Regards,
- Harsha
All Answers
trigger updateOLI on OpportunityLineItem (after insert) {
List<OpportunityLineItem> OpportunitiesToUpdate = new List<OpportunityLineItem>();
for(OpportunityLineItem OLI : [Select Id, Opportunity.Account.Id From OpportunityLineItem Where Id IN : trigger.newMap.keyset()]) {
OLI.Account_Name__c = OLI.Opportunity.Account.Id;
OpportunitiesToUpdate.add(OLI);
}
if(!OpportunitiesToUpdate.isEmpty())
update OpportunitiesToUpdate;
If the "Account_Name__c" field is just a Text field and you just wanted to store the Account Name of the Opportunity in there, then better to Opt for a formula field instead the trigger as @gm_sfdc_powerde suggested.
Regards,
- Harsha
@Harsha- thank you for your response and the code, I think this is what will work for me, I'll test it. Thanks a ton once again.
Regards,
- Harsha