Skip to main content

Posts

Showing posts with the label Trigger

Top 5 trigger scenarios in salesforce

  1)  Write a trigger on the Account when the Account is updated check all opportunities related to the account. Update all Opportunities Stage to close lost if an opportunity created date is greater than 30 days from today and stage not equal to close won. trigger UpdateOpportunitiesOnAccountUpdate on Account (after update) {          // Get the IDs of all the updated Accounts     Set<Id> accountIds = new Set<Id>();     for (Account acc : Trigger.new) {         accountIds.add(acc.Id);     }          // Query for all Opportunities related to the updated Accounts     List<Opportunity> opportunitiesToUpdate = [         SELECT Id, StageName, CreatedDate         FROM Opportunity         WHERE AccountId IN :accountIds     ];          // Update Opportunities that ...