Thursday 30 December 2021

Manipulation on Comma Separated values using Salesforce flow

SCENARIO

While working on one of the requirements for a manufacturing solutions customer based out Atlanta, Georgia there was need to automate User Onboarding Process based on the profile they are assigned to. When a user is added through the data loader, need to add that user to a public group (10 possible groups) automatically. Client wants the new user to be assigned to certain public groups based on the profile the new user has.

APPROCAH

We can think of many solutions to achieve the requirement, for example - Trigger, Apex Class etc., but we've decided to go with less coding approach either through Salesforce flow or Process builder to achieve the requirement.

We'd faced bulkification issue in Process builder earlier, we choose to go with salesforce flow to meet this requirement.

CHALLENGE

Based on the approach taken, we lead to a situation for having multiple groups assignment for user and comma separated public group Ids.

We have used custom metadata for required configuration.

We were able to get list of IDs (Collection of Ids) which are stored in a text field of custom metadata. We can use the same in our Salesforce Flow further execution.

Example:- 
Input String :- 00G2x000000X1GPEA0, 00G2x000000X1GUEA0, 00G2x000000X1GZEA0
Output String Collection:-  00G2x000000X1GPEA0
                                    00G2x000000X1GUEA0
                                    00G2x000000X1GZEA0
                                    
In the above example, comma-separated input string is 00G2x000000X1GPEA0, 00G2x000000X1GUEA0, 00G2x000000X1GZEA0 and output is an Array List - string collection. 

Below are the steps to get a List of Ids from a comma-separated string of Ids.

Step 1:-  Define flow properties.
  • Click Setup.
  • In the Quick Find box, type Flows.
  • Select Flows then click on the New Flow.
  • Select the Autolaunched Flow (No Trigger) option and click on Next and configure the flow as follows:
    • How do you want to start building: Freeform

Step 2:- Flow variables and formulas.
In this step, we will define variables and formulas.

Define InputString Text variable to store entered string.
  • Under Toolbox, select Manager, click on New Resource.
  • Input following information,
    • Resource Type - Variable
    • API Name - InputString
    • Data Type - Text
    • Allow multiple values (collection) - Uncheck 
  • Click Done.
InputString variable
Define StringCollection Text variable to store separated string.
  • Under Toolbox, select Manager, click on New Resource.
  • Input following information,
    • Resource Type - Variable
    • API Name - StringCollection
    • Data Type - Text
    • Allow multiple values (collection) - check 
  • Click Done.

StringCollection variable

Define GetFirstElementFromString  Formula to Get the first element from InputString.
  • Under Toolbox, select Manager, click on New Resource.
  • Input following information,
    • Resource Type - Formula
    • API Name - GetFirstElementFromString  
    • Data Type - Text
    • Formula -
TRIM(LEFT({!InputString}, FIND(",",{!InputString} )-1))
  • Click Done.

GetFirstElementFromString Formula
Define RemoveElementFromString formula to remove element from InputString.
  • Under Toolbox, select Manager, click on New Resource.
  • Input following information,
    • Resource Type - Formula
    • API Name - RemoveElementFromString   
    • Data Type - Text
    • Formula - 
TRIM(RIGHT({!InputString}, LEN({!InputString}) - FIND(",", {!InputString})))
  • Click Done.
RemoveElementFromString Formula

Step 3:-  Create Screen Element
In this step, we will create screen element to get the InputString.
  • Under Toolbox, select Elements. Drag and drop Screen onto the canvas.
  • Fill following Information on Screen Properties.
    • Enter Label the API Name will auto-populate.
    • Under Components, select Input, Drag and drop Long Text Area onto the screen. fill the following details on Long Text Area.
      • Label - Enter String
      • API Name - Enter_String
  • Click Done.
  • Connect Start to Screen Element.

Screen Element

Step 4:- Create Assignment Element.
In this step, we will assign Entered string to InputString.
  • Under Toolbox, select Elements. Drag and drop Assignment onto the canvas.
  • Fill as below,
    • Enter Label and API Name will auto-populate.
    • Set variable values as follow.
      • Variable - InputString
      • Operator - Equals
      • Value - Enter_String
    • Click Done.
  • Connect screen element to assignment element.          

Assign Enter string to Input String

Step 5:- Create Decision Element
In this step, we will check InputString is null or InputString has one string or InputString has multiple strings separated by a comma.
  • Under Toolbox, select Elements. Drag and drop Decision onto the canvas.
  • OutComes
    • No (If InputString contains multiple strings)
      • Enter Label as No Outcome API Name will auto-populate.
      • Condition Requirements to Execute Outcome - All Conditions Are Met (AND)
      • Row 1 
        • Resource - InputString
        • Operator - Does Not Equal
        • Value - Empty String (Not Null)
      • Row 2
        • Resource - InputString
        • Operator - Contains
        • Value - ,
    • Yes (If inputString is null/empty)
      • Enter Label as Yes Outcome API Name will auto-populate.
      • Condition Requirements to Execute Outcome - All Conditions Are Met (AND)
      • Row 1 
        • Resource - InputString
        • Operator - Equals
        • Value - Empty String (Not Null)
    • Single Value (If InputString has a single string)
      • Enter Label as Single Value Outcome API Name will auto-populate.
      • Condition Requirements to Execute Outcome - Custom Condition Logic Is Met
      • Condition Logic - 1 AND NOT 2 
      • Row 1 
        • Resource - InputString
        • Operator - Does Not Equal
        • Value - Empty String (Not Null)
      • Row 2
        • Resource - InputString
        • Operator - Contains
        • Value - ,
  • Click Done.
  • Connect assignment element to decision element. 
Decision element No as outcome

Decision element Yes as outcome

Decision element Single Value as outcome

Step 6:- Create Assignment Element
In this step, we will add InputString in StrinCollection and assign InputString as empty for Single Value outcome of the decision.
  • Under Toolbox, select Elements. Drag and drop Assignment onto the canvas.
  • Enter Label and API Name will auto-populate.
  • Set Variable Values as below.
    • Row 1
      • Variable - StringCollection
      • Operator - Add
      • Value - InputString
    • Row 2
      • Variable - InputString
      • Operator - Equals
      • Value - Empty String (Not Null)
  • Click Done.
  • Connect decision element to assignment element for Single Value outcome.
  • Connect back assignment element to decision element.
Assignment Add Single Value To Collection

Step 7:- Create Assignment Element
In this step, we will add the first element from InputString to StringCollection and remove that element to InputString for No outcome of decision.
  • Under Toolbox, select Elements. Drag and drop Assignment onto the canvas.
  • Enter Label and API Name will auto-populate.
  • Set Variable Values as below.
    • Row 1
      • Variable - StringCollection
      • Operator - Add
      • Value - GetFirstElementFromString
    • Row 2
      • Variable - InputString
      • Operator - Equals
      • Value - RemoveElementFromString
  • Click Done.
  • Connect decision element to assignment element for No outcome.
  • Connect back assignment element to decision element.
Assignment Add value to Collection

Step 8:- Create Screen Element
In this step, we will create a screen to see output.
  • Under Toolbox, select Elements. Drag and drop Screen onto the canvas.
  • Fill following Information on Screen Properties.
    • Enter Label the API Name will auto-populate.
    • under Components, select Input, Drag and drop Long Text Area onto the screenfill the following details on Long Text Area.
      • Label - String Collection
      • API Name - String_Collection
      • Default Value - {!StringCollection}
  • Click Done.
  • Connect decision element to screen element for Yes outcome.

Screen Element output StringCollection


Flow:- 
Flow diagram

Flow output:-

If you have any questions you can reach out our Salesforce Consulting team here.

Thursday 2 December 2021

Salesforce : Refreshing A Sandbox

WHAT IS SANDBOX?

Sandbox is the testing environment for your production environment. You can create different types of sandbox environments, or different copies of the same type to fulfill different purposes, such as development, testing, training, or UAT.


The Sandbox environment is isolated from the production environment. So, you can test as per need without affecting the production environment.


Salesforce provides 4 types of sandbox.

 1. Developer Sandbox
 2. Developer Pro Sandbox
 3. Partial Copy Sandbox
 4. Full Sandbox



WHY WE NEED TO REFRESH SANDBOX?
It is important to have accurate data while testing, development and training because its gives us confidence that configuration or code will not break the production environment. So, sandbox environment should be the mirror of the production environment as closely as possible.

The Salesforce Development Lifecycle Guide recommends that we should refresh/update our sandboxes on a regular basis to ensure that they have the most up-to-date setup and data.

WHAT IS SANDBOX REFRESH?

Refreshing a sandbox means updating all sandbox’s metadata from source org. If the sandbox is a clone or contains a template, the refresh process updates the org’s data and its metadata.

SANDBOX REFRESH PROCESS

At the time of refreshing, the salesforce creates a new org that contains all the objects, fields, validation rules, page layouts, record types, users, and so on as source org.

The sandbox based on template, partial copy, and full copies get some/all data from a source. Here, data refers to records.

SANDBOX REFRESH BEST PRACTICE

Refresh process builds all configuration like source org and remove current org configuration. As the current configuration will be lost, we need to make sure to have pre and post action document that we can compile and revert it after refresh if any issue arises.

In the document, you can include the below points. 
  • Scheduled jobs
  • Deliverability
  • Named Credentials
  • Custom Settings
  • Custom Metadata Types 
  • Remote Site Settings
  • Managed package configurations
  • Connected Apps
  • Apex Exception Email
  • Hardcoded values both in Apex and declarative tools
  • User credentials used in the integrations
  • Salesforce apps and their configurations
After the completion of refresh, we can compare and revert it back from the document.

If you have any questions you can reach out our Salesforce Consulting team here.

Thursday 11 November 2021

[Resolved:] File Upload using REST API from Salesforce to SharePoint with special characters in filename.


SCENARIO

While working on one of the requirements for a packaging solutions customer based out Atlanta, Georgia there was a requirement to allow Salesforce users to upload documents from Salesforce entities.


Due to Salesforce storage limitation, uploaded documents are stored into SharePoint.


CHALLENGE

We have achieved functionality of uploading a file from Salesforce to SharePoint by creating custom lightning web component. We have used SharePoint REST APIs for direct upload from Salesforce to SharePoint.

However, we got stuck with the error while uploading a file contains special characters. 


RESOLUTION

We tried various solutions to resolve the issue but no luck. After relentless efforts, we concluded to utilize simple JavaScript function which encodes given file name and upload to SharePoint with the same name through REST APIs. Finally, it does the trick. Below is the sample for the same:


var updatedFileName = encodeURIComponent(this.files.name);
var url1 = 'https://br.sharepoint.com/sites/SFUpload' + "/_api/web/GetFolderByServerRelativePath('/Sites//SFUpload/Document Library')/Files/AddUsingPath(overwrite=true,decodedurl='" + updatedFileName + "')";


CONCLUSION

By encoding the file name, we are successfully able to upload a file with special characters from Salesforce to SharePoint.


If you have any questions you can reach out our Salesforce Consulting team here.

Thursday 21 October 2021

[Resolved:] Salesforce Clone does not copy all the field values

SCENARIO

While working on one of the requirements for a packaging solutions customer based out Atlanta, Georgia there was a requirement to use salesforce standard clone feature and have some sort of customization on cloned records.


Salesforce provides standard feature to clone the records. We have implemented our customization when record is cloned and have a specific field value.


After successful implementation on UAT, we started getting issues from the users regarding custom functionality is not working for cloned records. However, we were not able to replicate the same issue at our end.


RESOLUTION

After further investigation, we were able to figure out that it was occurring only for specific users. So, we have verified the user access on the object and field. Everything in terms of permission and customization was looking good.


Again deep diving in our analysis, we've found out that only users having profile with specific page layout were facing this issue. The values of fields which are not added to page layout are not copied over to newly created clone records.


After adding those fields to the page layout, the functionality worked as expected.


CONCLUSION

In Salesforce when trying to clone records, All fields must be added to the page layout to ensure values of all fields are copied over. Click Link for the reference.


If you have any questions you can reach out our Salesforce Consulting team here.

Thursday 8 July 2021

Salesforce Configuration VS. Salesforce Customization

If a business decides to utilize a Salesforce solution, then they can expect it to meet all business requirements fully. The Salesforce platform is something that can provide business the functionality one might expect because it is configurable as well as customizable. Many businesses believe that Salesforce Configuration and customization are the same. However, these are actually quite different from each other.

The statistics tell us that more than 90% of the businesses during the Salesforce CRM development and customization have to deal with both configuration and customization. And the platform itself is designed to handle these things perfectly.

Difference between Configuration and Customization

When it comes to configuration, you deal with the items already available on the platform; you select whatever you need. However, if you need to perform customization, you have to handle the code to make the solution work as required. If you have to move to customization, it means that the available resources are not enough.

Salesforce Configuration

Salesforce Configuration is configuring your needs to the system without changing much of the basic structure. The configuration is less complicated, due to the availability of all the features and functions in the Salesforce environment. So, there should be fewer issues while implementing your business requirements. For that, you need to clearly understand what the features mean and how to handle them.

Features of Salesforce Configuration:

  • Configuration in Salesforce means offering user-defined values that will empower certain features/modules to start operating.
  • Configuration can allow you to work with the Salesforce Admin panel to alter switches and setups in the programs.
  • Salesforce Configuration helps to implement business requirements using Salesforce OOTB functionality.
  • You can add new Objects and fields, modules, workflows, surveys, and reports by altering settings in the Admin panel.
  • Customers can get what they expect by configuring and acquiring a pre-defined application of Salesforce.
  • It supports some inbuilt features like, Email-to-Case, Web-to-Case, Email-to-Lead, etc.

Salesforce Configuration includes:

  • Adding Objects/Fields
  • Adding tabs/apps
  • Create new profiles
  • Setting Permissions
  • Work with reports and workflows
  • Create email templates
  • Validation rules
  • Create page layouts or record types
  • Integrating Email Client
  • Create apps for AppExchange as well as Add some applications from AppExchange

Salesforce Customization

Customization can be stated as a step ahead of Salesforce configuration. Customization is required for cases where configuration doesn’t serve the purpose. Salesforce Customization relates to the custom development of code for creating tailored features and functionalities. If you have to move to customization, it means that the available resources are not enough, and you have to handle the code to make the solution work as required.

Features of Salesforce customization:

  • It helps in developing features/functions that aren’t available as a part of the Standard Salesforce Solution.
  • It helps to achieve certain actions that aren’t covered in OOTB configuration and requires some custom coding.
  • Customization allows the addition of triggers on the object to perform a few actions.
  • Salesforce Customization can be considered complex and involves giving attention to user adoption.
  • Once the Configuration is done properly, then Customization is used and brings fruitful results.

Salesforce Customization includes:

  • Work with Apex classes or triggers
  • Work with Visualforce and its components
  • Use CSS to change how the pages look
  • Integrate the solution with the third-party solutions
  • Use JavaScript to add additional features and capabilities
  • Create Lightning components
  • Build custom partner portals
  • Optimize the design and functionality

Summary:

Customization and Configuration are the most essential and demanded factors if you want to cover all your business’ needs. So, whatever you choose, make sure you get everything done with the help of a knowledgeable and experienced Salesforce implementation partner.

If you have any questions you can reach out our Salesforce Consulting team here.

Thursday 17 June 2021

Salesforce Custom Metadata Type

In Salesforce Custom Metadata type is similar to creating custom object or custom setting. A custom metadata type's records are metadata, not data, in and of themselves. In contrast to Custom Settings, where only metadata is eligible for migration, Custom Metadata Type and its records can be migrated from one org to another during deployment. Custom Metadata is usually deployable, package-able, customizable, and upgradeable. The key benefit of using Custom Metadata is that it does not count against the SOQL query limit for each APEX transaction.

Custom metadata types can be used for


  • Mappings— Make connections between objects, such as a custom metadata type that allocates cities, states, or provinces to specific countries & regions. 
  • Business rules— Custom functionality can be combined with configuration records. To route payments to the correct destination, use custom information types and Apex code.
  • Master data— Assume your organization utilizes a basic accounting system. Create a special metadata type for custom charges such as customs and VAT rates. Subscriber orgs can refer to the master data if this type is included as part of an extension package. 
  • Whitelists— Keep track of lists like approved contributors and pre-approved vendors. 
  • Secrets— Protected custom metadata types within a package can be used to store information such as API keys. 

Field Manageability


Field manageability is used to manage custom fields when they are created under the Custom Metadata Type. Custom metadata type supports the following custom field types: 
  • Metadata Relationship 
  • Checkbox
  • Date
  • Date and Time 
  • Email
  • Number
  • Percent
  • Phone
  • Picklist
  • Text
  • Text Area 
  • URL

Access Custom Metadata Type Records


There are new ways to access Custom Metadata Types in the Salesforce Spring-21 pre-release orgs and similar to those for Custom Settings. It is no longer necessary to query them using SOQL, and the contribution to the Query Rows limit is reduced. To access information from custom metadata type records faster, use the Apex getAll(), getInstance(recordId), getInstance(qualifiedApiName), and getInstance(developerName) methods. These methods don't use the SOQL engine and return the sObject information from the call directly.

1.Access the Custom Metadata Type records before Spring 21.

2.Access the Custom Metadata Type records after Spring 21.

A. getAll() to get Custom Metadata Type Records.

The following example uses the getAll() method. The custom metadata type named Ticket has a field called TicketType 

B. getInstance() to get specific Custom Metadata Type Record.

What about if you don’t need to get all records and need to access only a single record? In that case, you can use the getInstance() method. 

Advantages of Custom Metadata:

  • It's possible to distribute metadata! There will be no more time-consuming post-deployment configuration, as there will be with custom settings. To create your default custom setting records, you don't need to develop Apex classes.
  • Change sets or the force.com migration tool can also be used to deploy custom metadata records with metadata type definitions (ANT). The records in custom settings are uploaded after the definition of the custom setting is deployed. 
  • ListViews, Page Layouts, and Validation Rules can be created on the Custom Metadata Types.
  • Metadata Relationships are a thing of beauty! Lookups between Custom Metadata objects are possible. You may also perform an Object Definition lookup.
  • With custom metadata types, you can issue unlimited Salesforce Object Query Language (SOQL) queries for each Apex transaction. 
  • Custom metadata type is visible in test class without using “SeeAllData”. 
  • Custom Settings has the same permissions to edit records and configure the system. The “Configure Application” permission allows you to do both. You can edit records with Custom Metadata's "Configure Application," but you'll need "Author Apex" to update the configuration.

Limitations


The following are the limitations of Custom Metadata Type:
  • Custom metadata records cannot exceed the size of 10MB.
  • It does not support formula field data type.
  • It cannot be updated through Apex. The only way to edit custom metadata types is by leveraging metadata API
  • 100 custom metadata types can be created per salesforce org. 
  • We can create only 100 fields per custom metadata type. 
  • Global picklists are not supported. 

Summary


By creating custom metadata, we can create a static set of data and reuse it in our applications, triggers, apex class, test class, Aura components, etc. Click here for more details. 

If you have any questions you can reach out our Salesforce Consulting team here.