Tuesday, 27 June 2023

Due Date calculation formula for excluding weekends in flow

 Hi ,

The following formula field calculates the Due Date provided the Today() date and numberOfDays to be added to the Today() date excluding Saturdays and Sundays in the flow.

CASE(

MOD(TODAY()  - DATE(1900, 1, 7), 7),

0, (TODAY() ) + numberOfDays + FLOOR((numberOfDays-1)/5)*2,

1, (TODAY() ) + numberOfDays + FLOOR((numberOfDays)/5)*2,

2, (TODAY() ) + numberOfDays + FLOOR((numberOfDays+1)/5)*2,

3, (TODAY() ) + numberOfDays + FLOOR((numberOfDays+2)/5)*2,

4, (TODAY() ) + numberOfDays + FLOOR((numberOfDays+3)/5)*2,

5, (TODAY() ) + numberOfDays + CEILING((numberOfDays)/5)*2,

6, (TODAY() ) - IF(numberOfDays>0,1,0) + numberOfDays + CEILING((numberOfDays)/5)*2,

null)


Here numberOfDays is flow variable.


Example Scenario:

When an Account is created, a task should be created with a due date set to 5 days from today.

Reference:

https://help.salesforce.com/s/articleView?id=sf.formula_examples_dates.htm&type=5

Monday, 26 June 2023

Invoking(Launching) a Flow from Apex

 Hi,

We can launch a flow from Apex in the following ways


Invoking the flow from Apex Statically:

Without Namespace:

  Map<String, Object> inputs = new Map<String, Object>();

  inputs.put('AccountID','001XXXXXXX');

  inputs.put('OpportunityID','006XXXXXXX');

  Flow.Interview.Calculate_discounts myFlow = 

  new Flow.Interview.Calculate_discounts(inputs);

  myFlow.start();


With Namespace:

  Map<String, Object> inputs = new Map<String, Object>();

  inputs.put('AccountID','001XXXXXXX');

  inputs.put('OpportunityID','006XXXXXXX');

  Flow.Interview.myNamespace.Calculate_discounts myFlow = 

  new Flow.Interview. sftech.Calculate_discounts(inputs);

  myFlow.start();

Invoking the flow from Apex Dynamically:

Without Namespace:

Map<String, Object> inputs = new Map<String, Object>();

  inputs.put('AccountID','001XXXXXXX');

  inputs.put('OpportunityID','006XXXXXXX');

Flow.Interview myFlow = Flow.Interview.createInterview('Calculate_discounts', inputs);

myFlow.start();

With Namespace:

  Map<String, Object> inputs = new Map<String, Object>();

  inputs.put('AccountID','001XXXXXXX');

  inputs.put('OpportunityID','006XXXXXXX');

  Flow.Interview myFlow = Flow.Interview.createInterview('sftech', 'Calculate_discounts', inputs);

  myFlow.start();

Here Calculate_discounts  is the name of the flow.

AccountID and OpportunityID are input variables of the flow.

sftech is the namespace

How to get variable values from flow to Apex?

system.debug('My Output Variable: ' + myFlow.getVariableValue('varName'));


Note: We can invoke flow from Apex if the flow type is "Autolaunched Flow (No Trigger)" only







Reference:

https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/flow_interview_class.htm#apex_Flow_Interview_methods






Monday, 19 June 2023

Manage Apex Access for Package Version Creation Tests

 Sometimes the Apex tests that you write require a user to have certain permission sets or permission set licenses. Use the apexTestAccess setting to assign permission sets and permission set licenses to the user in whose context your Apex tests get run at package version creation.

Its very important step to include "apexTestAccess" if we are not using System.runas() in test methods for generating 2GP packages.



"packageDirectories": [

    {

        "path": "force-app",

        "package": "TestPackage", 

        "versionName": "ver 0.1",

        "versionNumber": "0.1.0.NEXT",

        "default": true, 

        "unpackagedMetadata": {

            "path": "my-unpackaged-directory"

        },

        "apexTestAccess": {

               "permissionSets": [

                   "Permission_Set_1",

                   "Permission_Set_2"

               ],

               "permissionSetLicenses": [

                   "SalesConsoleUser"

               ]

           }


    }, 

]

Reference:

https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_unlocked_pkg_unpackaged_md.htm

What’s the difference between Einstein Article Recommendations and Suggested Articles?

How Does Einstein Article Recommendations Work? Einstein Article Recommendations helps support agents resolve customer cases efficiently by ...