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
nagalakshminagalakshmi 

how to set rule criteria through trigger

Hi,

 

I want to share the records through trigger based on workflow rule.  I mean if the rule criteria is 'when the record is create' then i use the 'after insert' event.

 

If the rule criterial in work flow is 'When a record is created, or when a record is edited and did not previously meet the rule criteria'. How can i set the rule criteria in trigger... Any one please help me...

 

Thanks,

Lakshmi.

sourav046sourav046

Totaly unclear requirement .Be more specific possibly with an example .

 


Make sure you are not mixing up  Time-based workflow trigger and  APEX trigger  .

nagalakshminagalakshmi

Hi,

 

My requirement is,

 

I need to automate the work flow rules through triggers. in that work flow rule i am sending a email for user with sharing instructions of a record. I need to set that sharing criteria of a record through trigger.  I am doing everything fine... But i got a doubt that is, how to set the rule criteria in trigger if the work flow having ' When a record is created, or when a record is edited and did not previously meet the rule criteria'. 

 

Thanks,

Laskhmi

 

 

Madhan Raja MMadhan Raja M

Hi Laskhmi,

 

Use 'before insert', 'before update' events and create a checkbox called "previously met?". This checkbox helps you to track, whether the condition is satisfied in the previous condition.

 

Ex:

Assume, previously_met__c=FALSE;

 

If(previously_met__c!=TRUE)

{

// your logic

previously_met__c=TRUE;

}

 

 

Madhan Raja M

SFDC-SDSFDC-SD

You can use

Trigger.isInsert - (is Created )

 

Trigger.isUpdate && (sObject.Sharing_flag__c <> trigger.oldMap.get(Objectid).Sharing_flag__c)

(is edited ) and - Compare flag value(Create a custom field Sharing flag, set if Sharing Rules are set,

Note: don't add it to page layout)

 

 

 

 

nagalakshminagalakshmi

Hi,

 

Did you mean in Sharing_flag__c, shall i keep the sharing rule value like read or write somthing once edited.......

 

Thanks,

Lakshmi

SFDC-SDSFDC-SD

You can use the content of the variable however you want to use it, all depends on requirements.

 

If you are going to change the sharing rules based on some criteria in a field(like status) you can use the same field instead of additional custom field  like Sharing_flag__c.

 

Note: Sharing_flag__c is just a example I used, you can use the same fields and values that trigger the workflow