You need to sign in to do that
Don't have an account?
Avinash Dhanke 32
System.ListException: Duplicate id in list: 0016F000030h1SbQAI: Trigger.updateAccountIfOppCustomer: line 32, column 1
trigger updateAccountIfOppCustomer on Opportunity (after insert,after update) {
List<Account>accToupdate=new List<Account>();
List<Opportunity>opps = new List<Opportunity>();
set<id>associatedAccid = new set<id>();
for(Opportunity opp :trigger.new){
associatedAccid.add(opp.AccountId);
System.debug('associatedAccid'+opp.AccountId);
}
//Map<id,Account>Accmap=new Map<id,Account>
opps =[Select id,Accountid,StageName,Account.Type From Opportunity Where Accountid =:associatedAccid];
System.debug('Opportunity' +opps);
for(Opportunity opp:opps){
if(opp.StageName=='Closed Won-One Time'||opp.StageName=='Closed Won-Recurring'||opp.StageName=='Customer Reseller'){
opp.Account.Type='Customer-Direct';
accToupdate.add(opp.Account);
System.debug('accToupdate'+opp.Account);
}
else{
opp.Account.Type='Prospect';
accToupdate.add(opp.Account);
}
}
update accToupdate;
}
List<Account>accToupdate=new List<Account>();
List<Opportunity>opps = new List<Opportunity>();
set<id>associatedAccid = new set<id>();
for(Opportunity opp :trigger.new){
associatedAccid.add(opp.AccountId);
System.debug('associatedAccid'+opp.AccountId);
}
//Map<id,Account>Accmap=new Map<id,Account>
opps =[Select id,Accountid,StageName,Account.Type From Opportunity Where Accountid =:associatedAccid];
System.debug('Opportunity' +opps);
for(Opportunity opp:opps){
if(opp.StageName=='Closed Won-One Time'||opp.StageName=='Closed Won-Recurring'||opp.StageName=='Customer Reseller'){
opp.Account.Type='Customer-Direct';
accToupdate.add(opp.Account);
System.debug('accToupdate'+opp.Account);
}
else{
opp.Account.Type='Prospect';
accToupdate.add(opp.Account);
}
}
update accToupdate;
}
trigger.updateAccountIfOppCustomer: line 32, column 1
try this code
'Method does not exist or incorrect signature: void contains(Account) from the type Set<Id>'
Create a triger that runs whenever an opportuntity is Created or updated
The Trigger needs to check all the other Opportunities related to the account
of the opportunity being updated.itshould check to see if any opportunities have a
StageName equals to 'Closedwon-One Time' or 'Closed won-Recurring' and if so,it should
update the account type to 'Customer'.if none of the Opportunities are closed won,
the Account Tye is 'Prospect'
But i will suggest you to implements changes like below
1) Set Account.Type='Prospect' as default and update Account.Type='Customer-Direct' when opp closed. like below
2) Update your code like below
Let us know if this will help you