You need to sign in to do that
Don't have an account?
Anik soni 7
How to make a trigger for this situation, i am stuck on this need help, i am learner.
When an opportunity is inserted check for it’s a delicacy on the basis of its name and the account to which it is related to i.e. If it has the same name and it’s linked to the same Account then append “Duplicate Opportunity” in the name.
Try this code.I tested this in my org it is working fine.
Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards
All Answers
Try this code.I tested this in my org it is working fine.
Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards
Try the following approach:-
1.Query on all existing opportunities.
2.Using the existing opportunities, create a Map of Opportunity Name and accountId i.e. Map<String,Id>
3.Iterate over trigger.new and check if Map.KeySet() contains new opportunity name and if it does then get the accountId using the same Map.get(newOppName) and compare it with new accountId.
4.If it matches then, change name to duplicate opp.
Thanks,
Rishabh Bansal
Thank you for the help and i appreciate it. can you please check my code is it ok i am not sure.
trigger Secondtrigger on Opportunity (before insert)
{
for(Opportunity op : trigger.new)
{
List<Opportunity> op1 = [Select Name,AccountId from Opportunity Where AccountId = :op.AccountId AND Name = :op.Name LIMIT 1];
If(op1.isEmpty())
{
op.Name = op.Name + ' Duplicate Opprotunity';
}
}
}