Sunday, 30 June 2019

Load or Update Records with the Custom Metadata Loader

Usually, we can't insert or update Custom Metadata records using Apex with normal DML statements.

We have custom meta loader to insert or update multiple records into Custom Metadata.

The custom metadata loader lets you load or update up to 200 records with a single call.

  1. Download the tool from GitHub and deploy the package to your org via Workbench. Create the .zip file from the contents of the custom_md_loader directory instead of zipping up the directory itself.
  2. Create a .csv file with a header that contains the custom metadata type’s field API names. Either the Label or the Developer Name field is required. See sample.csv in your download for an example. If your org is namespaced, include the namespace prefix in your header. To update an existing custom metadata record, use the Label or Developer Name field to identify it.
  3. From Setup, assign the Custom Metadata Loader permission set to the appropriate users, including yourself.
  4. From the App Picker, select Custom Metadata Loader.
  5. Click the Custom Metadata Loader tab. If you haven’t already done so, the app prompts you to configure your Remote Site Settings.
  6. Upload your .csv file and select the corresponding custom metadata type.
  7. Click Create/Update custom metadata to bulk-load the records from the .csv file or update existing records. If the file has duplicate Label or Developer Name entries, the last entry becomes the new or updated record.


Saturday, 22 June 2019

Custom Metadata Record creation in apex


Here I am going to explain how can we create custom metadata record in apex.

Usually, we can' create custom metadata record through DML statements in apex.

But we have  "Metadata" class to create Custom Metadata record in apex.

When we use this no DML operations happen for creating records. instead, it does the deployment of custom metadata values.

Whenever we want to use this we have to create a call back class which implements "Metadata.DeployCallback" interface as shown below as this action is asynchronous.

Callback Class:
public class MetadataCallbackCls implements Metadata.DeployCallback {
    public void handleResult(Metadata.DeployResult result,
                             Metadata.DeployCallbackContext context) {
        if (result.status == Metadata.DeployStatus.Succeeded) {
            System.debug('success: '+ result);
        } else {         
            System.debug('fail: '+ result);

Example Snippet for creating Custom Meta Data:

Let's take custom metadata type "User_Creds__mdt" which has a custom field "Password__c".

To insert a record into the same we have to follow the same below.

    Metadata.CustomMetadata customMetadataObj =  new Metadata.CustomMetadata();
    customMetadataObj .fullName = 'User_Creds__mdt.Balaji_M';
    customMetadataObj .label = 'Balaji_M';

    Metadata.CustomMetadataValue customFieldObj = new Metadata.CustomMetadataValue();
    customFieldObj .field = 'Password__c';
    customFieldObj .value = 'XXXXX';


    Metadata.DeployContainer containerObj= new Metadata.DeployContainer();

    MetadataCallbackCls  callback = new MetadataCallbackCls ();
    Id jobId = Metadata.Operations.enqueueDeployment(containerObj, callback);



Sunday, 5 May 2019

What is Lightning Web Component

Hi ,

I just want to give you small information about Lightning Web Component.

We can build Lightning components using two programming models:

  1. Original model, Aura Components
  2. Lightning Web Components

Lightning web components are custom HTML elements built using HTML and modern JavaScript. 
Lightning web components and Aura components can coexist and interoperate on a page.

To admins and end users, they both appear as Lightning components.


Configure Default Field Values with Custom Metadata Types

Hi ,

Now with Spring 19 we can configure default field values with custom metadata types.
While creating fields you can defined the default value using formula expression. In formula expression you may not able to see the  record name with field from meta data type.

But you can following syntax to include one metadata record field value. 




DiscountPercent__mdt - API name of the metadata type

IT - is API Name of the record in the metadata type

Discount__C- is  Field API Name of the metadata type where we configure discount value.

By using this you can avoid updating the data references when there is any default value change in future instead you just need to change in one location which reflects all references.

Sunday, 20 January 2019

Create Dynamic Picklists for Your Custom Components (design:component)


We can expose a component property as a picklist when the component is configured in the Lightning App Builder. The picklist’s values are provided by an Apex class that you create.

For example, let’s say you’re creating a component for the Home page to display an object records. You can use an Apex class to put the object Names of your Salesforce org in a picklist in the component’s properties in the Lightning App Builder. Then, when admins add the component to a Home page, they can easily select the appropriate object to display records on the page.

Usually we use <design:component/> to set default values for a component while adding it in App Builder. When we want to provide picklist to hold all objects for selection while adding we have to follow the things below.

  • Create a custom Apex class to use as a datasource for the picklist. The Apex class must extend the VisualEditor.DynamicPickList abstract class.
  • Add an attribute to your design file that specifies your custom Apex class as the datasource.
Apex Class

global class MyCustomPickList extends VisualEditor.DynamicPickList{
    global override VisualEditor.DataRow getDefaultValue(){
        VisualEditor.DataRow defaultValue = new VisualEditor.DataRow('account', 'Account');
        return defaultValue;
    global override VisualEditor.DynamicPickListRows getValues() {        
        VisualEditor.DynamicPickListRows  picklistRowsList = new VisualEditor.DynamicPickListRows();
        List<VisualEditor.DataRow> dataRowsList = new List<VisualEditor.DataRow>();
        for(Schema.SObjectType sobjectTypeName:schema.getGlobalDescribe().values()){
            VisualEditor.DataRow rowObj = new VisualEditor.DataRow(sobjectTypeName.getDescribe().getLabel(), sobjectTypeName.getDescribe().getName());
        return picklistRowsList;

Add the Apex Class to Your Design File
To specify an Apex class as a datasource in an existing component, add the datasource

        <design:attribute name="sobjectName" datasource="apex://MyCustomPickList"/>

Dynamic Picklist Considerations

  • Specifying the Apex datasource as public isn’t respected in managed packages. If an Apex class is public and part of a managed package, it can be used as a datasource for custom components in the subscriber org.
  • Profile access on the Apex class isn’t respected when the Apex class is used as a datasource. If an admin’s profile doesn’t have access to the Apex class but does have access to the custom component, the admin sees values provided by the Apex class on the component in the Lightning App Builder.

Saturday, 8 December 2018

Convert 15 character IDs to 18 character IDs in formula field

Hi ,

We have new method "CASESAFEID()"in formula field now to make 15 character Id to 18 character.

1. Go to Setup | Customize | object name | click Fields
a. For Custom objects: Setup Create Objects | object name
3. In the related list "Custom Fields & Relationships" click New.
4. Click the Formula radio button.
5. Click the Text radio button for 'Formula Return Type.'
6. Input the following Formula into the Formula Editor:

7. Set Field Visibility, add or remove from the page layout.
 8. Click Save.

1. Go to Setup Object Manager | Object name | Fields & Relationships
2. Click New.
3. Click the Formula radio button.
4. Click the Text radio button for 'Formula Return Type.'
5. Input the following formula into the Formula Editor:

6. Set Field Visibility, add or remove from the page layout.
7. Click Save.


Sunday, 25 November 2018

Run Script After Sandbox Creation and Refresh

Hi ,
We have an interface SandboxPostCopy from to do data manipulation after sandbox is created or refresh.
It makes our  sandbox environment business ready, automate data manipulation or business logic tasks.
At sandbox creation, specify a single Apex class to perform the tasks. This class executes every time the sandbox is copied.
Lightning interface of sandbox post-copy script specification

Create an Apex class that implements SandboxPostCopy and specify the class here. For example, the following Apex class simply reports the three contexts available in SandboxPostCopy: your organization ID, sandbox ID, and sandbox name:
global class HelloWorld implements SandboxPostCopy {
  global void runApexClass(SandboxContext context) {
      System.debug('Hello Tester Pester ' + context.organizationId()
           + ' ' + context.sandboxId() + context.sandboxName()); 

you can write your business logic in the method "runApexClass"


Monday, 19 November 2018

SFDX with Non Scratch Orgs

Hi ,

Gave demo on SFDX with Non Scratch orgs in our Salesforce Techbook Channel. You can learn how to use SFDX with Non Scratch orgs after this demo.

VS Code:
Salesforce Extensions:

Monday, 12 November 2018

Software installations for SFDX setup

Hi ,

We need to setup the following software in the order mentioned

1)Install Java8 (jdk 8)  and set path
2)Install SFDXCLI "" and set path
3)Install VS Code
4)Install "Salesforce Extension Pack" in VS code  (Under extensions section search for Salesforce Extensions for Visual Studio Code)


Sunday, 14 October 2018

Get Record Type Id from lightning component in standard new action override (getting any url parameter)

Hi ,

Here we have requirement to get record type id from lightning component when standard "New" action is overrided.

To get selected RecordTypeId from the component we have to implement the lightning interface "lightning:isUrlAddressable" which will be useful to access parameter "RecordTypeId" from the top level.


Ligthtning Component:

<aura:component implements="lightning:isUrlAddressable" description="c:helloTarget component">
    <aura:attribute name="firstname" type="String" />
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    Hello {!v.firstname}.

    init: function(cmp, evt, helper) {
        var myPageRef = cmp.get("v.pageReference");
        var firstname = myPageRef.state.RecordTypeId;
        cmp.set("v.firstname", firstname);


lightning:workspaceAPI on Lightning Console Applications (Getting record id from record tab)

Hi ,

To access tabs or sub tabs information in Salesforce Classic console application we have Console Integration Toolkit.
In the same way to access tabs or sub tabs information in Lightning Conosle Application we have to use "workspaceAPI".
To access methods of "workspaceAPI" we have to create an instance of the lightning:workspaceAPI component and assign an aura:id attribute to it as shown below .

<lightning:workspaceAPI aura:id="workspace"/>

This component allows you to access methods for programmatically controlling workspace tabs and subtabs in a Lightning console app. In Lightning console apps, records open as workspace tabs and their related records open as subtabs.

When a record is opened in Lighning Console application  we should be able to find out the record ID from the record tab, for further process from application utility menu items.


<aura:component                  implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:appHostable" 
                access="global"  controller="UpdateCaseController">
    <lightning:workspaceAPI aura:id="workspace" />

    <aura:attribute name="recordId" type="String"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>


doInit : function(component, event, helper) {
        var workspaceAPI = component.find("workspace");
        workspaceAPI.getTabInfo().then(function(response) {
                       var action = component.get("c.updateCase");        
                             var result = data.getReturnValue();

Apex Controller:

public class UpdateCaseController{
   public static void updateCase(String caseRecordId){
       Case caseObj = new Case(Id=caseRecordId,ownerId=UserInfo.getUserId());
        update caseObj;



Load or Update Records with the Custom Metadata Loader

Hi, Usually, we can't insert or update Custom Metadata records using Apex with normal DML statements. We have custom meta loader to ...