-
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

Top Salesforce Spring '22 Features (Part - 2)
Salesforce Spring '22 release features part 2 is here to elevate, enhance and run your business efficiently. Let's have a look at what these features…

5 Steps to Maximize Your Document Strategy Within Salesforce
Drowning in documents can hinder productivity and innovation. Modernize your document management system and unlock a wave of efficiency.. Buying habits continuously change, and it…

Salesforce Migration Services | All You Need to Know
Transitioning to Salesforce, a robust and versatile CRM platform, can significantly enhance your business operations. However, the migration process can be intricate and demanding. This…
Popular Salesforce Videos
Prepare for Your Salesforce Pardot Implementation
If you're preparing for your Pardot implementation, you've come to the right place! Pardot implementation is a complex, multi-step process. In this video, we will…
Pardot Engagement Studio | Salesforce
Learn how to use Pardot Engagement Studio to engage and attract prospective students. Do let us know in the comment section if you have any…
14 Questions Asked in 95% Salesforce Interviews
In this video, Dan Croitor provides a list of 14 questions that are typically asked in Salesforce interviews. He goes over each question in detail,…