You need to sign in to do that
Don't have an account?
Arundhati Deb
hi, i want to write a trigger to update opportunity currency same as the opportunity owner currency in before insert.
Hi
I have a scenario where the account currency and opportunity currency can be different. The opportunity currency should be the same as opportunity owner currency. I have to write a trigger for it. Can anyone help me with it.
Highly appreciated.
I have a scenario where the account currency and opportunity currency can be different. The opportunity currency should be the same as opportunity owner currency. I have to write a trigger for it. Can anyone help me with it.
Highly appreciated.
I see some issues with your code so here is your code with some corrections.
All Answers
Please find the sample trigger below for the same and tweak it as per your need. Hope this helps.
Kindly mark this as solved if the reply was helpful.
Thanks,
Nagendra
public static void Opportunitycurrency (List<Opportunity> newOptyList) {
Set<Id> oppOwnerIds = new Set<Id>();
for(Opportunity opp: newOptyList)
{
if(opp.OwnerId != null)
{
oppOwnerIds.add(opp.OwnerId);
}
}
List<User> ownerList = ([SELECT Id, Name, CurrencyIsoCode FROM User WHERE Id IN :oppOwnerIds]);
Map<Id, User> userById=new Map<Id, User>();
userById.putall(ownerList);
for(Opportunity opp: newOptyList)
{
if(opp.type != 'Renewal'){
oppOwnerIds.add(opp.OwnerId);
opp.currencyisocode=userById.get(opp.OwnerId).currencyisocode;
}
}
}
Try below code,
Opportunity owner available only when opportunity created. Before Inserting an opportunity, it doesn't have any owner. So we have to take current logged in user as opportunity ower.
Kindly let us know if it helps you.
Regards,
Vijay
That is not true statement that Opportunity Owner is not available, please confirm and rever back with your confirmation. It is available and my code is working fine. I intentionally didn't use Current User base as it may fail if moving forward same code need to be used for the update where there is a change that the Opportunity Owner is not the logged in user.
This trigger is to be used while creating opportunity
I see some issues with your code so here is your code with some corrections.
https://www.customassignment.com/ a community outdoors in Augsburg, Germany. this isn't any longer San Diego and it truthfully isn't Kailua, even though it somewhat is between some rolling hills and a selection of woodland and eco-friendly fields. it somewhat is positive