Play Games

Search This Blog

Saturday, May 28, 2022

System.LimitException: Too many query rows: 50001 in salesforce - Salesforce Globe For You

System.LimitException: Too many query rows: 50001 in salesforce - Salesforce Globe For You

Answer: For each Apex transaction,total number of records retrieved by SOQL queries whether synchronous or asynchronous is 50000.

If single or multiple soql queries are running in a single transaction and the total sum of records returned 

by all queries in that single apex transaction exceeds 50000,then this error occurs.

Solution

1)Use conditions in soql queries if possible to filter the records.

2) Use Batch Apex.

Create Lead Assignment Rule in Salesforce - Salesforce Globe For You

Create Lead Assignment Rule in Salesforce - Salesforce Globe For You

Solution: Go to Setup --> Feature Settings --> Marketing --> Lead Assignment Rules


click on New button and create the assignment rule and also rule criteria as shown below.



Need for governor limits in Salesforce - Salesforce Globe For You

Need for governor limits in Salesforce - Salesforce Globe For You

Ans: Salesforce is a multitenant environment and these governor limits are imposed so that the shared resources won't be monopolized.

Wednesday, May 25, 2022

Hide or remove account hierarchy link in account record detail page in salesforce - Salesforce Globe For You

Hide or remove account hierarchy link in account record detail page in salesforce - Salesforce Globe For You

Solution: Go to Setup --> Feature Settings --> Sales --> Account Settings --> Make 'Show View Hierarchy link on account pages' 

in General Settings to false and save it.

Output:

Before 


After disable the link






Customize or modify the columns that display in the account hierarchy in salesforce - Salesforce Globe For You

Solution: Go to Setup --> Object Manager --> Account --> Hierarchy Columns 

click on New Button and add required columns and save it.

Output:



Tuesday, May 24, 2022

SOQL query to get accounts which doesn't have any contacts associated in salesforce - Salesforce Globe For You

SOQL query to get accounts which doesn't have any contacts associated in salesforce -  Salesforce Globe For You

Solution: Use the query below

Select Id, Name From Account Where Id NOT IN (Select AccountId From Contact)

Example:

Run the following piece of code in the execute anonymous window

List<Account> lstAccountWithOutContacts = new List<Account>();

lstAccountWithOutContacts = [Select Id, Name From Account Where Id NOT IN (Select AccountId From Contact)];

system.debug('Number of Accounts without Contacts: '+lstAccountWithOutContacts.size());

Output:

Note: The above query may give an error if the result has morethan 50000 rows.Use Limit as shown below

Select Id, Name From Account Where Id NOT IN (Select AccountId From Contact) Limit 50000

SOQL query to get accounts which have atleast one contact in salesforce - Salesforce Globe For You

SOQL query to get accounts which have atleast one contact in salesforce -  Salesforce Globe For You

Solution: Use the query below

Select Id, Name From Account Where Id  IN (Select AccountId From Contact)

Example:

Run the following piece of code in the execute anonymous window

List<Account> lstAccountWithContacts = new List<Account>();

lstAccountWithContacts = [Select Id, Name From Account Where Id  IN (Select AccountId From Contact)];

system.debug('Number of Accounts with Contacts: '+lstAccountWithContacts.size());

Output:

Note: The above query may give an error if the result has morethan 50000 rows.Use Limit as shown below

Select Id, Name From Account Where Id IN (Select AccountId From Contact) Limit 50000

Sunday, May 22, 2022

determine whether a lead is converted or not in salesforce - SalesforceGlobe4U

determine whether a lead is converted or not in salesforce - SalesforceGlobe4U

Solution: Use IsConverted field in the Lead object to check if a lead is converted or not in SOQL Query

Example:

select id,IsConverted from Lead where id=:leadid //leadid is the lead record id

Output:



Saturday, May 21, 2022

display Confirm dialog box in Lightning Web Component(LWC) - SalesforceGlobe4U

display Confirm dialog box in Lightning Web Component(LWC) - SalesforceGlobe4U

Solution: Use LightningConfirm module to show confirm box in lightning web component.

Example:

showConfirmBoxInLWC.html

<template>

    <lightning-card>

        <lightning-button label="Show Confirm Dialog" onclick={showConfirm}></lightning-button>

    </lightning-card>

</template>

showConfirmBoxInLWC.js

import { LightningElement } from 'lwc';

import LightningConfirm from 'lightning/confirm';

export default class ShowConfirmBoxInLWC extends LightningElement {

    async showConfirm() {

        await LightningConfirm.open({

            message:'Are you ready to learn Lightning Confirm Box in LWC?',

            label:'Welcome to Lightning Confirm'

        }).then((result) => {

            console.log('confirm: ',result);

        });

    }

}

showConfirmBoxInLWC.js-meta.xml

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

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

    <apiVersion>54.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:





display prompt dialog box in Lightning Web Component(LWC) - SalesforceGlobe4U

Solution: Use LightningPrompt module to show prompt box in lightning web component.

Example:

showPromptBoxInLWC.html

<template>

    <lightning-card>

        <lightning-button label="Show Prompt Dialog" onclick={showPrompt}></lightning-button>

    </lightning-card>

</template>

showPromptBoxInLWC.js

import { LightningElement } from 'lwc';

import LightningPrompt from 'lightning/prompt';

export default class ShowPromptBoxInLWC extends LightningElement {

    async showPrompt() {

        await LightningPrompt.open({

            message:'Welcome to Lightning Prompt in LWC',

            label:'Are you intrested to Learn Lightning Prompt?'

        }).then((result) => {

            console.log('Prompt: ',result);

        });

    }

}

showPromptBoxInLWC.js-meta.xml

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

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

    <apiVersion>54.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:





Get the number of records of a salesforce object using SOQL query in Salesforce - SalesforceGlobe4U

Fetch the number of records of a salesforce object using SOQL query in Salesforce - SalesforceGlobe4U

Solution: Use the count() in SOQL query to get the number of records of a specific object.

Example: In order to get the count of number of account records present in salesforce use the below query

select count() from Account

Output:



Tuesday, May 17, 2022

Show alerts in Lightning Web Component(LWC) - SalesforceGlobe4U

Solution: Use LightningAlert module to show alert in lightning web component.

showAlertInLWC.html

<template>

    <lightning-card>

        <lightning-button label="Show Alert" onclick={showAlert}></lightning-button>

    </lightning-card>

</template>

showAlertInLWC.js

import { LightningElement } from 'lwc';

import LightningAlert from 'lightning/alert';

export default class ShowAlertInLWC extends LightningElement {

    async showAlert() {

        await LightningAlert.open({

            message:'Welcome to Lightning Alert in LWC',

            theme:'success',

            label:'This is a alert Component'

        });

    }

}

showAlertInLWC.js-meta.xml

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

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

    <apiVersion>54.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:




Monday, May 16, 2022

Make readonly fields editable for a user in salesforce - SalesforceGlobe4U

Make readonly fields editable for a user in salesforce - SalesforceGlobe4U

Solution: Create a permission set and make 'Edit Read Only Fields' checkbox to true in the system permissions and then assign this permission set to the user who need this access.


Example:

Step 1: Create a permission set 'Make Read Only Fields Editable' and make 'Edit Read Only Fields' checkbox to true in the system permissions

as shown in image below



Step 2:  Assign this permission set to respective user

click on 'Manage assignments' button on the permission set


click on 'Add Assignments' buttons and select respective user and click on assign button.


That's it. Now the assigned users have the permission to edit the readonly fields.

Note: System fields like 'modified date' and 'formula field' will still be not editable.

Thursday, May 12, 2022

call apex method with parameters from the lightning web component in salesforce - SalesforceGlobe4U

call apex method with parameters from the lightning web component in salesforce - SalesforceGlobe4U

Solution:  pass list of parameters in JSON as an argument to a method as shown below

addNumbers({ 

n1 : this.number1,

n2 : this.number2

})


Example:

ApexClass:ApexMethodWithParameterController

public class ApexMethodWithParameterController {

    @AuraEnabled

    public static decimal addTwoNumbers(integer n1,integer n2) {

        decimal sum = n1+n2;

        return sum;

    }

}

apexMethodWithParametersInLWC.html:

<template>

    <lightning-card>

        <div style="padding-left:5px;padding-bottom:10px"><label>Enter Number 1 </label> <input type="number" value={number1} onchange={onNumberOneFieldChange}/></div>

        <div style="padding-left:5px;padding-bottom:10px"><label>Enter Number 2 </label> <input type="number" value={number2} onchange={onNumberTwoFieldChange}/></div>

        <div style="padding-left:5px;padding-bottom:10px"><label>Sum is </label> <output>{sum}</output></div>

        

        <div><input type="button" value="Calculate Sum" onclick={calculateSum}/></div>

    </lightning-card>

</template>

apexMethodWithParametersInLWC.js:

import { LightningElement ,track} from 'lwc';

import addNumbers from '@salesforce/apex/ApexMethodWithParameterController.addTwoNumbers';

export default class ApexMethodWithParametersInLWC extends LightningElement {

    @track sum;

    @track number1;

    @track number2;

    onNumberOneFieldChange(event) {

        this.number1 = event.target.value;

    }

    onNumberTwoFieldChange(event) {

        this.number2 = event.target.value;    

    }

    calculateSum() {

        addNumbers({ 

            n1 : this.number1,

            n2 :this.number2

        })

        .then(result => {

            console.log('hello');

            if(result){

                this.sum = result;

            }

        })

        .catch(error => {

            this.loader = false;

            this.error = error;

        });        

    }

}

apexMethodWithParametersInLWC.js-meta.xml:

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

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

    <apiVersion>54.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:



Tuesday, May 10, 2022

How to freeze a salesforce user using apex code - SalesforceGlobe4U

How to freeze a salesforce user using apex code - SalesforceGlobe4U

Solution: Update the IsFrozen field to true on UserLogin object to freeze the user.

Example: Run the following piece of code from Developer console

String salesforceUserId = '00590000001OPI9';//replace with salesforce user id

List<UserLogin> lstUserLogin = new List<UserLogin>();

lstUserLogin = [Select id,UserId,IsFrozen from UserLogin where UserId =:salesforceUserId];

if(!lstUserLogin.isEmpty()){

lstUserLogin[0].IsFrozen = true;

update lstUserLogin;

System.debug('Frozen User :'+ lstUserLogin[0].IsFrozen);

}

Output:




Saturday, May 7, 2022

How to fetch the deleted record in soql query - salesforceglobe4u

How to fetch the deleted record in soql query - salesforceglobe4u

Solution: Use the ALL ROWS keyword at the end of SOQL query to fetch deleted records as well as shown below

select id,name from Account where isdeleted=:true ALL ROWS

Example:

Run the following piece of code in execute anonymous window of Developer Console

List<Account> lstAccount = new List<Account>();

lstAccount = [select id,name from Account where isdeleted=:true ALL ROWS];

system.debug('Number of Accounts: '+lstAccount.size());

for(Account acc :lstAccount) {

system.debug('Account Name: '+acc.Name);

}

Output:

before deleting Nikhil Account you get 0 records in query


After deleting Nikhil Account


Single SOQL query to fetch account and its related contacts in salesforce - SalesforceGlobe4u

Single SOQL query to fetch account and its related contacts in salesforce - SalesforceGlobe4u 

Solution: Use the SOQL query as shown below

Select id,name,(select id,name from Contacts) from Account

Example: Run the following piece of code in execute anonymous window of Developer Console

List<Account> lstAccount = new List<Account>();

lstAccount = [Select id,name,(select id,name from contacts) from Account];

for(Account acc :lstAccount) {

system.debug('Account Name: '+acc.Name);

for(Contact con: acc.contacts) {

system.debug('Contact Name: '+con.Name);

}

}

Output:



Friday, May 6, 2022

How to retrieve apex triggers using package.xml in vs code salesforce - Salesforce Globe For You

How to retrieve apex triggers using package.xml in vs code salesforce - Salesforce Globe For You

Problem: Assume an apex trigger named 'AccountObjectTrigger' is written in salesforce.

Now we need to retrieve this trigger in vs code tool using package.xml

Solution: Use name as ApexTrigger and member as triggername as shown below.

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

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

<types>

<members>AccountObjectTrigger</members>

<name>ApexTrigger</name>

</types>

<version>53.0</version>

</Package>

Output: