You need to sign in to do that
Don't have an account?
Update Lead Status from task Trigger
I have a trigger on Task object (events: before insert, after insert, after update). The functionality of this trigger is – I have a set of call outcomes that determines the Lead status, which is coded using controllers and VF page. These values are nowhere build in the database as field values and are controlled by code. For example, when the user calls a prospect and based on the call outcomes he/she enters, the lead status will be set – like if it is “Number busy” the status remains as Open-Not Contacted, “Not interested” the status moves to Open-Suspended, “Interested” means “Working-Contacted”. And this outcomes are created as a “completed task” in to the Task object’s Activity History.
Now I am integrating a third party tool for Click-to-call functionality. This app gives me a handle to do same functionality in name of “Call dispositions”. Call dispositions is a custom picklist field in Activity. Now my requirement is –
- I need to trigger my lead status with this Call disposition i.e. each set of disposition should correspond to each status. And this functionality should not affect the earlier code that is append running in the system.
The problem is when I try to add few more conditions the system gets confused to execute what and when. I tried if-else, but it didn't work for me. Below is the piece of trigger I am speaking about - Check for the line of code that is commented out.
Trigger TaskTrigger on Task (before insert,after update,after insert) {
if(trigger.isinsert && trigger.isAfter){
list<lead> leadtoupdate = new list<lead>();
set<string> openNotContactedsubjectset = new set<string>{'Busy', 'Wrong Number', 'Voicemail'};
set<string> openSuspendedsubjectset = new set<string>{'Not Interested', 'Negative Email'};
set<string> workingContactedsubjectset = new set<string>{'Contacted', 'Okay for the deal', 'Shown Interest'};
for(task t : trigger.new){
if(t.whoid!=null && string.valueof(t.whoid).startsWith('00Q')){
/* Below code is for Call dispositions in Task Object
if(t.appExch__Call_Disposition__c == 'Wrong Number'||t.appExch__Call_Disposition__c == 'Number Busy'||t.appExch__Call_Disposition__c == 'Person Busy')
{
leadtoupdate.add(new lead(id=t.whoid,status='Open - Suspended'));
}
*/
if(openNotContactedsubjectset.contains(t.subject)){
leadtoupdate.add(new lead(id=t.whoid,status='Open - Not Contacted'));
else if(openSuspendedSubjectSet.contains(t.subject)){
leadtoupdate.add(new lead(id=t.whoid,status='Open - Suspended'));
}
else if(WorkingContactedSubjectSet.contains(t.subject)){
leadtoupdate.add(new lead(id=t.whoid,status='Working - Contacted'));
}
}
}
if(leadtoupdate.size()>0){
update leadtoupdate;
}