Tuesday, October 30, 2018

Process Builder is not fired when field update is called from Approval Process

In Final Approvals section ; in Approval Process we have field update to update Status field. In Process Builder , we have some action that need to be done when Status field is updated in Approval Process.However this process builder is not fired.

To handle this, in Field Update in Approval Process , check Re-evaluated Workflow Rules after Field Change as picture below.

What happen if field updated from Approval Process.
  1. Workflow - does not fires untill Re-evaluate workflow checkbox is ticked on your field update
  2. Process Builder - does not fires untill Re-evaluate workflow checkbox is ticked on your field update
  3. Trigger - will fire if conditions are matched

This is explained in article here .

Field Updates That Re-evaluate Workflow Rules

If Re-evaluate Workflow Rules After Field Change is enabled for a field update action, Salesforce re-evaluates all workflow rules on the object if the field update results in a change to the value of the field.
  • If the field update changes the field’s value, all workflow rules on the associated object are re-evaluated. Any workflow rules whose criteria are met as a result of the field update will be triggered.
  • If any of the triggered workflow rules result in another field update that’s also enabled for workflow rule re-evaluation, a domino effect occurs, and more workflow rules can be re-evaluated as a result of the newly-triggered field update. This cascade of workflow rule re-evaluation and triggering can happen up to five times after the initial field update that started it.
  • Make sure that your workflow rules aren’t set up to create recursive loops. For example, if a field update for Rule1 triggers Rule2, and a field update for Rule2 triggers Rule1, the recursive triggers may cause your organization to exceed its limit for workflow time triggers per hour.
  • In a batch update, workflow is only retriggered on the entities where there is a change.
  • Only workflow rules on the same object as the initial field update will be re-evaluated and triggered.
  • Only workflow rules that didn’t fire before will be retriggered.
  • Cross-object workflow rules aren’t candidates for re-evaluation.
  • Cross-object field updates that cause a field value to change don’t trigger workflow rule re-evaluation on the associated object.
  • An approval process can specify a field update action that reevaluates workflow rules for the updated object. If, however, the re-evaluated workflow rules include a cross-object field update, those cross-object field updates are ignored.
  • Time-dependent actions aren't executed for a reevaluated workflow rule in the following situations:
    • The reevaluated workflow rule’s immediate actions cause the record to no longer meet the workflow rule criteria.
    • An Apex after trigger that is executed as a result of a workflow or approvals action causes the record to no longer meet the workflow rule criteria.

Discussion about this can be found here .

Thursday, October 18, 2018

What happen on Content Document Link if we upload Salesforce Files from record?

This entry specifically to know more about ContentDocumentLink which are not represented in diagram below.I happen to know more about this object after I experimenting on content's trigger(in future post).

To understand how the content relationship works please refer to diagram below .
 content objects diagram version 44.
refer to Salesforce for latest diagram

The highlight of this article is to identify ContentDocumentLink object that not appear in the diagram above.

ContentDocumentLink is Represents the link between a Salesforce CRM Content document or Salesforce file and where it's shared.
Field LabelAPI Field NameTypeLengthPrecisionScale
ContentDocumentLink IDIdid15
Is DeletedIsDeletedboolean
Linked EntityLinkedEntityIdreference15
Share TypeShareTypepicklist40
System ModstampSystemModstampdatetime
Experiment : Upload a file from Opportunity record.Once upload, click on the file and copy the id in URL. The id is represent contentdocumentid.Open Developer Console --> Execute Anonymous. Paste this code with contentdocumentid that you got.

system.debug('@@@ ContentVersion :  '+new List<ContentVersion> ([select Id ,ContentDocumentId from ContentVersion where ContentDocumentId ='06990000005Eor5']).size());
system.debug('@@@ ContentDocument :  '+new List<ContentDocument> ([select Id  from ContentDocument where Id ='06990000005Eor5']).size());
system.debug('@@@ ContentDocumentLink :  '+new List<ContentDocumentLink> ([select Id ,ContentDocumentId from ContentDocumentLink where ContentDocumentId ='06990000005Eor5']).size());

The result is like below, notice that we have two contentdocumentlink records.

To check what actually record being inserted in ContentDocumentLink, please run SOQL below:
select Id, ContentDocumentId, LinkedEntityId, IsDeleted, LinkedEntity.Type from ContentDocumentLink where ContentDocumentId ='06990000005Eor5' 
Result - LinkedEntity.Type are User (who upload the File) and Opportunity (the record where the file is uploaded)

Hope this will give you clear picture on what ContentDocumentLink object is doing.I am doing testing and find something interesting on content object which I will share with you later.

Happy coding