Pages

Showing posts with label Process Builder. Show all posts
Showing posts with label Process Builder. Show all posts

Monday, November 23, 2020

Salesforce: Notification Builder

Salesforce offers an easy way to notify a user, such as a record owner, team members, etc. You do not need to wring a single line of code to build this (if you prefer); remember the admin motto "click-not-code").

The notification will appear in the Salesforce mobile app and Lightning experience (desktop web browser), but you can determine if you want the notification to appear in the Salesforce mobile app only, the Lightning experience only, or both.

Only a few steps for an admin to build the notification.

1. Create Custom Notifications

This is where we determine where the notification will show: mobile, desktop, or both. Navigate to the Setup menu and search for Salesforce Notifications.



From the Setup menu, search for Custom Notifications; you can create or edit existing notifications.


Once added, the new custom notification will be added and shown under Notification Delivery Settings.


2. Send Custom Notification from Process Builder

In addition to using Process Builder, the notification also can be sent from Flow Builder, Apex, and API.

In the Process Builder, from Action Type, select "Send Custom Notification".


Then, we can define who will be notified

Activate the Process once completed.


Here is a sample of notification in Lightning experience for Opportunity owner


Monday, January 22, 2018

Implementing Custom Permission for Workflow and Process Builder

More than 3 years ago, we wrote a blog on implementing Custom Permission for Validation Rules. In this blog, we are going to share the same Custom Permission, but for automation, including Workflow and Process Builder.

We'll not discuss further on how to create Custom Permission and Permission Set, so please check the blog mentioned earlier if you need a reference to create Custom Permission and Permission Set.

Workflow
From Workflow Rule Criteria, select formula evaluates to true.
If you have Custom Permission created, you will see $Permission > under Insert Field.



In this sample, I have a Custom Permission name "Edit_Customer_Custom_Permission", select that permission and add it to Rule Criteria $Permission.Edit_Customer_Custom_Permission.



With this criteria, only users assigned to the Permission Set will trigger the workflow, otherwise, the workflow will not be fired.

Process Builder
Let's use the same Custom Permission - Edit_Customer_Custom_Permission. From Criteria - "Define Criteria for this Action Group"
1. Select Formula evaluates to true.
2. In the Build Formula panel, click System Variable.


3. Select Permission >


4. Type or select the Custom Permission, click Choose button.



5. Now you have the formula built $Permission.Edit_Customer_Custom_Permission.



This is the same criteria with Workflow criteria's above.


ReferenceCustom Permission for Validation Rule



Friday, January 12, 2018

Salesforce: Update Records criteria in Process Builder

Until Spring '18 release, in Update Record action, if we have multiple conditions, we can't customize the logic for the condition with AND, OR. Feel free to vote my idea Process Builder - filter logic in Updating Records action.

no option to define logic


While in Define Criteria, the option to customize logic is available since long time back.



If we drill down further, for the condition in Record Update, by default the relation for each condition is AND, however, if we define more than 1 condition using the same field, the relation of the conditions for the same field would be OR, here an example:


From above sample, we define Account Source twice, and Support Level twice, the logic for this can be translated as (1 OR 2) AND (3 OR 4).

Here quote from Salesforce documentation Update Records from a Process.
When you define multiple filters, the filter logic usually defaults to AND. However, if multiple filters have the same field selected and use the equals operator, the filters are combined with OR. For example, your filters check whether a case’s Type equals Problem (1), Type equals Feature Request (2), and Escalated equals true (3). At runtime, those filters are combined to (1 OR 2) AND 3.


ReferenceUpdate Records from a Process



Monday, December 25, 2017

Salesforce: Schedule Action in Process Builder

You may read and see somewhere that Process Builder far superior to Workflow, but for some reason, you don't see the option to schedule action, while everyone says that you can schedule action using Process Builder.

There are even ideas in IdeaExchange asking for more details of the schedule jobs from process builder:
Scheduled actions from Process Builder should appear under Time-Based Workflow
Process Builder: Waiting Flow Interviews: Provide Better Information

But, where is the Schedule Action? Is this something need to be enabled by Salesforce support? Or my Salesforce edition does not support Process Builder? Process Builder available from Professional Edition and above, read here Lightning Process Builder.

only immediate action and no scheduled action option

scheduled action available to be configured

What is the causes in the 1st screenshot we don't see scheduled actions option? To have schedule actions, your process has to meet at least 1 of 2 criteria below:
  • Start the process only when a record is created (1). Select this option when you choose an object for your process, or
  • Start the process when a record is created or edited (2). In addition, select the advanced option to execute actions only when specified changes are made (3) when you add criteria to your process.



I have a blog written last year related to "Do you want to execute the actions only when specified changes are made to the record?", so here is the other usage of that checkbox, using ISNEW() and ISCHANGED() will not enabled scheduled action option.


Reference



Friday, January 6, 2017

Salesforce: Workflow Action Failed to Trigger Flow

You build awesome Process Builder or Flow and it works as tested. Few days later, your user start complaining see ugly error as sample below. What is this mean? Is this mean Salesforce buggy, or you have successfully hack it?

Workflow Action Failed to Trigger Flow
The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 30128000000AgZ7. Contact your administrator for help.

Click here to return to the previous page. 


or something like this:

Workflow Action Failed to Trigger Flow
The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 30190000000XmQs. Flow error messages: <b>An unhandled fault has occurred in this flow</b><br>An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help. 

Click here to return to the previous page.

The one below happened when PB try to call Flow and it fail, it may be caused by the Flow is Inactive, while the one earlier is related to update record fail.

Actually, what here mean is, something is broken with Process Builder or Flow built into your org., it can be fail to update record because of validation rules, error in Flow, or etc.

In our blog earlier, we mentioned that prefix 301 is InteractionDefinitionVersion, but we can't really easily see that record content by putting into URL, or by query with SOQL. So, how to trace that 301 error is referring to which Process Builder or Flow?

The user who create the Process Builder will get email from FlowApplication, with subject "Error Occurred During Flow "flow name", this email will mentioned the flow name, but no Version Id information as in the screenshot above. If the user create that Process Builder not in office, how you can trace Version Id prefix 301 is related to what?

There are 2 options to find this:

1. Flow
Use Flow Designer to check if that Id is refer to which Process Builder or Flow -- remember that Process Builder is using Flow as it engine. Follow this Url https://na3.salesforce.com/designer/designer.apexp#Id=30190000000XmQs, change na3 to your salesforce instance and you should see the Flow Name which is Lead Share for this sample.



2. Workbench
Login to workbench, navigate to menu Info | Metadata Types & Components, select Flow from drop down and click Expand All. You should find that 301 Version Id from the components and get the Flow name, which is "Lead Share"



This is the Process Builder as result of our finding:




ReferenceValidation Rule in Workflow and Process Builder



Monday, September 26, 2016

Salesforce: Process Builder, Flow and Workflow running in System Mode

System mode: process running is NOT DEPEND on the current user permissions to the object access, field level security, sharing rule. In which the level permissions of the current user are ignored.

User mode: process running is DEPEND on the current user permission to the object access, field level security, sharing rule. In which the level permissions of the current user are enforced.

Automation in Salesforce will run in System mode, in the declarative mode this is include: Workflow, Process Builder, Process Builder + Flow. The same applicable for apex trigger as well.

While Flow will run in User mode, this is make sense as Flow is not count as automation, Flow have user interface that need user to fill something or click button.

Thanks to Mayank Srivastava for sharing matrix below this in Success Community.


The matrix is tested as of Summer '16 release, so this may change in the future. 

When Flow hit error if user do not have access to the field, an error email will be sent to the Flow creator:
Subject: Error Occurred During Flow "Flow_Name": INSERT --- INSERT FAILED --- ERRORS : (INVALID_FIELD_FOR_INSERT_UPD...

Body: An error occurred at element Element_Name (FlowRecordCreate).
INSERT --- INSERT FAILED --- ERRORS : (INVALID_FIELD_FOR_INSERT_UPDATE) Unable to create/update fields: Field_Name__c. Please check the security settings of this field and verify that it is read/write for your profile or permission set., 


Reference:

Sunday, August 14, 2016

Salesforce: Validation Rule in Workflow and Process Builder

Based on Salesforce Triggers and Order of Execution "If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules, duplicate rules, and escalation rules are not run again."

This mean, when a user hit save button, all Validation Rules will fired, if nothing fit into custom validation rules defined, workflow will kick-in and if there is any field update, validation rules will not fired again.



Rule: Account Number should be not blank, but workflow able to set Account Number to blank.

Scenario: Initially Account Number is not blank, user edit the Account, and Workflow rule will fired with Field Update action to set Account Number to blank.

Let's debug this workflow:
37.0 APEX_CODE,DEBUG;APEX_PROFILING,DEBUG;CALLOUT,DEBUG;DB,DEBUG;SYSTEM,DEBUG;VALIDATION,DEBUG;VISUALFORCE,DEBUG;WORKFLOW,DEBUG
14:23:35.0 (82155)|USER_INFO|[EXTERNAL]|00528000002ILq8|abc@playground.com|Singapore Time|GMT+08:00
14:23:35.0 (114745)|EXECUTION_STARTED
14:23:35.0 (120056)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Account:0012800000gyUy6
14:23:35.0 (130074)|VALIDATION_RULE|03d28000000EPIz|Validation_Rule_Check_Account_Number
14:23:35.0 (228425)|VALIDATION_FORMULA|ISBLANK( AccountNumber )|AccountNumber=4
14:23:35.0 (237103)|VALIDATION_PASS
14:23:35.0 (269418)|CODE_UNIT_FINISHED|Validation:Account:0012800000gyUy6
14:23:35.0 (274425)|EXECUTION_FINISHED
14:23:35.30 (30037797)|USER_INFO|[EXTERNAL]|00528000002ILq8|abc@playground.com|Singapore Time|GMT+08:00
14:23:35.30 (30056259)|EXECUTION_STARTED
14:23:35.30 (30061600)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Account
14:23:35.30 (50813798)|WF_RULE_EVAL_BEGIN|Workflow
14:23:35.30 (50860348)|WF_CRITERIA_BEGIN|[Account: Ke 4 0012800000gyUy6]|Account Name not blank|01Q28000000Cc09|ON_ALL_CHANGES|0
14:23:35.30 (54819564)|WF_RULE_FILTER|[Account : Account Name not equal to ]
14:23:35.30 (54838482)|WF_RULE_EVAL_VALUE|Ke 4
14:23:35.30 (54843398)|WF_CRITERIA_END|true
14:23:35.30 (73750806)|WF_SPOOL_ACTION_BEGIN|Workflow
14:23:35.30 (73896415)|WF_FIELD_UPDATE|[Account: Ke 4 0012800000gyUy6]|Field:Account: Account Number|Value:null|Id=04Y280000002Bz8|CurrentRule:Account Name not blank (Id=01Q28000000Cc09)
14:23:35.30 (73918213)|WF_ACTION| Field Update: 1;
14:23:35.30 (73920533)|WF_RULE_EVAL_END
14:23:35.30 (88370151)|WF_ACTIONS_END| Field Update: 1;
14:23:35.30 (88385818)|CODE_UNIT_FINISHED|Workflow:Account
14:23:35.30 (88392301)|EXECUTION_FINISHED

legend:
  • Red highlight 03d28000000EPIz = Validation Rule Id
  • Orange highlight 01Q28000000Cc09 = Workflow Rule Id
  • Cyan highlight 04Y280000002Bz8 = Field Update action Id
After workflow action end, execution finished.


Let's convert above Workflow rule to Process Builder with Update Records action, it should be pretty straight forward, let see the result when we edit and save the Account from Salesforce UI:

Workflow Action Failed to Trigger Flow
The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 30128000000AgZ7. Contact your administrator for help.

Click here to return to the previous page. 

Note: 301 prefix ID above is refer to an object call "InteractionDefinitionVersion", but you cannot easily know this Id is refer to which Process Builder. 

Instead of getting the same result, we will see above error message. But, only admin who create the Process Builder / Flow will receive fault email with more detail information, such as:

An error occurred at element myRule_1_A1 (FlowRecordUpdate).
UPDATE --- UPDATE FAILED --- ERRORS : (FIELD_CUSTOM_VALIDATION_EXCEPTION) Validation Rule Account_Number is blank
________________________________________
This report lists the elements that the flow interview executed. The report is a beta feature.
We welcome your feedback on IdeaExchange.
Flow Details
Flow Name: Account_Name_not_blank
Type: Workflow
Version: 1
Status: Active
Flow Interview Details
Interview Label: Account_Name_not_blank-1_Account
Current User: ABC Playground (00528000002ILq8)
Start time: 8/14/2016 2:34 PM
Duration: 0 seconds
How the Interview Started
Admin Playground (00528000002ILq8) started the flow interview.
Some of this flow's variables were set when the interview started.
myVariable_old = 0012800000gyUy6AAE
myVariable_current = 0012800000gyUy6AAE
ASSIGNMENT: myVariable_waitStartTimeAssignment
{!myVariable_waitStartTimeVariable} Equals {!Flow.CurrentDateTime}
Result
{!myVariable_waitStartTimeVariable} = "8/14/2016 2:34 PM"
DECISION: myDecision
Executed this outcome: myRule_1
Outcome conditions: and
1. {!myVariable_current.Name} (Ke 4) Does not equal null
Logic: All conditions must be true (AND)
RECORD UPDATE: myRule_1_A1
Find all Account records where:
Id Equals {!myVariable_current.Id} (0012800000gyUy6AAE)
Update the records’ field values.
AccountNumber = 
Result
Failed to update records that meet the filter criteria.
________________________________________
Error Occurred: UPDATE --- UPDATE FAILED --- ERRORS : (FIELD_CUSTOM_VALIDATION_EXCEPTION) Validation Rule Account_Number is blank 

legend:
- Red text = Process Builder API Name
- Blue text = Validation Rule error message

Prefix 301 can be referred to a Process Builder or Flow. The workaround is to use Flow Designer to check if that Id is refer to which Process Builder or Flow -- remember that Process Builder is using Flow as it engine. Follow this Url https://na3.salesforce.com/designer/designer.apexp#Id=30128000000AgZ7, change na3 to your salesforce instance.

In my sample, I see Flow Designer below, it show the Process Builder is Account Name not blank.



Let's analyze this Process Builder debug log:

37.0 APEX_CODE,DEBUG;APEX_PROFILING,DEBUG;CALLOUT,DEBUG;DB,DEBUG;SYSTEM,DEBUG;VALIDATION,DEBUG;VISUALFORCE,DEBUG;WORKFLOW,DEBUG
14:34:47.0 (558162)|USER_INFO|[EXTERNAL]|00528000002ILq8|abc@playground.com|Singapore Time|GMT+08:00
14:34:47.0 (592212)|EXECUTION_STARTED
14:34:47.0 (598100)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Account:0012800000gyUy6
14:34:47.0 (606907)|VALIDATION_RULE|03d28000000EPIz|Validation_Rule_Check_Account_Number
14:34:47.0 (776191)|VALIDATION_FORMULA|ISBLANK( AccountNumber )|AccountNumber=4
14:34:47.0 (781498)|VALIDATION_PASS
14:34:47.0 (804187)|CODE_UNIT_FINISHED|Validation:Account:0012800000gyUy6
14:34:47.0 (809205)|EXECUTION_FINISHED
14:34:47.59 (59552281)|USER_INFO|[EXTERNAL]|00528000002ILq8|abc@playground.com|Singapore Time|GMT+08:00
14:34:47.59 (59569571)|EXECUTION_STARTED
14:34:47.59 (59575357)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Account
14:34:47.59 (82062195)|WF_RULE_EVAL_BEGIN|Workflow
14:34:47.59 (82101694)|WF_CRITERIA_BEGIN|[Account: Ke 4 0012800000gyUy6]|Account_Name_not_blank30128000000AgZ7|01Q28000000Cc0E|ON_ALL_CHANGES|0
14:34:47.59 (82345496)|WF_FORMULA|Formula:ENCODED:[treatNullAsNull]true|Values:
14:34:47.59 (82352535)|WF_CRITERIA_END|true
14:34:47.59 (97686928)|WF_SPOOL_ACTION_BEGIN|Workflow
14:34:47.59 (97718850)|WF_ACTION| Flow Trigger: 1;
14:34:47.59 (97721792)|WF_RULE_EVAL_END
14:34:47.59 (103758514)|WF_FLOW_ACTION_BEGIN|09L28000000Dx9D
14:34:47.105 (105390847)|USER_INFO|[EXTERNAL]|00528000002ILq8|abc@playground.com|Singapore Time|GMT+08:00
14:34:47.105 (105416019)|FLOW_CREATE_INTERVIEW_BEGIN|00D28000001GqzS|30028000000DADN|30128000000AgZ7
14:34:47.105 (328513776)|FLOW_CREATE_INTERVIEW_END|2218d9911a59768798c816adb579156879d9ea4-3fe3|Account Name not blank
14:34:47.328 (328991140)|USER_INFO|[EXTERNAL]|00528000002ILq8|abc@playground.com|Singapore Time|GMT+08:00
14:34:47.328 (329016464)|FLOW_START_INTERVIEWS_BEGIN|1
14:34:47.328 (356679048)|FLOW_START_INTERVIEW_BEGIN|2218d9911a59768798c816adb579156879d9ea4-3fe3|Account Name not blank
14:34:47.328 (357910736)|FLOW_START_INTERVIEW_END|2218d9911a59768798c816adb579156879d9ea4-3fe3|Account Name not blank
14:34:47.632 (632463208)|USER_INFO|[EXTERNAL]|00528000002ILq8|abc@playground.com|Singapore Time|GMT+08:00
14:34:47.632 (632488241)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Account:0012800000gyUy6
14:34:47.632 (632503881)|VALIDATION_RULE|03d28000000EPIz|Validation_Rule_Check_Account_Number
14:34:47.632 (632613125)|VALIDATION_FORMULA|ISBLANK( AccountNumber )|AccountNumber=null
14:34:47.632 (632625147)|VALIDATION_FAIL
14:34:47.632 (632678806)|CODE_UNIT_FINISHED|Validation:Account:0012800000gyUy6
14:34:47.328 (634577332)|FLOW_ELEMENT_ERROR|UPDATE --- UPDATE FAILED ---  ERRORS :  (FIELD_CUSTOM_VALIDATION_EXCEPTION) Validation Rule Account_Number is blank, |FlowRecordUpdate|myRule_1_A1
14:34:47.328 (663434606)|FLOW_START_INTERVIEWS_END|1
14:34:47.59 (663505014)|WF_FLOW_ACTION_ERROR|09L28000000Dx9D|30028000000DADN|Error executing flow: Account_Name_not_blank, FlowDefId: 30028000000DADN, FlowVersionId: 30128000000AgZ7
14:34:47.59 (663520003)|WF_FLOW_ACTION_ERROR_DETAIL|<b>An unhandled fault has occurred in this flow</b><br>An unhandled fault has occurred while processing the flow.  Please contact your system administrator for more information.
14:34:47.59 (663596389)|WF_FLOW_ACTION_END|09L28000000Dx9D
14:34:47.59 (663613069)|CODE_UNIT_FINISHED|Workflow:Account
14:34:47.59 (665545797)|EXECUTION_FINISHED

legend:
  • Red highlight 03d28000000EPIz = Validation Rule Id, this is the same validation rule
  • Green highlight 30128000000AgZ7= Interaction Definition Version Id, this is the Id show in error message (cannot open directly)
  • Orange highlight 01Q28000000Cc0E = workflow Id, (cannot open directly, because this is Flow)
  • Blue highlight 09L28000000Dx9D = Action Flow Id  (cannot open directly)
  • Yellow highlight 30028000000DADN = Flow Definition Id (cannot open directly)

If we analyze the log above, within Flow Action, it will call Validation Rule and this will stop Process Builder to update record.

Let's compare to a successful Process Builder with Record Update and Validation Rule.
37.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
15:24:54.0 (95867)|USER_INFO|[EXTERNAL]|00528000002ILq8|abc@playground.com|Singapore Time|GMT+08:00
15:24:54.0 (129750)|EXECUTION_STARTED
15:24:54.0 (135441)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Account:0012800000gyUy6
15:24:54.0 (146785)|VALIDATION_RULE|03d28000000EPIz|Validation_Rule_Check_Account_Number
15:24:54.0 (309565)|VALIDATION_FORMULA|ISBLANK( Name )|Name=Ke 4
15:24:54.0 (314519)|VALIDATION_PASS
15:24:54.0 (334878)|CODE_UNIT_FINISHED|Validation:Account:0012800000gyUy6
15:24:54.0 (339757)|EXECUTION_FINISHED
15:24:54.30 (30239766)|USER_INFO|[EXTERNAL]|00528000002ILq8|abc@playground.com|Singapore Time|GMT+08:00
15:24:54.30 (30253350)|EXECUTION_STARTED
15:24:54.30 (30258265)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Account
15:24:54.30 (42750062)|WF_RULE_EVAL_BEGIN|Workflow
15:24:54.30 (42795063)|WF_CRITERIA_BEGIN|[Account: Ke 4 0012800000gyUy6]|Account_Name_not_blank30128000000AgZ7|01Q28000000Cc0E|ON_ALL_CHANGES|0
15:24:54.30 (43029449)|WF_FORMULA|Formula:ENCODED:[treatNullAsNull]true|Values:
15:24:54.30 (43036888)|WF_CRITERIA_END|true
15:24:54.30 (44033222)|WF_SPOOL_ACTION_BEGIN|Workflow
15:24:54.30 (44056720)|WF_ACTION| Flow Trigger: 1;
15:24:54.30 (44058614)|WF_RULE_EVAL_END
15:24:54.30 (44682997)|WF_FLOW_ACTION_BEGIN|09L28000000Dx9D
15:24:54.46 (46193540)|USER_INFO|[EXTERNAL]|00528000002ILq8|abc@playground.com|Singapore Time|GMT+08:00
15:24:54.46 (46218553)|FLOW_CREATE_INTERVIEW_BEGIN|00D28000001GqzS|30028000000DADN|30128000000AgZ7
15:24:54.46 (47747434)|FLOW_CREATE_INTERVIEW_END|1940b7d42414e1d9dcfb404801f715687e6cde0-3f6f|Account Name not blank
15:24:54.48 (48073487)|USER_INFO|[EXTERNAL]|00528000002ILq8|abc@playground.com|Singapore Time|GMT+08:00
15:24:54.48 (48088578)|FLOW_START_INTERVIEWS_BEGIN|1
15:24:54.48 (48766530)|FLOW_START_INTERVIEW_BEGIN|1940b7d42414e1d9dcfb404801f715687e6cde0-3f6f|Account Name not blank
15:24:54.48 (49602259)|FLOW_START_INTERVIEW_END|1940b7d42414e1d9dcfb404801f715687e6cde0-3f6f|Account Name not blank
15:24:54.91 (91366282)|USER_INFO|[EXTERNAL]|00528000002ILq8|abc@playground.com|Singapore Time|GMT+08:00
15:24:54.91 (91385208)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Account:0012800000gyUy6
15:24:54.91 (91397228)|VALIDATION_RULE|03d28000000EPIz|Validation_Rule_Check_Account_Number
15:24:54.91 (91481561)|VALIDATION_FORMULA|ISBLANK( Name )|Name=Ke 4
15:24:54.91 (91487538)|VALIDATION_PASS
15:24:54.91 (91509480)|CODE_UNIT_FINISHED|Validation:Account:0012800000gyUy6
15:24:54.48 (109154474)|FLOW_START_INTERVIEWS_END|1
15:24:54.30 (110713941)|WF_FLOW_ACTION_END|09L28000000Dx9D
15:24:54.30 (110757222)|WF_RULE_EVAL_BEGIN|Workflow
15:24:54.30 (110768818)|WF_SPOOL_ACTION_BEGIN|Workflow
15:24:54.30 (110774246)|WF_ACTION| None
15:24:54.30 (110776310)|WF_RULE_EVAL_END
15:24:54.30 (110844992)|WF_ACTIONS_END| Flow Trigger: 1;
15:24:54.30 (110852765)|CODE_UNIT_FINISHED|Workflow:Account
15:24:54.30 (112112867)|EXECUTION_FINISHED




Reference:

Tuesday, August 9, 2016

Salesforce: Auto Enable Marketing User

Use Case: some user need to be auto enable with Marketing User in the user detail because they need to add Contact / Lead to Campaign, see this blog for detail.

Solution:
1. Create Auto-launched Flow
2. Create Process Builder

Auto-launched Flow
We need this flow called by Process Builder because field UserPermissionsMarketingUser in User object is not accessible from Process Builder, you need to have a Record Update process with a variable use as input of User Id.

Vote for this idea to allow Process Builder able to access all fields in the object.


Process Builder
With Process Builder on User creation, call above Flow and pass the User Id to that flow.



With simple Process Builder + Auto-launched Flow above, new user created will be have Marketing User auto check, you can add criteria in Process Builder if need to evaluate certain Profile or Role or etc.

Note: deactivate and re-activate user will not effect Marketing User checkbox, so it is not necessary to run the Process Builder on user update.



Tuesday, April 26, 2016

Salesforce: Store Approval Comments to Notes

Use Case: we need to capture Comments type by approver when approve or reject in Approval process as Notes.

Assume that you already have the following:
- Status picklist field: Draft, In Progress, Rejected, Approved
- Approval Process with actions to update status to Rejected or Approved

Solutions:
1. Process Builder 
Process to trigger when the status change to Approved or Rejected

a. Select the object and make sure to select "when a record is created or edited"
b. Criteria: make sure both values captured with OR logic

c. Action: call Flow with passing Record Id as flow variable


2. Autolaunched Flow
Flow designer:

a. Lookup to Process Instance object, filter to Record Id and Approval Process Id, you need to store Approval Process Id into a constant.
Store the result (Id and Status) to a sobject variables, as this will always return only 1 record, we can use Sobject Variables.

b. Lookup to Process Instance Step object, filter to Process Instance Id, Step Status equal to Rejected and Approved. Store the result (Comments, StepStatus, and ActorId) to a sobject Collecton variables, this lookup may return more than 1 record, so we should use Sobject Collection Variables.

c. Loop the Process Instance Step object
Copy each record from Sobject Collection Variables to Sobject Variables.

d. Assign Sobject Variables
Populated fields to a new Sobject Variables.

formulaBody is a formula resource = {!lvProcessInstanceSteps.ActorId} & " | " &
 TEXT({!lvProcessInstanceSteps.StepStatus}) & " | " &
{!lvProcessInstanceSteps.Comments}
Approval Comment is just a text for note title.

e. Assign Sobject Collection Variables
Add Sobject Variables to new Sobject Collection Variables

f. Create Notes


So, when it is approved / rejected, a note will be automatically created.


Here is the notes content:


With slight adjustment in the Flow, you can change the flow to store approval history into a custom object.



Monday, April 25, 2016

Salesforce: Retrieving Metadata with Developer Workbench

Use Case: as time goes by, we have more and more Process Builder calling Auto Launched Flow, we found an Auto Launched Flow and not sure is called by Process Builder.

Solution:
Use Force.com IDE or MavensMate to download the metadata file, but if your machine is not installed with any IDE, you can use Developer Workbench to download the metadata XML file -- huge thanks to Doug Ayers for the tips.

1. Prepare the Package 

A. Using Package XML file
Save the file as package.xml or any other name
 <?xml version="1.0" encoding="UTF-8"?>  
 <Package xmlns="http://soap.sforce.com/2006/04/metadata">  
   <types>  
     <members>*</members>  
     <name>Flow</name>  
   </types>  
   <types>  
     <members>*</members>  
     <name>FlowDefinition</name>  
   </types>  
   <version>36.0</version>  
 </Package>  
** to get the name tag, you can use this free tool Package Builder

B. Create Package
Instead of creating XML file as above, the other option is by creating Package from Salesforce menu Setup | Create | Packages, see this blog for complete reference Getting Unstuck.


2. Developer Workbench
- Click Migration | Retrieve
- Select the XML file created for "Unpackaged Manifest"
- or enter the Package Name, if you use option B - Create Package
- Check "Single Package"

- Click Next button
- Click Retrieve button

- Click "Download ZIP File" link when done


3. Extract and Find
A zip file will be download, you need to extract it and using tool like Notepad++ to find the metadata you need. In my use case as above, I am looking for <actionType>flow</actionType> to find all Flow called by Process Builder.



Reference:

Wednesday, February 24, 2016

Salesforce: Process Builder Criteria

When you configure Workflow in Salesforce, if you need to configure the workflow only trigger upon creation or update on certain field to a value, we use rule criteria formula evaluates to true.

We can use the same way in Process Builder, see sample screenshot below:


However, Process Builder come with more advance (and easier) technique without the need to use ISNEW() and ISCHANGED() formula.

When you are in define criteria, you can simply use Conditions are met and select the fields value condition to trigger the process. But, make sure you click Advanced and select Yes in Do you want to execute the actions only when specified changes are made to the record? Otherwise, this process will keep trigger even there is no such need to trigger it.

When you select yes, the actions are executed only if the record meets the criteria now but the values that the record had immediately before it was saved didn't meet criteria. This means that these actions won't be executed when irrelevant changes are made - this will covered on record creation and record update.




With this simple conditions, it will do the same as you use ISNEW() and ISCHANGED() formula.


Wednesday, January 20, 2016

Salesforce: Auto Add User to Chatter Group with Quick Action

In previous blog, we explain step by step on how to configure Process Builder with Auto-launched Flow to auto add user to a Chatter Group upon user creation or re-activation. It's pretty complex as you need to configure a workflow with Time-Dependent Action, continue with Flow, then Process Builder.

There is another option to auto add user to chatter group (not include using apex Trigger), which is using Process Builder with Quick Action, which is much more simpler compare to using time-dependent action workflow and Flow.

Here is the steps:
1. Create Process Builder
2. Select an object
3. Define the Criteria
4. In Immediate Actions, select Quick Actions
5. Enter Action Name
6. Filter Search By Type | Create a Record | NewGroupMember (once selected it will become CollaborationGroup.NewGroupMember)


7. You need to provide 2 variables for the quick actions:
  • Related Record ID = Chatter Group Id
  • Member Id reference to [User].Id




Thursday, May 7, 2015

Salesforce: Update User Manager

Manager field in User object in Salesforce is pretty special, it can be used as approver when a user submit for approval. But, when user go to their Advanced User Details, from click User Name | My Settings | PersonalAdvanced User Details, when user click Edit button Manager field is read-only.


After finding more on this field, only user with Manage Users and Manage Internal Users permission allowed to update this field. The reason behind, if users could modify this field, the concern is that they might update their manager to a friend who would approve time off request or expense charge.

In our case, for some reason and our Salesforce system is not linked to HR system, so user need to update their manager field manually for a time-period, before it locked.

Solution

1. Custom "Hierarchical Relationship" field + Workflow + Field Update
Fail, this is because Field Update on Manager do not allow to dynamically update the value from other field, only to a defined user.



2. Custom "Hierarchical Relationship" field + Process Builder + Update Records


SuccessHow this works?
1. Create a new Hierarchical Relationship custom field name "Report To" in User object
2. Make this field available in User page layout and not read-only
3. User update their own Manager through this field from Advanced User Details
4. Process Builder will update standard Manager field from "Report To"

Last message, do not forget to activate the Process :)




Sunday, March 8, 2015

Salesforce: Auto Add User to Chatter Group

As of now Spring '15 release, when create a new user in Salesforce, we cannot auto add user to Chatter Groups, except write Apex Trigger code in User object (see Bob Buzzard's blog), or get paid app from AppExchange ChattoMate.

But, with new Visual Flow + Process Builder, this has been made possible without writing code or using paid app.

Use Case: business request to add all Salesforce/Chatter users to a Chatter Group called 'All Users'. There is also an existing process to auto deactivate user if user last login is more than 2 months. By default, deactivate user will be remove user from the Chatter Group. When user request to be re-activate, user should be added back to the Chatter Group. Manual add user to the Group is not ideal as admins prone to forget, we need to look for solution to automate it.

Here is the simple logic to use Visual Flow and Process Builder:

1. Create Process Builder
  • When user created or edited, call Visual Flow below
2. Create Visual Flow
  • Check is user has been member of the Chatter Group
  • If not found, add user to the Chatter Group
But, issue arise as Salesforce do not allow to have Setup change and a Data change at the same. In that case, creating a user is Setup changed, and adding user to Chatter Group Member is Data changed. This causes the Mixed DML error. here is the full error message:
UPSERT FAILED ---  ERRORS : (MIXED_DML_OPERATION) DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): CollaborationGroupMember, original object: User ---

Workaround: change the transaction of adding user to Chatter group as future change. To make it simple, we'll create a new custom Checkbox field in User object to flag that particular user need to be added to Chatter Group.

Here is the updated logic:

1. Create a Workflow with Time-Dependent Action 
  • When user created or edited, and the checkbox is false, perform "future" Field Update action to update the custom field to true
2. Create Process Builder
  • When the flag is true, call Visual Flow below
3. Create Visual Flow
  • Lookup if user is member of the Chatter Group
  • If not found, add user to the Chatter Group

Create Visual Flow
1. Navigate to Setup | Create | Workflow & Approvals | Flows

2. Click New Flow button

3. Drag Record Lookup element onto the canvas


4. Enter Record Lookup Name = Check User Exist in Chatter Group

5. Select CollaborationGroupMember as look up object
    - CollaborationGroupId = the Chatter Group Id
    - MemberId = create new Variable, name it UserId 

6. Assign the Id to by create a new variable


7. Name the variable as GroupMemberId


8. This is what we have for Lookup 


9. Click OK button to continue

10. Drag Decision element onto the canvas

11. Enter Decision Name = Lookup Result

12. Enter outcome name = Not Found with condition as below:

13. Click OK button to continue

14. Connect Record Lookup element with Decision element


15. Drag Record Create element onto the canvas

16. Enter Decision Name = Create Membership

17. Select object = CollaborationGroupMember
     - CollaborationGroupId = the Chatter Group Id
     - CollaborationRole = select PICKLIST VALUES Standard
   [Admin or Standard]
     - MemberId = select variable UserId
     - NotificationFrequency = select PICKLIST VALUES D
       [D = Daily Digest; P = Each Post; W = Weekly Digest; N = Never]
   

18. Just leave record Id created, as we do not need it. Click OK button to continue

19. Connect Decision element with Record Create element

20. It will prompt you for Decision Routing, select Not Found (this is outcome name we set in step 12 above)

21. Hover mouse over Record Lookup and click the green arrow icon to set it as Start element.

22. This is the complete Flow

23. Click Save button, enter name = Add User to Chatter Group; select type = Autolaunched Flow, click OK to continue

24. Click Close button to back to list of Flows, then click Activate link, otherwise the flow will not visible in Process Builder.


Create Workflow with Time-Dependent Action 
1. Add a custom object Checkbox in User object = Add to Chatter group, with Default Value = unchecked.

2. Create a workflow rule as below:


3. Create Field Update action to update custom object Checkbox "Add to Chatter group" to true. It is important to select "Re-evaluate Workflow Rules after Field Change", otherwise later on field update here will not trigger Process Builder when this flag set to true.


4. Back to the workflow and add Time Trigger action, set it to 0 hours after Rule trigger date. Usually the trigger will kick-in within 15 minutes as it will be put the actions to queue, you can monitor from Setup | Time-Based Workflow, click Search button.

5. Add created field update action (step 3) as Time-Dependent Workflow Actions in this workflow.

6. Activate the workflow.


Create Process Builder 
1. Navigate to Setup | Create | Workflow & Approvals | Process Builder 

2. Click new Button to create new Process Builder

3. Enter name = Auto Add User to Chatter Group All

4. Select Object = User, and select Start the process = when a record is created or edited .Click Save button to continue.

5. Add Criteria, see following setting and click Save to continue


6. In Immediate Actions, call Flow created earlier


7. Click Activate button to activate the Process



Page-level ad