You need to sign in to do that
Don't have an account?
Tin013
Newbie Trigger question
Hi all,
I have a custom HR_Job__c object. On which I have Application_Status__c picklist field. Everytime a value is changed, I would like to create a task on the related filed with task subject being the updated value from the Application_Status__c pick list.
I know it can be done through a trigger but I am not sure how I can go about implementing this.
If someone can point me to the right direction, i would be very thankful.
Many thanks!
Tim
This sounds like something you could achieve using Workflow too right - using the New Task Workflow Action.
http://shivasoft.in/blog/webtech/salesforce/step-by-step-salesforce-tutorial-–-creating-workflow-rule-–-5-of-n/
Hi there,
Thanks for your reply. I am afriad not. I actually thought of that. With workflow, I wouldn't be able to bring down the status field value into the task subject line.
I also need to put in a few other info into Task such as status and date etc.
I think the only way around to this is through trigger.
Could someone tell where I could find a similar example to meet this sort of requirements please?
Thanks
trigger HRJobAfter on HR_Job__c {after update}
{
Task[] tasksToInsert = new Task[]{};
for(HR_Job__c hrJob : trigger.New)
{
if(trigger.OldMap.get(hrJob.Id).Application_Status__c != hrJob.Application_Status__c)
{
//IN THE CONSTRUCTOR SET WHATEVER ELSE FIELDS YOU NEED, I'VE JUST SET WHATID AND SUBJECT
tasksToInsert.add(new Task(WhatId=hrJob.Id, Subject=hrJob.Application_Status__c);
}
}
if(tasksToInsert != null && !tasksToInsert.isEmpty())
Database.insert(tasksToInsert);
}
Hi Ritesh Aswaney
Many thanks for your reply. I will have go!
Cheers