User Story
As a developer, I want to automatically update the description of opportunities associated with an account when the probability of closing the opportunity is greater than 50%.
HINT: When an account is updated, the related opportunities will have the description set to "High probability account: Bank of America."
Codes
trigger UpdateOpportunityDescription on Account (after update) {
Set<Id> accountIds = new Set<Id>();
for (Account a : Trigger.new) {
accountIds.add(a.Id);
}
List<Opportunity> opportunities = [SELECT Id, Description FROM Opportunity WHERE AccountId IN :accountIds];
for (Opportunity o : opportunities) {
Account a = [SELECT Id FROM Account WHERE Id = :o.AccountId];
if (o.Probability > 50) {
o.Description = 'High probability account: ' + a.Name;
}
}
update opportunities;
}