You need to sign in to do that
Don't have an account?

Trigger Based Question
When an opportunity is inserted check for it’s duplicacy on the basis of its name and the account to which it is related to i.e. If it has same name and it’s linked to same Account then append “Duplicate Opportunity” in the name
Please share any code that you have already tried.
{
if(Trigger.isAfter)
{
if(Trigger.isInsert)
{
classname.methodname(Trigger.new, Trigger.oldMap);
}
}
}
class ClassName
{
public static void methodname(List<Account> acclist, Map<Id, Account> accmap)
{
List<Opportunity> opp = new List<Opportunity>();
Map<Id, Account> mapacc = new Map<Id, Account>
([Select Id, Name,(Select Name From Opportunities) From Account Where
Id In : acclist]);
for(Account a : acclist)
{
if(mapacc.get(a.Id).Opportunity.size()==0)
{
if(a.Name!=accmap.get(a.Id).Name)
{
opp.add(new Opportunity(AccountId = a.Name, Name='shubham saini'+'FirstOpportunity',StageName ='Prospecting',
CloseDate=System.date()));
}
else
{
opp.add(new Opportunity(AccountId = a.Name+'DuplicateOpportunity', Name='shubham saini',StageName ='Prospecting',
CloseDate=System.date()));
}
}
}
}
}
Can you please re-post that code by doing the following:
In your reply, click the <> button (highlighted below) at the top of your reply box.
Then paste your code inside the popup text box.
That will make it much easier to read and follow, and it will give your code line numbers that we use for reference.
Secondly, I'm seeing what appears at first glance to be a lot of extra, non-needed code, but that is not what is not working, I guess.
Thirdly I see that in line 26 you create a... ...but in line 30 you use the Name and not the Id as the Map key.
Fourthly, you are comparing Account names and then inserting an Opportunity with 'Duplicate Opportunity' as part of the Opportunity name.
My understanding from your original question is that you were trying to compare Opportunity names to see if they are duplicates.
Lastly, you still haven't said exactly what issue(s) you have - is it just not working, or are there errors (if so, share them)?