Monday, April 3, 2023

What are Remote Site Settings in Salesforce

Salesforce allows you to access external website resources from a Salesforce application for your organization. You can access these external websites through Visualforce pages, Apex Callout, and via XmlHttpRequest calls. To avoid accessing malicious websites from Salesforce.com, the website first needs to be registered with remote site settings. Once the site is registered, it can be used within Salesforce.com. 

To Setup the Remote Site Setting 

  • search and click remote site settings in setup.site
  • Click on New Remote Site and enter the URL and other fields required.
  • Click Save.

Please find the description of the fields in remote site settings

site

Let me know your thoughts in the comment section!!

Friday, March 31, 2023

Wrapper Class in Salesforce

Wrapper Class in Apex Salesforce

In simple words, a wrapper class is a class inside a class. It is also known as a container class. It stores a group of similar or different data type variables into a single object.

Lets understand with an example:


public class ExampleCls {
    public class WrapperCls{
        public Boolean selected { getset;}
        public String record  { getset;}
        
    }
}

In this example, ExampleCls is the main class and
WrapperCls is the wrapper or the inner class.

This wrapper class contains two different data types,
one Boolean and other one is String

Use of Wrapper Class:

  1. It helps to stores a group of similar or different data type variables into a single object.
  2. We can use a wrapper class in Lightning Component when we need to send group of data from apex to lightning components.
  3. We can use Wrapper classes to parse the JSON request and response in REST API.

Wednesday, March 29, 2023

How to Check Custom Setting is List or Hierarchy in Apex

Today, we will learn how we can check whether the given custom setting is List of Hierarchy.

To Understand custom settings click here.

Apex Code:

String api = 'customSettingName__c';
Type reflector = Type.forName(api);
SObject sobj=(SObject)reflector.newInstance();
DescribeSObjectResult sobjResult = 
sobj.getSObjectType().getDescribe();
//some Name field info
SObjectField field = 
sobjResult.Fields.getMap().get('Name');
DescribeFieldResult fieldResult = 
field.getDescribe();
Integer length = fieldResult.getLength();
system.debug('length-'+length);

If length is 38 that means it is list, if length is 80 that means it is hierarchy


Please share your thoughts on this if there is any other way to do so.

Monday, March 27, 2023

What are Custom Settings in Salesforce

In Salesforce, custom settings are application metadata that offers a reusable set of static data that different departments in your company can access. 

Custom settings are classified into two types: 

  • Hierarchy Custom Settings
  • List Custom Settings 

The data in Hierarchy Custom Settings checks the organization, profile and user settings for the current user and makes the data visible for them accordingly. It uses a built-in hierarchical logic which lets you personalize settings for a specific user or a profile.

The data in List Custom Settings is directly visible to any user in the org. It provides a reusable set of static data which can be accessed across your organization.

Custom settings can be used to store a variety of data, such as configuration settings, feature switches, and business rules. They can be accessed using validation rules, workflows, Apex code, Lightning components, and the Salesforce API.


Advantages of Custom Settings

The main advantage of using Custom Settings is that the data is cached, which enables efficient access without the cost of repeated queries to the database. One doesn’t have to use SOQL queries which count against the governor limits.

Sunday, March 26, 2023

How to Hide a Div Tag Like a Toast Message in Lightning Web Components

Lets understand how we can hide a div like a toast message.

HTML File:

<div data-id="overview" class="red-bg">
  <lightning-formatted-text value={errorMsg}>
</lightning-formatted-text>
</div>

In this HTML file, we are creating a div element and will set a data-id

Data-id value will be used in the JS file to show or hide the div.

Js File:

We can call this hidemsg() method from the success of a server call.

This above div tag will be hidden after 5 secs

hidemsg(){
 setTimeout(() => {
this.template.querySelector('[data-id="overview"]').style.display 
='none';
  }, "5000")
}

When this hidemsg() is called, we can add setTimeout()

method will put a delay.

Mostly Viewed