You need to sign in to do that
Don't have an account?
trigger fire two times
Hi,
I am trying to create task when account recrod type is dealer customer and manafer value polulate form null value.
Here is my code.
trigger assignTask on Account (before update) { List<Task> task = new List<Task>(); for (Integer i = 0; i < Trigger.new.size(); i++) { //System.debug('territorys'+territory); if(Trigger.new[i].RecordTypeId=='012300000000AGr'){ if ( (Trigger.old[i].Account_Manager__c != Trigger.new[i].Account_Manager__c)&&(Trigger.old[i].Account_Manager__c ==null)){ String taskname='New Dealer SAP '+Trigger.new[i].Name; if(taskname.length()>79){ taskname=taskname.substring(0,78); } task.add(new Task( RecordTypeId ='01240000000Ditr', // RecordTypeId ='012T00000004Uql', WhatId=Trigger.new[i].Id, OwnerId=Trigger.new[i].Account_Manager__c, Subject=taskname )); } } } }
now if I change first recrod type dealer prospect to dealer customer- and saved it.
after that with same account edit it and add account manager it works fine.It jsut create one task.
anothe senario for update:account which is dealer prospect and I click on change recrod type and choose delaer cusomter as record type and hit next button and add manager info and saved it. It created two task.
Can some one points out why in second senarion it creates two task,while only one time upsate happens.
first seanrio working fine,but second it fails.
-thanks
trigger assignTask on Account (before update)
{
List<Task> task = new List<Task>();
for (Integer i = 0; i < Trigger.new.size(); i++)
{
//System.debug('territorys'+territory);
if(Trigger.new[i].RecordTypeId=='012300000000AGr')
{
if ( (Trigger.new[i].Account_Manager__c != null && Trigger.old[i].Account_Manager__c ==null)
{
String taskname='New Dealer SAP '+Trigger.new[i].Name;
if(taskname.length()>79)
{
taskname=taskname.substring(0,78);
}
task.add(new Task(
RecordTypeId ='01240000000Ditr',
// RecordTypeId ='012T00000004Uql',
WhatId=Trigger.new[i].Id,
OwnerId=Trigger.new[i].Account_Manager__c,
Subject=taskname
));
}
}
}
if(task.size() > 0)
{
insert task;
}
}
thanks for reply.
task.size>0 does not make any sense to me.
As its already created two recrod,and if I apply this code,it will still create two recrod.
I changed code which you gave, and same two task was created.
-any idea?
I'm not sure if this is the problem, but check out #11 on this link. If the record is updated via a workflow, then the update trigger will fire again.
Good luck
Jeff Douglas
Informa Plc
http://blog.jeffdouglas.com
Hi,
I have chcked workflow and there is not work flow related task in application.
If I changed subject,two task subject also changed.So it's not workflow issue.
Now thing is I have dealer id field in acocunt set as external id.
If I changed first recrodtype with dealer id and save recrod. after this if I place manager,task will created once.
If I changed put dealer id,recrod type nad manager info all at once in edit page,two time task created.
Could you provide your thoughts in this external id and how update happens?
-Thanks,