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
ShaTShaT 

Case Assignment Rule from trigger

Hi

  I have a trigger  on oppertunity .When stage is closed won . i m creating a case and assisning a r Assignment rule to it with Database.DMLOptions.  I have a update trigger on case. When a new csae is inserted . Update trigger is fired. 

This is because of the Assignment rule . it is udated after case is created.

How can i stop  firying the update on case.

 

Trigger-:

 oDatabase.DMLOptins dmo = new Database.DMLOptions();
 dmo.assignmentRuleHeader.useDefaultRule= true;

if(o.StageName == 'Closed Won' && o.Cases__r.size()<1 )  {
        try
        {
              Case  c = new Case();
              c.AccountId = o.AccountId;
              c.Opportunity__c = o.Id;
              c.Subject = o.Name;
              c.setOptions(dmo);                      
              caseList.add(c);
               
        }
        catch(Exception e){}   
  }
  if(!(caseList.isEmpty())){
     
    insert caseList;
  
  }

 

After this update trigger is executed.

Please Help!!!!!!!!!!!!!!!

 

Thanks

Shailu

minkeshminkesh

Hi,

      Use Trigger.isUpdate and Trigger.isInsert to check weather it is being updated or Inserted and according to this write your code.

 

ShaTShaT

Thanks ...

But is is not also working... its beacuse Assignment rule is updated after creation.

 

Any other ideas!!!!

 

Thanks

Shailu

JayantJayant

Use a static variable and set it in your code to control execution.

For e.g.

Put this in some public class, say ABC -

public static boolean recursion = true;

 

Use it in your trigger i.e. set it as false in your trigger eg.

 

ABC.recursion = false;

if (ABC.recursion == false)

{

your business logic here...

}

 

 

In the other trigger i.e. update trigger, check for the value of recursion, if it's false, it means the control has came from your trigger (otherwise it would have been true).

So enclose all the logic of update trigger in If (ABC.recursion == true) so that it executes in all cases other than when control comes from your code.

 

You may also use any other combination of Static variables but that's how it should be done.

 

Thanks a lot.