You need to sign in to do that
Don't have an account?
Angela Schloeder
Trigger -
I cannot figure out what Im doing wrong. I need it to have Priority of Low if no Direct Dial and/or Mobile on Contact and Medium if there is Direct Dial AND/OR Mobile. Medium works but not Low.
Any ideas? Help is very much appreciated.
trigger createTask on Contact (after insert, after update) {
List<Task> listOfTaskToBeInserted = new List<Task>();
Task newtask;
for(Contact con : trigger.new){
if((trigger.isInsert && (con.Direct_Dial__c == '' || con.MobilePhone == '')) || (trigger.isUpdate && trigger.oldMap.get(con.id).Exec_Type__c != con.Exec_Type__c && (con.Exec_Type__c == 'Key Exec' || con.Exec_Type__c == 'Approved Exec'))){
newtask = new Task();
newtask.WhatId = con.AccountId;
newtask.Subject = 'Target';
newtask.whoId = con.id;
newtask.ActivityDate = system.today();
newTask.Status = 'Open';
newTask.Attendee__c = con.Task_Attendee__c;
if(con.Direct_Dial__c == ''){
newTask.Priority = 'Low';
}
else{
newTask.Priority = 'Medium';
}
listOfTaskToBeInserted.add(newTask);
}
}
if(listOfTaskToBeInserted.size() > 0){
insert listOfTaskToBeInserted;
}
}
Any ideas? Help is very much appreciated.
trigger createTask on Contact (after insert, after update) {
List<Task> listOfTaskToBeInserted = new List<Task>();
Task newtask;
for(Contact con : trigger.new){
if((trigger.isInsert && (con.Direct_Dial__c == '' || con.MobilePhone == '')) || (trigger.isUpdate && trigger.oldMap.get(con.id).Exec_Type__c != con.Exec_Type__c && (con.Exec_Type__c == 'Key Exec' || con.Exec_Type__c == 'Approved Exec'))){
newtask = new Task();
newtask.WhatId = con.AccountId;
newtask.Subject = 'Target';
newtask.whoId = con.id;
newtask.ActivityDate = system.today();
newTask.Status = 'Open';
newTask.Attendee__c = con.Task_Attendee__c;
if(con.Direct_Dial__c == ''){
newTask.Priority = 'Low';
}
else{
newTask.Priority = 'Medium';
}
listOfTaskToBeInserted.add(newTask);
}
}
if(listOfTaskToBeInserted.size() > 0){
insert listOfTaskToBeInserted;
}
}
Try the below and let me know if you face any issues :