Monday, 26 April 2021

Override Tab with Lightning Component

 Hi,

Here are we are going to learn about overriding standard object or custom object tab for the following scenario.

Scenario: Invoke an apex method when the Account tab is loaded and then navigate to the Account default list view.

Solution:

Lighning Component: 

AccountOverride.cmp

<aura:component implements="flexipage:availableForAllPageTypes,lightning:actionOverride" access="global">

    <aura:handler name="init" value="{!this}" action="{!c.init}"/>

<div class="spinnerCss" >

      <div class="slds-spinner_container">

        <div role="status" class="slds-spinner slds-spinner_medium slds-spinner_brand">

          <span class="slds-assistive-text">Loading</span>

          <div class="slds-spinner__dot-a"></div>

          <div class="slds-spinner__dot-b"></div>

        </div>

      </div>

</div>

</aura:component>

AccountOverrideController.js:

({    

    init : function(component, event, helper) {  

        var action = component.get("c.sampleMethod");

        action.setCallback(this, function(response){

            var state = response.getState();          

        });

        $A.enqueueAction(action);         

        window.open(`${window.location.origin}/lightning/o/Account/list`,'_top')

    }  

})

AccountOverride.css:

.THIS.spinnerCss{

    position: relative;

    display: inline-block;

    width: 100%;

    height: 100%;

    background-color: rgba(255, 255, 255, 1);

}


Apex Class:

public class AccountTabOverride {

   @AuraEnabled

    public static String sampleMethod() {       

        return 'Thank You';

    }

}


Reference:

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

JSON parsing using Map sample

 Hi,

Here we are going to learn how to do parsing JSON with the help of Map.

Let's take a simple JSON String


String jsonString = '{"accountRecords": [{"actNumber": "ACT0001","rating":"hot"}]}';

Here let's try to get actNumber and rating attributes values.

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

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

List<Object> accountRecordsList= (List<Object>)jsonMap.get('accountRecords');

System.debug('---'+accountRecordsList[0]);
Map<String,Object> accountRecordMap= (Map<String,Object>)accountRecordsList[0];


System.debug('---'+accountRecordMap.get('actNumber'));

System.debug('---'+accountRecordMap.get('rating'));


Reference:

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

Tuesday, 13 April 2021

URL Hacking for import wizard in Lightning experience

 Hi ,

Here we are going to learn how to do URL hacking for import wizard.

By default, we have the "Import" button in the list view.

But when we want to achieve the same from related list (Eg:on Contact Related List on Account) then we can simply do URL hacking as shown below:


Syntax:

/dataImporter/dataimporter.app?objectSelection=<Object API Name>

Eg:

/dataImporter/dataimporter.app?objectSelection=Contact

Reference:

More about Import Wizard

Friday, 9 April 2021

How to create a Second Generation managed package and install

 Hi ,

Here we are going to learn how to create a Second Generation Managed Package and how to install the same.

Before you create a Second Generation Managed Package , we have to complete the following things.

  • Create a Developer Edition org if you don't have already and configure a name space 
  • Now Enable DevHub and Second Generation package where you want to register your name space(If you are implementing AppExchange product then Salesforce Recommends to d the same in PBO org)
Now you are ready to create a Second Generation Managed Package.
  • Authorize DevHub using the following command via command prompt or vs code
        sfdx force:auth:web:login -d -a DevHub
  • Check you  sfdx-project.json and include your name. Here I have included name space called "Balu131"
       sfdx-project.json
    {
      "packageDirectories": [
         {
            "path": "force-app",
            "default": true                  
         }
         ],
       "namespace": "Balu131",
       "sfdcLoginUrl": "https://login.salesforce.com",
       "sourceApiVersion": "50.0"   
    }
  • Create a package using the following command
        sfdx force:package:create --name "test2GPManged" --path force-app --packagetype Managed --            targetdevhubusername DevHub

        once it is completed then it adds the verionName,versionNumber and packageAliases to your            sfdx-project.json file.
       {
        "packageDirectories": [
          {
            "path": "force-app",
            "default": true,
            "package": "test2GPManged",
            "versionName": "ver 0.1",
            "versionNumber": "0.1.0.NEXT"
         }
       ],
       "namespace": "Balu131",
       "sfdcLoginUrl": "https://login.salesforce.com",
       "sourceApiVersion": "50.0",
       "packageAliases": {
          "test2GPManged": "0Ho09000000wk90CAA"
       }
    }
  • Create a version using the following command
       sfdx force:package:version:create --package "test2GPManged" --installationkey test1234 --wait 10          -v DevHub

or 
       sfdx force:package:version:create --package "test2GPManged" --installationkey test1234 --wait 10      --codecoverage    -v DevHub

  • Promote your package version (Note: to promote we always need to run test classes with the help of --codecoverage parameter while creating version above.
            sfdx force:package:version:promote -p test2GPManged@1.0.0-1 -v DevHub
  • Install your managed package into destination org.
        sfdx force:package:install --package "test2GPManged@1.0.0-1" --targetusername       PackageDemoOrg --installationkey test1234 --wait 10 --publishwait 10


Reference:

Friday, 2 April 2021

How to save a record that’s been identified as a duplicate.

 Hi,

Here we are going to learn how to save a record that's identified as duplicate with the help of DMLOptions.

Especially it helps to bypass duplicate rules in test class.

Eg:

Save an account record that’s been identified as a duplicate\

Database.DMLOptions dml = new Database.DMLOptions(); 

dml.DuplicateRuleHeader.allowSave = true;

dml.DuplicateRuleHeader.runAsCurrentUser = true;

Account duplicateAccount = new Account(Name='dupe');

Database.SaveResult sr = Database.insert(duplicateAccount, dml);

if (sr.isSuccess()) {

System.debug('Duplicate account has been inserted in Salesforce!');

}


Reference:

Click for more information

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 ...