You need to sign in to do that
Don't have an account?
Lisa Horne
Apex Trigger to Create Task from Lead
I need some assitance with creating a Trigger that creates a task from a lead record that has text in the Lead Web Comment Field to create a task for the Lead owner, with priority of Normal, Subject of Text "Lead Web Comment", Status of Lead Web Comment.
I have this trigger started but don't know exactly how to have all the fields populated with the above requirements.
Could someone please help?
trigger Lead_After_Insert on Lead (after insert)
{
list<Task> lNewTasks = new list<Task>();
for(integer i=0; i<trigger.new.size(); i++)
{
lNewTasks.add(MyTask = new Task(
Subject = 'Lead Web Comment',
WhoID = trigger.new[i].id
*Other Task Fields Here*
);
}
insert lNewTasks;
}
I have this trigger started but don't know exactly how to have all the fields populated with the above requirements.
Could someone please help?
trigger Lead_After_Insert on Lead (after insert)
{
list<Task> lNewTasks = new list<Task>();
for(integer i=0; i<trigger.new.size(); i++)
{
lNewTasks.add(MyTask = new Task(
Subject = 'Lead Web Comment',
WhoID = trigger.new[i].id
*Other Task Fields Here*
);
}
insert lNewTasks;
}
...and Test Class
This is the Test Class. Done. Now you are prepared to deploy and enjoy!
Please run all tests and Please let me know if I helped.
All Answers
Task t = new Task();
WhoId = trigger.new[i].Id;
Subject = 'Web Lead';
OwnerId = trigger.new[i].OwnerId
ActivityDate = date.today();
Hi Lisa,
You don't need trigger to solve this problem. Just create a workflow like as ScreenShot below:
Workflow rule:
Task associated with your workflow rule:
Please let me know if I helped.
Give me a minutes to help you with the sample code.
...and Test Class
This is the Test Class. Done. Now you are prepared to deploy and enjoy!
Please run all tests and Please let me know if I helped.
Do you solved this question? If my solution works to you please mark her as a best answer.
Thank you for the Workflow instructions. Is there a way to modify the Assigned To field in this Workflow so that is is a Pick List of Users, e.g. sales personnel, instead of having to put one person's name?
I have a similar query
I have a web to lead form and need to update a field on the lead created once the customer has paid.
We are putting a credit card payment module called Stripe on the return URL page
Any ideas how I can don this?
I realise that the leads are not created immediately but hopefully by the time that the payment has gone through it should be there?
Any assistance woudl be gratefully received
I am doing this work in my spare time for a charity and although experienced I am not a developer
Many thanks
Laura