You need to sign in to do that
Don't have an account?
Katie Hamberg
Trigger Permissions
I have a trigger that auto creates a task if a contact is still in open status. The trigger is working fine for me, but for a standard user it is not. There isn't code within the trigger that would be preventing this, so I'm not sure why this would be happening?
Thanks!
Thanks!
trigger createNextTask on Task (before update) {
Map<Id,string> whatIds = new Map<Id,string>();
Set<Id> ECIds = new Set<Id>();
Set<Id> EPIds = new Set<Id>();
Map<Id,string> whoIds = new Map<Id,string>();
set<Id> EI2ContactIds = new Set<Id>();
set<Id> EI2ProjectIds = new Set<Id>();
List<Task> EI2tskList = new List<Task>();
Task EI2tsk;
private Id eidTaskRecordTypeId = Schema.SObjectType.Task.getRecordTypeInfosByName().get('EI2').getRecordTypeId();
if(TriggerHandler.firstRun) {
for(task t:trigger.new){
if(t.RecordTypeId == eidTaskRecordTypeId){
string whId = t.WhoId;
if(whId!= null && whId.startsWith('003')&& !EI2ContactIds.contains(t.WhoId)){
EI2ContactIds.add(t.WhoId);
}
string whaId = t.WhatId;
// cnte sandbox id for ISEIF and EI2 Projects is a1Z
// if(whaId!= null && whaId.startsWith('a1Z')&& !EI2ProjectIds.contains(t.WhatId)){
// production id for ISEIF and EI2 Projects is a0Y
if(whaId!= null && whaId.startsWith('a0Y')&& !EI2ProjectIds.contains(t.WhatId)){
EI2ProjectIds.add(t.WhatId);
}
}
}
for(contact c :[select Id,EI2_Act_on_Status__c,ARES_Status__c,Real_Time_Status__c from contact where Id IN :EI2ContactIds ]){
if( ( c.EI2_Act_on_Status__c =='Interested'|| c.EI2_Act_on_Status__c == 'Referred')||(c.ARES_Status__c == 'Interested'||c.ARES_Status__c =='Referred')
||(c.Real_Time_Status__c == 'Interested'|| c.Real_Time_Status__c == 'Referred')){
ECIds.add(c.id);
}
}
for(ISEIF_and_EI2_Projects__c p :[select Id, Project_Status__c, ARES_Status__c, EI2_Project_Status__c From ISEIF_and_EI2_Projects__c where Id IN :EI2ProjectIds ]) {
if( p.EI2_Project_Status__c=='Active' || p.EI2_Project_Status__c =='On Hold' || p.EI2_Project_Status__c=='FO Hold' ||
p.EI2_Project_Status__c=='Construction' || p.EI2_Project_Status__c=='Audit' ||
p.EI2_Project_Status__c=='QAQC' || p.EI2_Project_Status__c=='House Party Scheduled' ||
p.ARES_Status__c=='Active' || p.ARES_Status__c =='On Hold' || p.ARES_Status__c == 'FO Hold'||
p.Project_Status__c=='Active'|| p.Project_Status__c=='On Hold' || p.Project_Status__c=='FO Hold' ){
EPIds.add(p.id);
}
}
for(task ta:trigger.New){
string status = ta.TStatus__c;
string priority = ta.TPriority__c;
string program = ta.TProgram_Related_To__c;
string subj = ta.TSubject__c;
if( (ECIds.contains(ta.WhoId) || EPIds.contains(ta.WhatID)) && ta.Status == 'Completed'){
if(status== null){
ta.TStatus__c.adderror('The Contact or ISEIF and EI2 Project is still Open. Please Fill the Status field to create a new task');
}
if(priority == null){
ta.TPriority__c.adderror('The Contact or ISEIF and EI2 Project is still Open. Please Fill the Priority field to create a new task');
}
if(program == null){
ta.TProgram_Related_To__c.adderror('The Contact or ISEIF and EI2 Project is still Open. Please Fill the Program Related To field to create a new task');
}
if(subj== null){
ta.TSubject__c.adderror('The Contact or ISEIF and EI2 Project is still Open. Please Fill the Subject field to create a new task');
}
if(status!=null&&priority!=null&&program!=null&&subj!=null){
EI2tsk = new Task(Subject = ta.TSubject__c,Priority = ta.TPriority__c,
Program_Related_To__c = ta.TProgram_Related_To__c,
ActivityDate = Date.Today(), OwnerId= ta.OwnerId,
Status = ta.TStatus__c,
WhoId = ta.WhoId, WhatId = ta.WhatId,
Interaction_Result__c=ta.TInteraction_Result__c,
Interaction_Source__c = ta.TInteraction_Source__c,
Interaction_Type__c = ta.TInteraction_Type__c,
Activity_data_time__c=ta.TCompleted_date_time__c,
RecordTypeId=ta.RecordTypeId);
EI2tskList.add(EI2tsk );
}
}
}
if(EI2tskList.size()>0){
database.insert(EI2tskList,false);
}
TriggerHandler.firstRun = false;
}
}