You need to sign in to do that
Don't have an account?
Asel Vazir 1
Help to figure out why my code is not creating related opportunity if account is updated
Here is my method that should create another missing related opportunity if the account is updated and have only one opportunity.
public static void missingOpp(List<Account> acctList3) { List<Opportunity> oppList3 = new List<Opportunity>(); List <Account> acctsTypeProspect = new List<Account>( [ SELECT Id, Name, OwnerId, Type FROM Account WHERE Type = 'Prospect' AND Id IN (SELECT AccountId FROM Opportunity) AND Id IN :acctList3 ]); for (Account acct : acctsTypeProspect) { for (Opportunity oppt : acct.Opportunities) { if (oppt.Name == 'Default Residential Opp') { } Opportunity opp1 = new Opportunity(); opp1.Name = 'Default Commercial Opp'; opp1.AccountId = acct.Id; opp1.CloseDate = System.today().addMonths(1); opp1.StageName = 'Prospecting'; oppList3.add(opp1); if (oppt.Name == 'Default Commercial Opp') { } Opportunity opp2 = new Opportunity(); opp2.Name = 'Default Residential Opp'; opp2.AccountId = acct.Id; opp2.CloseDate = System.today().addMonths(1); opp2.StageName = 'Prospecting'; oppList3.add(opp2); } insert oppList3; } }
Please refer below code: