Search This Blog

Saturday, October 30, 2021

System Administrator not able to login as other user in Salesforce - Salesforce Globe For You

System Administrator not able to login as other user in Salesforce - Salesforce Globe For You

Problem: When system Admin logged into the Salesforce org,and went to the users list,login button before the user is not visibile which is used for Admins to login as other user



Solution: 'Administrators Can Log in as Any User'  setting should be enabled in order for Admins to get access to login as other user.

Go to Setup --> Security controls --> Login Access Policies.

Enable the checkbox next to 'Administrators Can Log in as Any User' as shown in the image below



Friday, October 29, 2021

Getting the values in Apex class but not in lightning component - Salesforce Globe For You

Getting the values in Apex class but not in lightning component - Salesforce Globe For You

Problem: When using wrapper class, the wrapper variable data is shown in debug logs of apex but in LWC component ,the data is not shown.

Solution: When using wrapper class,even the wrapper variables needs to be @AuraEnabled annotation as shown below

public class PersonData {

    @AuraEnabled public string name {get;set;}

    @AuraEnabled public String id {get;set;}

}

Example:

Apex Class: DisplayDataController

public class DisplayDataController {

    @AuraEnabled

    public static List<PersonData> fetchData() {

        List<PersonData> lstPersonData = new List<PersonData>();

        for(integer i =0; i<2; i++) {

            PersonData objPersonData = new PersonData();

            integer j= i+1;

            objPersonData.id = '00'+j;

            objPersonData.name = 'Test '+j;

            lstPersonData.add(objPersonData);

        }

        return lstPersonData;

    }

    public class PersonData {

        @AuraEnabled public string name {get;set;}

        @AuraEnabled public String id {get;set;}

    }

}

displayData.html

<template>

    <lightning-Card title="Person Data">

        <div>

            <lightning-datatable

                    key-field="id"

                    data={lstPerson}

                    columns={columns}>

            </lightning-datatable>

        </div>    

    </lightning-Card>

</template>

displayData.js

import { LightningElement,track } from 'lwc';

import personData from '@salesforce/apex/DisplayDataController.fetchData';

const columns = [

    { label: 'id', fieldName: 'id' },

    { label: 'name', fieldName: 'name'}

    

];

export default class DisplayData extends LightningElement {

    @track lstPerson;

    @track columns = columns;

    connectedCallback() {

        personData().then(result => {

            this.lstPerson = result;

            console.log('lstPerson',result);

        })

        .catch(error => {

            this.error = error;

        });

    }


}

displayData.js-meta.xml

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

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

    <apiVersion>51.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:



Thursday, October 28, 2021

How to remove or hide 'setup' link from specific users in salesforce - Salesforce Globe For You

How to remove or hide 'setup' link from specific users in salesforce -  Salesforce Globe For You

Solution: Uncheck the “View Setup and Configuration” permission under the Systems Permission section of associated profile or permission set.



How to skip a particular piece of code while test class is running in apex - Salesforce Globe For You

How to skip a particular piece of code while test class is running in apex -  Salesforce Globe For You

Solution: Use Test.isRunningTest() This method returns true if this code is called from test method of test class.

So in case if you need to skip piece of code when test class is running,place that code inside if(!Test.isRunningTest()){}.

Example:

public class SkipCodeController {

    public static void run() {

        if(!Test.isRunningTest()) {

            system.debug('This method runs in normal method call from normal class');

        } else {

            system.debug('This method runs only when called from Test Class');

        }

    }

}

Output: When you call this method like SkipCodeController.run() output will be



Monday, October 25, 2021

How to lock sobject records in Apex - Salesforce Globe For You

How to lock sobject records in Apex - Salesforce Globe For You

Solution: Use FOR UPDATE keyword in inline SOQL queries to lock sObject records.

Example: Select id,name from Lead Limit 1 FOR UPDATE

Sample Code:

List<Lead> lstLead = new List<Lead>();

for(Lead objLead : [Select Id,lastName from Lead Limit 1 FOR UPDATE]) {

objLead.lastName = 'Lead '+objLead.lastName;  

    lstLead.add(objLead);

}

if(!lstLead.isEMPTY()) {

update lstLead;

    system.debug('lstLead '+lstLead[0].lastName);

}

Output:



Note: You can’t use the ORDER BY keywords in  SOQL query where FOR UPDATE is used.

How to find the referenced apex controller in a lightning component(Aura or LWC) in salesforce with out looking into component code - Salesforce Globe For You

How to find the referenced apex controller in a lightning component(Aura or LWC) in salesforce with out looking into component code - Salesforce Globe For You

Solution: Go to setup --> Custom Code --> Lightning Components --> click on the respective component as shown in the image  below.



The LWC dependencies section as shown in the image below gives the required information.



Monday, October 18, 2021

How to retrieve custom metadata records in visual studio code using package.xml - Salesforce Globe For You

 How to retrieve custom metadata records in visual studio code using package.xml - Salesforce Globe For You

Solution: Assume Test_Metadata_Records__mdt is the api name of the custom metadata object and First is the record created.

Use Test_Metadata_Records.First as members and CustomMetadata as name as shown below

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

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

<types>

<members>Test_Metadata_Records.First</members>

<name>CustomMetadata</name>

</types>

<version>51.0</version>

</Package>

Output:



Wednesday, October 13, 2021

How to prepare or get set of record ids from SOQL query without using for loop in apex - Salesforce Globe For You

 How to prepare or get set of record ids from SOQL query without using for loop in apex - Salesforce Globe For You

Sample Code:

Set<Id> setLeadIds = new Set<Id>();

setLeadIds = new Map<Id,Lead>([Select id,name from Lead]).keyset();

system.debug('setLeadIds:'+setLeadIds);

Output