Custom Setting & Custom Metadata Cheatsheet

 Recently I took an interview for a Salesforce Developer and I asked the below question.

    Q: What is the difference between custom setting and custom metadata?

Most of them mentioned it a deployable apart from that no other answer so, I decided to list out the difference here.


I hope this will be helpful. Please let me know your thoughts.





Logout Link on Lightning Community

Currently I am working on the community implementation and I come accross the scenario where I need to place a logout link on the community page. On google most of them mention to redirect logout.jsp page. When I use this logout.jsp page it is just redirecting to the logout page without clearing the session. Then I started going through the salesforce documentation and came across the below Lightning Web Component(LWC) for the logout link.

LogoutPage.js 


This code will clear the session and redirect to the community login screen. To make this code work 100% in your community then you have to follow the below steps. 

 1. Your community should not be a public facing. 
 2. On the community setting Login and Logout pages should be set as default pages. 

I hope this will help. Please let me know your thoughts.

Formula Hours to Mins and Mins to Hours

   I was getting a requirement from the client to calculate Total Hours based on the user input. When I am searching on the google I didn't get a proper result so, I thought of writing this. User will enter the time in any of these format e.g. 1.00, 1.62 so the total hours should be calculated a s 3.00.

1. Convert the user input hours spent to min

2.  Summarise the above the field and then by using this summarised field calculate the total hours from the summarised min.


I hope this will help most of them. Please let me know your feedback in comments.

Free App Walkthrough 1: Sandbox Post-refresh Masking Scripts

    As a consultant I feel it's really important to know the handful of free apps which is available on the Appexchange.  I have started this 'Free App Walkthrough' serious to explain the configuration and usage of an app.

    In this post I am going to walkthrough 'Sandbox Post-refresh Masking Scripts'. With this app you can able to mask any fields with the below setting.
      1. Custom String
      2. Random Date
      3. Random Email
      4. Random Phone
      5. Random String

There are two way you can mask the data 
    1. On any type of sandbox, masking the existing data.
    2. Mask the data while creating/or refreshing the Sandbox.

List of important component which is created after installing this package
    1. Custom Metadata: Data Masking Configuration,  Post Copy Task
    2. Object: Automation Task Log
    3. Apex Class: SBX_BatchMaskSandboxData

 1. On any type of sandbox, masking the existing data:
        Let's create the configuration to mask the data in sandbox. You can mask both the standard and custom object fields. For example now I am going to mask the contact email field, to do that lets create the 'Data Masking Configuration' metadata record for contact and it's email. To do go to the 
        
        Setup --> Custom Metadata Type --> Click Manage Records on the Data Masking Configuration --> Click New. Enter the details as like below.

    

        Like this you can able to create data masking configuration for any objects and it's field. Once you created all the record you can run the below code on your developer console to mask the records.


        Once the job has completed you will receive the email and also the status will be stored in the 'Automation Task Log' object. 

Job status:




    Note: Key limitations include any validations on the fields may cause an issue with the scrambling.

2. Mask the data while creating/or refreshing the Sandbox:
            
      I will update this details next week.

Please let me know your thoughts and the data masking methods/tools which you are using.




    


 
 

Salesforce and Xero Integration Using OAuth 2.0

        In this article I am going to explain the steps to integrate Salesforce and Xero by using OAuth 2.0, the latest version of xero authentication.

Note: OAuth 1.0a will no longer be supported for any apps.

I am going to connect the salesforce and xero with 'OpenID Connect' authentication. If you want learn more about openID connect click here.

Create a app in Xero:

1. Open the below link and click 'New app' in right corner.
           https://developer.xero.com/myapps/

2. Provide the details as mentioned below
          App name: Demo (You can give any name)
          OAuth 2.0 grant type: Auth code (Web app)
          Company or application URL:
          https://lweb-dev-ed.lightning.force.com/services/auth/oauth/XeroAuthProvider
          <Salesforce domain URL>/services/auth/oauth/<name of the auth. provider which are going to create in the next step>
          OAuth 2.0 redirect URI:
          https://lweb-dev-ed.lightning.force.com/services/authcallback/XeroAuthProvider
          <Salesforce domain URL>/services/authcallback/<name of the auth. provider which are going to create in the next step>




3. Agree the terms and condition and click 'Create app'. Now you are on the App detail screen. Click ‘Generate Secret’ button to create the secret key.

4. Copy both the Client id and Client Secret and keep it in a separate note pad. We need this for our next step.
       
Create a Auth. Provider and Named Credential in Salesforce:

1.  In Salesforce go to Setup --> enter 'Auth' in the quick find and select the 'Auth. Providers'. Click 'New' and select 'Open ID Connect'. As I mentioned earlier I am going to connect open ID connect for integration.

2. Enter the details as mentioned below

           Name: XeroAuthProvider
           URL Suffix: This will be auto populated leave it as it is.
           Consumer Key: Paste the client id which you copied on the step 4
           Consumer Secret: Paste the client secret which you copied on the step 4.
           Authorize Endpoint URL: https://login.xero.com/identity/connect/authorize
           Token Endpoint URL: https://identity.xero.com/connect/token
           Include Consumer Secret in API Responses: Uncheck this checkbox

     Click Save. Now you are on the Auth. Provider detail page, on this page there is a section called 'Salesforce configuration' with 'OAuth-Only Initialization URL' and 'Callback URL'. Make sure this URL is same as in xero app which we create in the above steps. If this URL is not matching then connection won't be success.

3. Lets create a 'Named credentials'. Go to setup --> enter 'Named' in the quick find and select the Named Credentials --> click 'New'.  Enter the details as below.

       Label: XeroDemo
       Name: It will be auto populated as label. Leave it as it is.
       URL: https://api.xero.com/
       Identity Type: NamedPricipal
       Authentication Protocol: OAuth 2.0
       Authentication Provide: Select ‘XeroAuthProvider’ which you created in the previous step.
       Scope: openid offline_access accounting.settings.read
       Start Authentication Flow on Save: Check the checkbox.
       Allow Merge Fields in HTTP Header: Check the checkbox.

   Click 'Save', it will take you to the Xero login page(if you are not logged into xero). Once you entered the details you have the ability to select the xero organisation to be accessed from salesforce.
After the select click continue and you will be redirected to salesforce.

Note: Even the scope can be defined on the auth provider default scope.

Verify the connection:

If you run the below code in your developer console and if you get the status code as 200 then you are successfully connected the salesforce and xero.



Please let me know your thoughts on the comment.







Quarantine Activity as Salesforce Admin & Consultant

     In this post I am going to suggest few activity for admins and consultants who are supporting the business in this quarantine time.

1. Updating the account and contact database:
           Speak to the sales and marketing team to update the current account and contact database. There are few way as a admin/consultant you can support this activity.

            1.1. Creating reports on duplicate records: Duplicate records will be displayed only when you have enabled 'Report' option on the duplicate rule. If you enable now then it will work only for the future records. You have to update the existing records to get the duplicate record item to be created.
Below URL will help you to create the report on duplicate records.
            https://help.salesforce.com/articleView?id=duplicate_management_custom_report_types.htm&type=5

            1.2. Stay-in-Touch: As you already know stay in touch is retired with summer'17 release, but there is a free app exchange package called 'Contact Update Request' will help you with this stay-in-touch. By using this you can keep contact with current information.

            1.3 You can use the free data quality analysis tool to find out your data quality.
             https://appexchange.salesforce.com/appxListingDetail?listingId=a0N300000016cshEAA

2. Ask the marketing team to create the target list after the quarantine.
         This can be done by creating the campaign and adding the target audience.

3. Go through the business process with the team and make sure the system function is matching with the business process. If it's not you can plan for the enhancement.

4. Arrange a webinar session with team and educate the system process and features.

5. Optimizer: Run the optimizer report to review the current implementation and work on the recommendation which you have received in the report. 

6. Health Check: Review the standard health check page to make sure it meets the security standard.

7. Upgrading existing package: Client might be using some paid installed packages. Please check with the provider and make sure it is with the latest version. If it is not then plan the upgrade and educate the team with new features.

8. Upgrading the classes: As a maintenance activity you can update the classes with the latest release.
This needs to be first done in sandbox and then deployed to Production.

9. You can clean the metadata and unused fields. You can use Field Trip appexchange tool to find out the unused fields

In this there are few item which you might be already doing as a org maintenance but if you haven't then this might be a right time to do this. If you are doing any other activity please let me know in comment.