function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MaxaMaxa 

Insert task trigger

Hi,I have created following trigger, this trigger supposed o evaluate opportunity ifType is equal to new business and CC coordinator is not blank it should create new task with subject first contact, but it does not and I have no idea how to fix, can any one help please

trigger assignTask on Opportunity (before insert, before update) { List<Task> task = new List<Task>(); List<Opportunity> newOpportunity = new List<Opportunity>(); for (Integer i = 0; i < Trigger.new.size(); i++) { if ((Trigger.new[i].Type == 'New Business')&&(Trigger.new[i].CC_Co_ordinator__c ==null)) { System.debug('triggerfire'); task.add(new Task( whatid=Trigger.new[i].Id, OwnerId=Trigger.new[i].CC_Co_ordinator__c, Subject='First Contact ' )); } } insert task; }

 

Best Answer chosen by Admin (Salesforce Developers) 
MaxaMaxa

i found the problem it was due to field update done by workflow,

any way ignore this post

All Answers

MaxaMaxa

its actually workign now

problem i'm having now its creates 2 tasks,

any ideas why?

MaxaMaxa

i found the problem it was due to field update done by workflow,

any way ignore this post

This was selected as the best answer
AMR27AMR27

Hey Maxa,

 

Can you extrapolate on the two task issue?

 

I am running this myself and everything works great, except it creates two tasks for me as well.

 

I don't see any live WF rules that would have anything to do with this, so I am at a loss as to what to do.

 

Please let me know what you did to fix it, or if anyone else can help it would be appreciated.

 

Thanks - 

 

Alex


 

MaxaMaxa

i have inserted tick box task created, and i update it when trigger runs, also put a condidtion if task created false then run trigger