Wednesday, 31 July 2024

ContentNote record Creation in Apex

 Hi,

We have to create 2 object records :

  • ContentNote - For Creating ContentNote Record
  • ContentDocumentLink - For linking to the Record (ex: Account, Contact etc)

ContentNote Record creation:


The following Apex code creates a note and escapes any special characters so they’re converted to their HTML equivalents.

ContentNote cnObj = new ContentNote(); cnObj.Title = 'test1'; String body = 'Hello World. Before insert/update,
escape special characters such as ", ', &,
and other standard escape characters.'; cnObj.Content = Blob.valueOf(body.escapeHTML4()); insert cnObj;

The following code creates a note using text that is already formatted as HTML, so it doesn’t need to be escaped.

ContentNote cnObj = new ContentNote(); cnObj.Title = 'test2'; String body = '<b>Hello World. Because this text is already
formatted as HTML,
it does not need to be escaped. Special characters such as &quot;, etc.
must already use their HTML equivalents.
</b>'; cnObj.Content = body; insert cnObj;

To Link to a record (eg: Account Record Id = 001XXXXXXXXXXXXXXX) :

ContentDocumentLink cdlObj = new ContentDocumentLink();

cdlObj.ContentDocumentId = cnObj.Id;

cdlObj.LinkedEntityId = '001XXXXXXXXXXXXXXX';//We have to add record id //dynamically here based on requirement

insert cdlObj;



Reference:

Tuesday, 30 July 2024

How do we retrieve picklist values from standard picklist fields?

 Hi ,

 When we have to retrieve picklist values from the standard Picklist Fields (eg: Stage on Opportunity object , Industry on Account object etc.,) then we have to use StandardValueSet. 

In API version 38.0 and later, standard picklists are represented by the StandardValueSet type. In previous versions, standard picklists are represented by the CustomField type. 

Note:

The names of standard value sets and picklist fields are case-sensitive.


Example: 

To retrieve picklist values from Opportunity's Stage field then we have to use StandardValueSet as shown below.

package.xml:

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

Output:




This following link has standard picklists as standard value sets and their corresponding field names.



Reference:


Sunday, 28 July 2024

How to configure a LWC for Screen flows

 Hi,

To include a custom Lightning Web Component in a Flow Screen and define its properties (input/output), we must configure the appropriate values in the meta file (componentName.js-meta.xml).

  • To make your component usable in a flow screen, add the lightning__FlowScreen target.
  • To add input fields to your component, add targetConfig properties.
  • To restrict a property to inputOnly or outputOnly, use the role attribute. 
  • For example, if a property is restricted to outputOnly, users can’t set its value from a Lightning record page. If you don’t specify the role attribute, the default value allows input and output.
  • This sample component has five flow screen input fields.   The startDate property is set to inputOnly.

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

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

      <apiVersion>61.0</apiVersion>

      <isExposed>true</isExposed>

      <masterLabel>Best Component Ever</masterLabel>

      <description>This is a demo component.</description>

      <targets>

        <target>lightning__FlowScreen</target>

      </targets>

      <targetConfigs>

        <targetConfig targets="lightning__FlowScreen">

          <property name="startDate" label="Start Date" type="Date" role="inputOnly" />

          <property name="account" label="Account Chosen" type="@salesforce/schema/Account" />

          <property name="annualRevenue" label="Annual Revenue" type="Integer" role="outputOnly" />

          <property name="name" label="Account Name" type="String" />

        </targetConfig>

      </targetConfigs>

    </LightningComponentBundle>




    Reference:

    https://developer.salesforce.com/docs/platform/lwc/guide/use-config-for-flow-screens.html

    https://developer.salesforce.com/docs/platform/lwc/guide/reference-configuration-tags.html




    Thursday, 25 July 2024

    Uninstall Salesforce CLI from macOS, Linux and Windows

    Hi,

    If you are facing issues with VS Code with Salesforce CLI then follow the instructions below to uninstall completely. Once un install is completed then you can re install for better performance.

    The method to uninstall Salesforce CLI differs depending on whether you used an operating-specific installer or npm

    If  You Installed on macOS or Linux Using the Installers or TAR Files


    macOS or Linux


    Enter all these commands in a terminal to remove Salesforce CLI. The commands uninstall both sfdx (v7) and sf (v1 and v2).

    sudo rm -rf /usr/local/sfdx
    sudo rm -rf /usr/local/lib/sfdx
    sudo rm -rf /usr/local/bin/sfdx
    sudo rm -rf ~/.local/share/sfdx ~/.config/sfdx ~/.cache/sfdx
    sudo rm -rf ~/Library/Caches/sfdx
    sudo rm -rf /usr/local/sf
    sudo rm -rf /usr/local/bin/sf
    sudo rm -rf ~/.local/share/sf ~/.config/sf ~/.cache/sf
    sudo rm -rf ~/Library/Caches/sf


    If you Installed on Windows Using the Installer


    These steps uninstall both sfdx (v7) and sf (v1 and v2):

    1. Select Start > Control Panel > Programs > Programs and Features.
    2. Select @salesforce/cli, and click Uninstall.
    3. Inside your home directory, delete these two directories:
        • config\sfdx
        • config\sf

    If Salesforce CLI is still installed, delete these directories:

        • %LOCALAPPDATA%\sfdx
        • %LOCALAPPDATA%\sf


    If You Installed Using npm


    To uninstall sfdx (v7), run this npm command from a terminal or command prompt:

        npm uninstall sfdx-cli --global

    To uninstall sf (v1 or v2), run this command:
        
        npm uninstall @salesforce/cli --global

    Inside your home directory, delete these two directories.

      • Library/Caches/sfdx (On Windows: Library\Caches\sfdx)
      • Library/Caches/sf (On Windows: Library\Caches\sf)



    Reference:
    https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_uninstall.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 ...