Play Games

Search This Blog

Friday, December 13, 2024

Wednesday, December 4, 2024

How to get Salesforce Org limits in Apex


Solution:
Use the below code

List<System.OrgLimit> lstOrgLimits = OrgLimits.getAll();

for (System.OrgLimit objLimit : lstOrgLimits) {

    System.debug('Limit        : ' + objLimit.getName());

    System.debug('Current Limit: ' + objLimit.getValue());

    System.debug('Max Limit    : ' + objLimit.getLimit());

}

Output:

To get specific limit, for example file storage limit use the below code

System.OrgLimit objLimit = OrgLimits.getMap().get('FileStorageMB');

System.debug('Limit        : ' + objLimit.getName());

System.debug('Current Limit: ' + objLimit.getValue());

System.debug('Max Limit    : ' + objLimit.getLimit());

Output:



Top 10 Salesforce Youtube Channels that I follow


Below are the salesforce YouTube channels that I follow . Hope you do follow them and gain some knowledge.

1) Salesforce Developers https://www.youtube.com/@SalesforceDevs/videos

2) Salesforce Architects https://www.youtube.com/@SalesforceArchitects/videos

3) Apex Hours https://www.youtube.com/@apexhours

4) Samarth Ahuja Tech Videos https://www.youtube.com/@samCoder

5) Salesforce Techbook https://www.youtube.com/@salesforcetechbook

6) Salesforce https://www.youtube.com/@salesforce

7) Path to code https://www.youtube.com/@PathtoCode

8) Salesforce Hulk https://www.youtube.com/@SalesforceHulk

9) Salesforce Codex https://www.youtube.com/@SalesforceCodex

10) Salesforce Ben https://www.youtube.com/@OfficialSFBen

Wednesday, May 1, 2024

How to enforce field level security in SOQL Query salesforce - Salesforce Globe 4U

Solution: There are 2 ways to enforce FLS in SOQL query

1)Using USER_MODE 

2)WITH SECURITY_ENFORCED clause

Using USER_MODE:

Example: run the below code in execute anonymous window 

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

lstAccount = [Select id,name from Account with USER_MODE];

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

SELECT Id,name from Account with USER_MODE

Output:



Using WITH SECURITY_ENFORCED clause:

Example: run the below code in execute anonymous window 

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

lstAccount = [Select id,name from Account with SECURITY_ENFORCED];

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


Note: Salesforce recommends using the USER_MODE than WITH SECURITY_ENFORCED as it has additional advantages

1) USER_MODE accounts for polymorphic fields as well where as SECURITY_ENFORCED donot account for it.

2)USER_MODE returns all the FLS errors where as SECURITY_ENFORCED returns only the first.

Refer to the salesforce link for more details

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_enforce_usermode.htm

How to query the validation rules of an object in salesforce - Salesforce Globe 4u

Solution: Using tooling api ,the validation rules can be queried.

Example: Use the following query in developer console by enabling the tooling api

SELECT Id, Active, Description, EntityDefinition.QualifiedApiName, ErrorDisplayField, ErrorMessage,ValidationName FROM ValidationRule

Output:



To filter validation rules for a specific object, use EntityDefinition.QualifiedApiName(object api name) in where clause of query 

Example:

SELECT Id, Active, Description, EntityDefinition.QualifiedApiName, ErrorDisplayField, ErrorMessage,ValidationName FROM ValidationRule where EntityDefinition.QualifiedAPiName='A__c'

Output:



Monday, April 22, 2024

How to access custom labels in lightning web component salesforce - Salesforce Globe 4u

 Solution: 

Step1: Import the label in LWC using the below import 

import labelname from "@salesforce/label/labelreference";

Step2: create label object as below 

label ={

        myblogURL

    }

Reference the custom label in html file using label.labelname.

Example:



customLabelInLWC.html:

<template>

    <lightning-card>

        <h1> Custom Label value :{label.myblogURL}</h1>

    </lightning-card>

</template>

customLabelInLWC.js:

import { LightningElement } from 'lwc';

import myblogURL from "@salesforce/label/c.Blog_URL";

export default class CustomLabelInLWC extends LightningElement {

    label ={

        myblogURL

    }

}

customLabelInLWC.js-meta.xml:

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

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

    <apiVersion>59.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__AppPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:



Notes related list is missing in record detail page to capture notes in salesforce - Salesforce Globe 4u

Solution: Need to enable notes feature in order to add notes related list

Step1: we need to enable notes feature first.

Go to setup --> Feature Settings --> Sales --> Notes Settings --> enable the 'Enable Notes' checkbox.

Step 2: Add the Notes related list to the respective page layout 

That's it. You will be able to see Notes related list to add new notes.




Enjoy learning salesforce.

How to get the count of number of custom objects in salesforce org - Salesforce Globe 4u

There are 2 ways to know this.

Solution1: Login into the org and Go to the setup --> System Overview.

Here you will find the required details.

Solution2: Run the piece of code in execute anonymous windows of Developer console

Map<String, SObjectType> sObjects = Schema.getGlobalDescribe();

Integer noOfCustomObjects = 0;

for (SObjectType obj : sObjects.values())

{

    if(obj.getDescribe().isCustom() == true) {

        noOfCustomObjects = noOfCustomObjects+1;

        //system.debug(obj.getDescribe().getName());

    }

}

System.debug('Number of Custom Objects: '+noOfCustomObjects);

Output:



Saturday, April 20, 2024

Lightning Messaging Service example in salesforcelightning web component

 Lightning Messaging Service: It is used to communicate between the visualforce pages, aura components and Lightning web Components. It can be used to communicate between one aura component and one Lightning web component as well and also between one visualforce page and one aura component as well.

Example: In this example you can see how a message is communicated from one lightning web component to other lightning web component
Step 1: Create a lightning messaging channel: Go to visual studio code tool and create 'messageChannels' folder inside the default folder as shown in image below


create a file as 'filename.messageChannel-meta.xml' shown in the image below and deploy to salesforce org.




Step 2: Create publisher lightning web component(source)
publisherLWCComponent.html:
<template>
<lightning-card>
<div class="slds-grid">
<lightning-button label="Publish" variant="brand" onclick={sendMessage}></lightning-button>
</div>
</lightning-card>
</template>

publisherLWCComponent.js:
import { LightningElement } from 'lwc';
import { createMessageContext, releaseMessageContext,publish} from 'lightning/messageService';
import msg from "@salesforce/messageChannel/TestMessageChannel__c";
export default class PublisherLWCComponent extends LightningElement {
context = createMessageContext();
sendMessage() {
const msgTosend = {
paramOne: 'This is message to be sent to other LWC'
}
publish(this.context, msg, msgTosend);
};
}

publisherLWCComponent.js-meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>

Step3: Create Subscriber Lightning web component(destimation):
subscriberLWCComponent.html:
<template>
<lightning-card>
Message Received: {msgReceived}
</lightning-card>
</template>

subscriberLWCComponent.js:
import { LightningElement,track } from 'lwc';
import { createMessageContext, releaseMessageContext,APPLICATION_SCOPE,subscribe, unsubscribe } from 'lightning/messageService';
import msg from "@salesforce/messageChannel/TestMessageChannel__c";
export default class SubscriberLWCComponent extends LightningElement {
context = createMessageContext();
@track msgReceived ='';
connectedCallback(){
subscribe(this.context, msg, (message) => {
this.msgReceived = message.paramOne;
},{scope: APPLICATION_SCOPE});

}
}
subscriberLWCComponent.js-meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
Output:






Wednesday, March 6, 2024

how to check the version of visual studio code IDE

 Solution: Open the visual studio code and go to help and About as shown in the image.

A popup will show the required details.



How to install previous or older version of extension in visual studio code IDE

 Solution: In this example, will show by installing the salesforce extension pack

Open visual studio code and then go to the extensions icon as shown in image below and search for salesforce extension pack.

Right click on particular extension, then you will get an option to install other versions as shown in image.


Select any version from this and install.


Note: In case if your not getting option to show other versions, install and then try again to change to other version by following above steps.