You need to sign in to do that
Don't have an account?
Manjunath reddy 6
The trigger will add a task to any opportunity inserted or updated with the stage of 'Closed Won'. The task's subject must be 'Follow Up Test Task'.The Apex trigger must be called 'ClosedOpportunityTrigger'
With 'ClosedOpportunityTrigger' active, if an opportunity is inserted or updated with a stage of 'Closed Won', it will have a task created with the subject 'Follow Up Test Task'.
To associate the task with the opportunity, fill the 'WhatId' field with the opportunity ID.
This challenge specifically tests 200 records in one operation.
I tried with the above code, task is not created.
Create an Apex trigger for Opportunity that adds a task to any opportunity set to 'Closed Won'.
trigger ClosedOpportunityTrigger on Opportunity (after insert,after update) { List<task> carry=New List<task>(); for(opportunity opp:trigger.new){ if(opp.stagename=='closed own'){ task t=new task(whatid=opp.id); carry.add(t); } } insert carry; }
The trigger will add a task to any opportunity inserted or updated with the stage of 'Closed Won'. The task's subject must be 'Follow Up Test Task'.The Apex trigger must be called 'ClosedOpportunityTrigger'
With 'ClosedOpportunityTrigger' active, if an opportunity is inserted or updated with a stage of 'Closed Won', it will have a task created with the subject 'Follow Up Test Task'.
To associate the task with the opportunity, fill the 'WhatId' field with the opportunity ID.
This challenge specifically tests 200 records in one operation.
I tried with the above code, task is not created.
All Answers
Additionaly u need populate subject field in task record as "Follow Up Test Task"
Try this code As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks,
Alex
Try this below code
Follows my way to solve this challenge:
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {
List <Task> opptask = new List<Task>();
List<Opportunity> opp = [SELECT Id FROM Opportunity WHERE Id in :Trigger.New AND StageName = 'Closed Won'];
for (integer i = 0; i < opp.size(); i++)
{
task t = new task(WhatId = opp.Id, subject = 'Follow Up Test Task');
opptask.add(t);
}
if (opptask.size() > 0)
insert opptask;
}
Is this something amiss in the system since the fields are in the Opportunities object or do I have a syntax issue?
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Discount_Percent__c]: [Discount_Percent__c]
am facing this error with the below code, Can anyone look into the code and tell me whats wrong?
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {
List<Task> tList = new List<Task>();
FOR (Opportunity opp: [SELECT Id, StageName FROM Opportunity WHERE StageName = 'Closed Won'])
{
task values = new task (WhatId = opp.Id, Subject = 'Follow Up Test Task');
tList.add(values);
}
if (tList.size () > 0 ) {
insert tList;
}
}
Challenge not yet complete in My Trailhead Playground 1
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “Opportunity Management” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records: REQUIRED_FIELD_MISSING: Required fields are missing: [AccountId]. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 377956270-241564 (-667225970): []
I'm getting this error continuously can someone help me out, please
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update)
{
if(Trigger.isAfter)
{
if(Trigger.isInsert || Trigger.isUpdate)
{
List<task> tasLists = new List<task>();
for(opportunity opp : Trigger.new)
{
if(opp.stagename =='Closed Won')
{
task tas = new task(Whatid = opp.id, Status = 'Active', Subject = 'Follow Up Test Task',
Priority = 'High', ActivityDate = system.today());
tasLists.add(tas);
}
}
if(tasLists.size()>0)
{
insert tasLists;
}
}
}
}
List<Opportunity> toProcess =null;
switch on Trigger.operationType{
when AFTER_INSERT{
toProcess=Trigger.New;
}
when AFTER_UPDATE{
toProcess= [select id,StageName from Opportunity where id in:Trigger.New AND StageName='Closed Won'];
}
}
List<Task> taskList = new List<Task>();
for(Opportunity p:toProcess){
if(p.StageName=='closedWon'){
Task t = new Task();
t.WhatId=p.Id;
t.subject='Follow Up Test Task';
taskList.add(t);
}
insert taskList;
}