You need to sign in to do that
Don't have an account?
Kiril Vodenicharov 7
How to use Map collection to associate between Account and Opportunity
How to write a trigger that creates 10 identical Opportunities whenever an Account with more than 99 employees is created. Make sure all Opportunities are associated with the Account. Use any values for the fields on the Opportunities and to work with Map collection.
Kindly find solution.
If you find your Solution than mark as this as a best answer.
Thanks and Regards
Suraj Tripathi.
Okay, but when you create account the Opportunity creation must be based on Account employees. If the account employees are 99 then you have to create 10 identical Opportunities.
Map<Id, Account> accountMap = new Map<Id, Account>([SELECT Id, Name FROM Account WHERE Id IN: accList AND NumberOfEmployees > 99]);
List<Opportunity> oppList = new List<Opportunity>();
for(Integer i = 0; i < 10; i++) {
for(Account acc : [SELECT Id, Name FROM Account WHERE Id IN: accountMap.keySet()]) {
Opportunity opp = new Opportunity();
opp.AccountId = acc.Id;
opp.Name = acc.Name;
opp.CloseDate = Date.today();
opp.StageName = 'Prospecting';
oppList.add(opp);
}
}
insert oppList;
Something like this one that I've written, but without nested loops.