Thursday 29 December 2022

How to create a Picklist Mapping in MuleSoft Composer Flow for Salesforce

 Hi,

Using Picklist Mapping, you can map data from one application to the corresponding data needed by another application and then reuse those mappings in different flows in your organization. This enables you to connect two applications that have different values for similar fields and to align the values in those fields across applications. You can then determine how the possible values of an output field (data pill) map to the possible values of an input field.


For example, you can map a data pill from the Country field in a Salesforce record and provide the same values in the Country field of the NetSuite record.



COUNTRY (SALESFORCE)

COUNTRY (NETSUITE)

US

_unitedStates

CA

_canada

DE

_germany

AR

_argentina




When mapping source data fields:

  • The source field must be a data pill with a fixed list of values.
  • The target field must be an enumerated data type field.
  • If any other unmapped value from the source system is found, the default mapping specifies the value in the target system . If you do not specify a default value, the original value from the source field is passed to the target field.
  • The mapping is stored at the organization level and can be reused across flows.
  • The mapping must have a unique name.
  • Mappings are available to everyone in your organization.

To map source data fields to target fields:

  1. From the Composer Flows tab, open a flow and click Edit.
  2. In an action card, in a field that supports Pick from List, select Picklist Mapping from the drop-down menu.
    The Picklist Mapping window appears.
  3. In the Picklist Source section, in the Source field, select the value from the drop-down list that you want to map to the value in the Target field, and then click Next.
  4. In the Global Picklist Selection section, create a new picklist or choose an existing picklist.

Lets take an example to map Account object Billing Country to NetSuite Country. 
You can go through the following screenshots:




































































































































































































































































































































Reference:


Tuesday 16 August 2022

Configure the Running User and Batch Size for Your Platform Event Trigger

 Hi,

Here we are going to learn how to Configure the Running User and Batch Size for Your Platform Event Trigger.

By default, the trigger on Platform Event runs as the Automated Process system user with a batch size of 2,000 event messages. 

By configuring a platform event trigger using PlatformEventSubscriberConfig in Metadata API or Tooling API we can override the running user and batch size of a Platform Event Apex Trigger.

Benefits:

Configuring the user and batch size enables you to bypass some limitations that sometimes arise from using the defaults.

Eg:

Record system and OwnerId fields are populated as the specified user. 

And setting a batch size smaller than 2,000 can help avoid hitting Apex governor limits.

Run the code block as a specified user which is written under Platform Event Trigger.

How to Configure PlatformEventSubscriberConfig?

  • Create a folder called "PlatformEventSubscriberConfigs"
  • Create a file with the suffix .platformEventSubscriberConfig as shown below.

<?xml version="1.0" encoding="UTF-8"?>
<PlatformEventSubscriberConfig xmlns="http://soap.sforce.com/2006/04/metadata">
    <platformEventConsumer>AccountEventTrigger</platformEventConsumer>
    <batchSize>200</batchSize>
    <masterLabel>AccountEventTriggerConfig</masterLabel>
    <user>user@example.com</user>
    <isProtected>false</isProtected>
</PlatformEventSubscriberConfig>

Here 
AccountEventTrigger  is the name of the Platform Event Trigger
200  is batch size (Batch size 1 is not recommended)
AccountEventTriggerConfig is the name of the PlatformEventSubscriberConfig

Create package.xml as shown below.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">   
     <types>
        <members>AccountTriggerEventConfig</members>
        <name>PlatformEventSubscriberConfig</name>        
    </types>
    <version>55.0</version>
</Package>

Once we create both as shown below then create any folder include the following and zip.





Now open Workbench then chooses the Deploy option and then select the zip.





Now click on Deploy then it will be successful.


Reference:
https://help.salesforce.com/s/articleView?id=release-notes.rn_messaging_trigger_config.htm&type=5&release=230

https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_platformeventsubscriberconfig.htm




Tuesday 2 August 2022

How to get the current recordId in LWC quick action?

Hi,

To get the current recordId when we create a quick action with LWC  we have to use the below code snippet.



_recordId;
set recordId(recordId) {
    if (recordId !== this._recordId) {
        this._recordId = recordId;


Note:
LWC quick actions don’t pass in recordId in connectedCallback()




Reference:


Wednesday 4 May 2022

How to navigate to Standard Edit record page LWC

 Hi,

The following code snippet helps to navigate to the Standard edit record page.


Code Snippet:

 this[NavigationMixin.Navigate]({            

                        type: 'standard__recordPage',

                        attributes: {

                            recordId: this.recordId,

                            objectApiName: 'Account',

                            actionName: 'edit',        

                        },

        

                        state: {

                            nooverride: 1,

                            backgroundContext: '/lightning/r/Account/' + this.recordid + '/view'        

        

                        }

        

                    });

                    eval("$A.get('e.force:refreshView').fire();");

}


Reference: 

https://developer.salesforce.com/docs/component-library/overview/components


How to auto populate default values when New button is overridden with lwc

 Hi,

The following js code snippet helps to auto-populate values when the New button is overridden.


Code Snippet:

 

 const defaultValues = encodeDefaultFieldValues({

                        Name: 'Salesforce Techbook Foundation',                       

                    });                         

                    this[NavigationMixin.Navigate]({

                        type: 'standard__objectPage',

                        attributes: {

                            objectApiName: 'Account',

                            actionName: 'new'

                        },

                        state: {

                            nooverride: '1',

                            recordTypeId: this.recordtypId,

                            defaultFieldValues: defaultValues

                        }

                    });

eval("$A.get('e.force:refreshView').fire();");


Reference : 

https://developer.salesforce.com/docs/component-library/overview/components

Tuesday 3 May 2022

Main Components to be retrieved for deploying a Community

 Hi,

When we have to deploy a community to another Salesforce org that is not connected then the following components have to be retrieved along with the other necessary components like Apex Classes, Visualforce page, Aura, etc., based on our project.

 <?xml version="1.0" encoding="UTF-8"?>

<Package xmlns="http://soap.sforce.com/2006/04/metadata">

  <types>       

        <members>*</members>

        <name>ContentAsset</name>

    </types>

    <types>       

        <members>*</members>

        <name>CustomSite</name>

    </types>

    <types>       

        <members>*</members>

        <name>Audience</name>

    </types>

    <types>       

        <members>*</members>

        <name>Network</name>

    </types>

    <types>       

        <members>*</members>

        <name>SiteDotCom</name>

    </types>

     <types>       

        <members>*</members>

        <name>NetworkBranding</name>

    </types>

     <types>       

        <members>*</members>

        <name>CustomSite</name>

    </types>

    <types>

        <members>*</members>

        <name>Profile</name>

    </types>    

     <types>

        <members>*</member>

        <name>CustomLabel</name>

    </types>

    <types>

        <members>*</member>

        <name>Flow</name>

    </types>

    <types>

        <members>*</member>

        <name>Community</name>

    </types>

    <types>

        <members>*</member>

        <name>CommunityTemplateDefinition</name>

    </types>

    <types>

        <members>*</member>

        <name>CommunityThemeDefinition</name>

    </types>

  <version>53.0</version>

</Package>


Reference:

https://developer.salesforce.com/docs/atlas.en-us.220.0.communities_dev.meta/communities_dev/networks_migrate_overview.htm

Tuesday 26 April 2022

How to Encode a string to Base64 format in Apex

 Hi ,

Here we are going to learn how to encode a string to Base64 format in Apex 

Eg:

String urlparam = 'Salesforce Techbook';

String urlString = EncodingUtil.base64Encode(Blob.valueof(urlparam));

System.debug(urlString);

Output: U2FsZXNmb3JjZSBUZWNoYm9vaw==


Reference: 

https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_restful_encodingUtil.htm

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_encoding.htm


Sunday 24 April 2022

Generate JSON with Map in apex

 Hi ,

Here we are going to learn how to generate JSON with the help of Map in apex.

Let's take the following JSON and see how to generate the same with the help of Map in apex.

JSON:

{

    "lastname":"SF",

    "firstname":"Techbook",

    "account":{

        "name":"Salesforce Techbook",

        "address":{

            "shippingstreet":"test_street",

            "shippingcity":"test_city"

        }

    },

    "phone":"12454565",

    "mailingcity":"test_cont_City"    

}

Let's try to generate the above JSON with Map:

//Preparation of  outer JSON object

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

jsonGenMap.put('lastname','SF');

jsonGenMap.put('firstname','Techbook');

jsonGenMap.put('phone','12454565');

jsonGenMap.put('mailingcity','test_cont_City');

//Preparation of "account" JSON object

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

jsonActMap.put('name','Salesforce Techbook');

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

jsonActAddressMap.put('shippingstreet','test_street');

jsonActAddressMap.put('shippingcity','test_city');

jsonActMap.put('address',jsonActAddressMap);

jsonGenMap.put('account',jsonActMap);

//Generation of JSON from the above with the help of "serialize" method under "JSON" class.

string jsonstring = JSON.serialize(jsonGenMap);

System.debug(jsonstring);


References:

https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Json.htm


Saturday 2 April 2022

JSON parsing with Map Sample for getting list of values

 Hi,

Here we are going to learn how to get the values from an array that has plain values instead of a list of JSON objects.

Let's take the example below.

Here we have "langaugeskills" array in the following JSON String with the values "English,Hindi, Telugu". To capture those values we have to follow the below approach.


String jsonStr = '{"LastName": "Balu","langaugeskills": ["English","Hindi","Telugu"]}';

Map<String,Object> jsonMap = (Map<String,Object>)JSON.deserializeUntyped(jsonStr);

System.debug('JSON :::'+jsonMap);

List<Object> langSkillsList = (List<Object>)jsonMap.get('langaugeskills');

System.debug('---->'+langSkillsList);

for(Object langStr:langSkillsList){

    System.debug((String)langStr);

}


output:



Reference:

https://salesforce-walker.blogspot.com/2021/04/json-parsing-using-map-sample.html

Wednesday 23 March 2022

How to display Translation from a Picklist in LWC

 Hi,

Here we are going to learn how to display translations for the Picklist values in LWC.

Here let's take the picklist field "LeadSource"

displayLead.html :

<template>

    <template if:true={isshowCard}>

        <lightning-card>


            <h3 slot="title" style="color: red;">              

                <lightning-icon icon-name="standard:lead" size="small"></lightning-icon> &nbsp;

                Lead Record

            </h3>

        

            <div>

                <lightning-layout>

                    <lightning-layout-item padding="around-small">

                        <div class="header-column">

                            <p class="field-title">

                                <b>Lead Name<br /> </b>

                            </p>

                            <p style="color: rgb(255, 81, 0);"> {leadname}</p>

                        </div>

                    </lightning-layout-item>

                    <lightning-layout-item padding="around-small">

                        <div class="header-column">

                            <p class="field-title">

                                <b>Lead Source <br /></b>

                            </p>

                            <p>{leadsource}</p>

                        </div>

                    </lightning-layout-item>

                </lightning-layout>

            </div>

        </lightning-card>

    </template>

</template>



displayLead.js :

import { LightningElement,api,wire} from 'lwc';

import LEAD_OBJECT from '@salesforce/schema/Lead';

import LEAD_SOURCE from "@salesforce/schema/Lead.LeadSource";

import LEAD_NAME from "@salesforce/schema/Lead.Name";

import { getRecord } from 'lightning/uiRecordApi';

const FIELDS = [LEAD_SOURCE, LEAD_NAME];

export default class DisplayLead extends LightningElement {

    @api recordId;

    leadRecord;  

leadsource;

leadname;

    @wire(getRecord, { recordId: '$recordId', fields: FIELDS })

    leadRecord({ error, data }) {

       if (data) {

            this.leadRecord = data; 

            //Here displayValue helps to display translation for picklist LeadSource 

            this.leadsource = this.accountRec.fields.LeadSource.displayValue;

            this.leadname =this.accountRec.fields.Name.value;

        }

    }

}

displayLead.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>

<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">

    <apiVersion>52.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

    </targets>

</LightningComponentBundle>


Reference:

https://developer.salesforce.com/docs/component-library/documentation/en/lwc


Thursday 13 January 2022

How to add a connected app to a second-generation(2GP) managed package.

  1. Create a Connected App in Salesforce instance where we maintain namespace.
  2. Create a first-generation managed package (1GP) and add the connected app. It’s fine if the connected app is the only component in the package. Always use the same namespace as the 2GP package for the 1GP package.
  3. Take note of the version number of the connected app; this number is needed later.
  4.  Upload the 1GP Package to create a package version.
  5. Promote the 1GP version to the released state.
  6. Promoting the 1GP version allows the connected app to be included in a second-generation managed package. We don’t need to install the 1GP version into an org.
  7. Now in our source code navigate to folder "connectedApps" where we are trying to generate 2GP Package



create an XML file with <connectedAppName>.connectedApp-meta.xml 

and the body of the XML file should be as shown below.

<ConnectedApp xmlns="http://soap.sforce.com/2006/04/metadata">
    <developerName><namespace>__<connected_app_Name></developerName>
    <label>A Connected App</label>
    <version>1.0</version>
</ConnectedApp>

Now generate a 2GP package and promote. Then the connected app is automatically added to your 2GP Package.

The version specified in the source file is the version number of the connected app. Use decimal formatting when specifying the version number. The version number must match the version number of the connected app before it was added to the 1GP managed package.

Note:

When you add a connected app to a 1GP package and upload the package, the version number of the connected app is auto-incremented. For example, when version 1.0 of a connected app is added to a 1GP package, the package version increments the version number of the connected app from 1.0 to 2.0. When creating the source file for your 2GP package, specify the version number of the connected app before it was uploaded into a 1GP package, in this case, 1.0.



Reference:

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

Wednesday 5 January 2022

How to show user license information on report

 Hi ,

We are going to learn how to show user license information in a report.

In Lightning Experience:


  1. Click the gear icon, and click Setup
  2. Enter Report Types in the Quick Find box, and select Report Types
  3. Click New Custom Report Type
  4. In the Primary Object field, select Users
  5. Enter a Name, Label, Description, and Category for your new report type
  6. Select a deployment status
  7. Click Next, then Save
  8. Click Edit Layout
  9. Under the 'View' dropdown box, click the Add fields related via lookup link
  10. Click Profile
  11. Select User License, then click ‘view related fields
  12. Select NameStatus, and Total Licenses, then click OK
  13. Click Save























Once the above steps are completed we can generate reports by using the above report type with report builder.

Reference: 


How to include a screen flow in a Lightning Web Component

 Hi, Assume  you have a flow called "Quick Contact Creation" and API Name for the same is "Quick_Contact_Creation". To i...