-
Issue with After Trigger And Before Trigger in Salesforce
Hi All,
this trigger is not working
trigger ClosedOpportunityTriggera on Opportunity (before insert,before update) {
List<Task> toBeAddedTasks = new List<Task>();
for(Opportunity A:[SELECT id FROM Opportunity WHERE StageName = 'Closed Won' AND id IN :Trigger.New])
{ toBeAddedTasks.add(new Task(Subject = 'Follow Up Test Task', WhatId = A.Id)); }
upsert toBeAddedTasks; }it is working when i change before insert to after and before update to after
trigger ClosedOpportunityTriggera on Opportunity (after insert,after update) {
List<Task> toBeAddedTasks = new List<Task>();
for(Opportunity A:[SELECT id FROM Opportunity WHERE StageName = 'Closed Won' AND id IN :Trigger.New])
{ toBeAddedTasks.add(new Task(Subject = 'Follow Up Test Task', WhatId = A.Id)); }
upsert toBeAddedTasks; }i need to know why it is not working similar in both scenario
thanks
Log In to reply.
Popular Salesforce Blogs
Decorators in LWC | Salesforce Developer Guide
Lightning Web Components (LWC) is a framework provided by Salesforce to develop fast, responsive, and reusable web components for their platform. One of the key…
Maximizing Efficiency: Exploring Related Lists with PWR Components
Introduction Salesforce, renowned for its CRM capabilities, faces limitations in managing intricate business scenarios, particularly in e-commerce. Traditional Salesforce-related lists struggle with dynamic data and…
Know The Importance of CRM and ERP Integration | Salesforce
At a high level, integrating ERP and CRM empowers your employees to provide fast, informed and more personalized customer service. The reason for ERP and CRM…
Popular Salesforce Videos
Salesforce Platform Quick Tip: How to Access Popular Items in a Single Click
Want to get to the things you use most with fewer clicks? Trailblazer and Senior Salesforce Developer, Ellie Matthewman shows us how to use favourites…
Salesforce App Builder Certification Questions Explained
CRM tools serve as the base for managing small and large-scale businesses, and Salesforce is among the best CRM tools in the industry. Therefore, Salesforce…
Duplicate Management In Salesforce | Duplicate Rule and Matching Rule
Learn how to work with duplicate rules and duplicate records in Salesforce. This video will cover the following points - 1. Matching Rule (1:20) Get…