You need to sign in to do that
Don't have an account?
Sandra Wicket
Trigger - create new record
Hey Guys,
i need to complete this trigger. It works like it is.. the problem is, everytime when i update the account, the trigger creates a new Case ( i am not a Coder but i understand why ^^) The Trigger is simple and i hope you can see what i want. I want the trigger to stop if the last (newest) case is in progress (status = in progress). So the trigger should only fire when there is no Case in progress. How can i fix this ? I want to learn apex and i understand why the trigger is still running but i dont know how to fix it. Thanks for your help guys :)
i need to complete this trigger. It works like it is.. the problem is, everytime when i update the account, the trigger creates a new Case ( i am not a Coder but i understand why ^^) The Trigger is simple and i hope you can see what i want. I want the trigger to stop if the last (newest) case is in progress (status = in progress). So the trigger should only fire when there is no Case in progress. How can i fix this ? I want to learn apex and i understand why the trigger is still running but i dont know how to fix it. Thanks for your help guys :)
List<case> caToInsert = new List<case>();
for(Account acc : Trigger.new){
if(acc.Rating_Status__C != 'time for Rating'){
integer num = [select count() from case where AccountId = :acc.id and Status = 'in progress'];
if(num==0)
{
Case cas = new Case(Account=acc.id);
cas.subject = 'Rating time';
cas.origin = 'Rating';
cas.Status = 'in progress';
cas.betreut_von_c='Donalod Duck';
caToInsert.add(cas);
}
}
}
try{
insert caToInsert;
}
catch(system.Dmlexception e){
system.debug(e);
}
}
Insert this code it help u ...
All Answers
List<case> caToInsert = new List<case>();
for(Account acc : Trigger.new){
if(acc.Rating_Status__C != 'time for Rating'){
integer num = [select count() from case where AccountId = :acc.id and Status = 'in progress'];
if(num==0)
{
Case cas = new Case(Account=acc.id);
cas.subject = 'Rating time';
cas.origin = 'Rating';
cas.Status = 'in progress';
cas.betreut_von_c='Donalod Duck';
caToInsert.add(cas);
}
}
}
try{
insert caToInsert;
}
catch(system.Dmlexception e){
system.debug(e);
}
}
Insert this code it help u ...
thanks a lot ! Can i ask you sth ? I dont understand this line
where AccountId = :acc.id and Status = 'in progress'
why " =" + " : "
i dont understand the spelling ^^
Best Wishes
Jorma