Search This Blog

Saturday, October 22, 2022

Get salesforce free trail development environment

In order to learn and practise salesforce concepts,we need the development environment org instance.

For any trail environment,go to the https://developer.salesforce.com/free-trials and then you can sign up for you respective environment.

The following free trial environment orgs are available

1) Salesforce Developer Edition

2) CRM Analytics Free trail

3) Mulesoft free trail

4) Tableau free trail

5) slack free tier

6) Quip free trail

7) Financial Service clouds free trails

8) Health cloud free trails

9) Manufacturing  cloud free trails

10) Consumer goods cloud free trails

11) Salesforce Schedular free trails

12) Loyalty Management free trail

13) Net Zero cloud free trails

14) Public sector cloud free trail etc.

In one place i.e https://developer.salesforce.com/free-trials#browse,you will be able to find all free trail environments that you can register and start using.

Friday, October 7, 2022

How to create salesforce org that supports salesforce cpq functionality to learn salesforce CPQ

Solution: Create the org that supports cpq by filling the form in the following link

https://trailhead.salesforce.com/promo/orgs/cpqtrails

Finish the salesforce cpq Admin fundamentails trial to learn the basic of salesforce CPQ.

Link: https://trailhead.salesforce.com/content/learn/trails/cpq-admin

Thursday, September 22, 2022

Install Java and setup java path

Step 1: Download the java from the link 

https://www.oracle.com/java/technologies/downloads/

Downloaded x64 for windows.

Step 2: Install java by double clicking the file downloaded.

Step 3:Setup java path

Open the folder where java is installed and copy the url till bin folder.

Go through the image for reference.

C:\Program Files\Java\jdk-19\bin

Now right click on Computer --> properties --> Advanced system settings --> Environment Variables --> new -->

Enter variable name as "JAVA_HOME" and in variable value, paste the java url which you copied. and then click ok.

Now open the command prompt and run javac command.If you get below response,then it means that you have set java path correctly.



Thursday, September 15, 2022

difference() of String class in apex Salesforce

 The difference() returns the difference between the current String and the specified String.

Example:

String str1 = 'Hello Suresh';

String str2 = 'Hello Mahesh';

String difference = str1.difference(str2);

system.debug('Difference : '+difference);

Output:

Note: It's case sensitive.

Query profile in Salesforce - Salesforce Globe For You

Solution: Use the below query to fetch profile in salesforce

SELECT name,UserType,Description from Profile

Output:



Query custom labels in Salesforce - Salesforce Globe For You

Solution: Use the below query by making sure tooling API is enabled

SELECT name,value from ExternalString

Output:



Wednesday, September 14, 2022

Query to fetch the apex class in salesforce - Salesforce Globe For You

Solution: Use the below SOQL query to fetch the apex classes

select Name,status,LengthWithoutComments,Body,APiversion,createddate from ApexClass

Output:



Friday, September 2, 2022

System.SObjectException: SObject row was retrieved via SOQL without querying the requested field salesforce

Problem: This error generally occurs when you are using a field in the logic without quering that field in its related SOQL query.

Example:

Account a = [Select id,name from Account limit 1];

if(a != null) {

    if(a.rating =='Cold') {

        System.debug('Rating is Cold');

    }  

}

In the above code, line 3 rating field is referred but it's not queried in the soql query at line 1.

Updated Code:

Account a = [Select id,name,rating from Account limit 1];

if(a != null) {

    if(a.rating =='Cold') {

        System.debug('Rating is Cold');

    }  

}

Output:



Reverse a string in apex salesforce

Solution: Use reverse() to reverse a given string

Example:

String blog ='Salesforce Globe For You';

System.debug('Reverse :'+blog.reverse());

Output:



Get salesforce instance name

Solution: Use the following query on Organization object to get the instance name

select instancename from Organization

Output:



Get salesforce OrganizationType

Solution: Use the following SOQL on the organization object to know the organization type.

select organizationtype from Organization

Output:



Friday, August 19, 2022

formula to calculate days between two dates in salesforce - Salesforce lobe For You

Solution: If both dates are of date datatype,then directly subtract start date from end date field to get the number of days between 2 dates.

Example: Start Date and End Date are date fields on Lead Object.



The formula field (No.of days) will be like this 

Output:


If both are of datetime datatype fields,then also directly subtract start date time from end date time field to get the number of days between 2 dates.

Example: Start Date and time and End Date and Time are date time fields on Lead Object.



The formula field (No.of days) will be like this 

Output:



query to filter records based on multiselect picklist values in apex salesforce - Salesforce Globe For You

Solution: Use includes in query to filter based on multiselect picklist field with values separated by comma(,) or semicolon (;)

Use semicolon(;) to specify AND operation. Example ('A;B') means record where A and B values are selected.

Use comma (,) to specify OR operation.Example ('A','B') means record where A or B are selected.

Assume Alphabet is a multi select picklist field created on Lead object with values from A to Z 

SOQL query to fetch lead records where A and B multiselect picklist values are selected 

Select id,name from Lead where Alphabet__c includes ('A;B')

Output:

SOQL query to fetch lead records where A or B or both multiselect picklist values are selected 

Select id,name,Alphabet__c from Lead where Alphabet__c includes ('A','B')

Output:



Thursday, August 18, 2022

Trigger.operationType in salesforce - Salesforce Globe For You

OperationType is a Trigger class context variable which returns an enum of type System.TriggerOperation corresponding to the current operation.

Possible values of the System.TriggerOperation enum are: 

BEFORE_INSERT

BEFORE_UPDATE

BEFORE_DELETE

AFTER_INSERT

AFTER_UPDATE

AFTER_DELETE and 

AFTER_UNDELETE.

Trigger.operationType is used in trigger to determine the type of operation whether it is before insert or before update etc.

Example:

trigger LeadTrigger on Lead ( before Insert ,Before Update , After Insert, After Update) {

    system.debug('Trigger.OperationType :' +Trigger.OperationType);

}

Now when I update any one lead record ,the output is as shown below


It means when the lead record is updated, the lead trigger runs and the Trigger.OperationType tells that the trigger is running for the before update and after update context.

Monday, August 8, 2022

Rename salesforce trailhead palyground org - SalesforceGlobe4U

Solution: Login to Salesforce trailhead account and navigate to bottom of the screen where the launch section is visible as shown below

click on 3 dots and click on manage Orgs link


It will navigate to the connected orgs screen as shown below


click rename to rename specific org and save.

Display prime numbers with in the range

Solution: A prime number is a number that is only divisible by 1 and itself.

Example: 2, 3, 5, 7, 11 etc are prime numbers

Example:

Apex class:

public class PrimeNumberController {

    public static void displayPrimeNumbers(Integer startingNumber,Integer endNumber) {

        List<Integer> lstPrimeNumber = new List<Integer>();

        for(integer i= startingNumber ; i<=endNumber ; i++) {

            if(checkPrimeNumber(i) == true) {

                lstPrimeNumber.add(i);

            }

        }

        System.debug('The Prime Numbers are: '+lstPrimeNumber);

    }

    public static Boolean checkPrimeNumber(integer num) {

        Boolean isPrimeNumber = true;

        if(num <2) {

            isPrimeNumber = false;

        } else {

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

                integer m = math.mod(num,i);

                if(math.mod(num,i) == 0) {

                    isPrimeNumber = false;

                }

            }

        }

        return isPrimeNumber;

    }

}

Run the following from developer console

PrimeNumberController.displayPrimeNumbers(40,50);

Output:



Wednesday, August 3, 2022

Pass current page record id to wire method in Lightning Web Component - Salesforce Globe For You

Solution: @api recordId property will fetch the record id from the detail record page where this component is placed.

Use '$recordId' to pass current page record id to wire method inside the js file.

Example:

passRecordIdToWireInLWC.html:

<template>

    <lightning-card title="Get Related List Contact Records">

        <template if:true={records}>

            <div class="slds-m-around_medium">

                <template for:each={records} for:item="rec">

                    <p key={rec.fields.Id.value}>

                        {rec.fields.Name.value}

                    </p>

                </template>

            </div>

        </template>

    </lightning-card>

</template>

passRecordIdToWireInLWC.js:

import { LightningElement, wire ,api } from 'lwc';

import { getRelatedListRecords } from 'lightning/uiRelatedListApi';

export default class PassRecordIdToWireInLWC extends LightningElement {

    @api recordId;

    error;

    records;

    @wire(getRelatedListRecords, {

        parentRecordId: '$recordId',

        relatedListId: 'Contacts',

        fields: ['Contact.Id','Contact.Name']

    })listInfo({ error, data }) {

        if (data) {

            this.records = data.records;

            this.error = undefined;

        } else if (error) {

            this.error = error;

            this.records = undefined;

        }

    }

}

passRecordIdToWireInLWC.js-meta.xml:

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

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

    <apiVersion>55.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__RecordPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:



Wednesday, July 20, 2022

How to align label and value to appear in same line(single line) in standard lightning record page salesforce - SalesforceGlobe4U

Solution: If you set the Density settings as compact, the label and value in record page will appear in same line

Go to Setup --> User Interface --> Density Settings -->Compact


The alignment of field label and value will look like this


If you want to display label on top and value below in record page, set the Density setting as Comfy




Tuesday, July 19, 2022

Code Builder Salesforce - Salesforce Globe For You

Code Builder is a salesforce IDE(Integrated Development Environment) which can be accessed directly from web browser itself.

We can use this Salesforce Code Builder IDE to do salesforce development similar to Visual studio code.

Setup of Code Builder: 

Step 1: Go to the Code Builder(Beta) in the app exchange or click the link below

https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3u00000Qsdi5EAB and install the package in your org.

Step 2: To give access to code builder for a specific user, code builder permission set needs to be assigned to that user.


Step 3: To access Code Builder IDE, go to the Code Builder (Beta) app from the app manager as shown in the image below


Step 4: connect to the org and start exploring the code Builder.

Note: Code Builder is in Open Beta as of now.

How to load currency exchange rates in salesforce - Salesforce Globe For You

Solution: load the currency exchange rates records into DatedConversionRate object using Data loader.


Step 1: Prepare the CSV file as shown in the image 

insert the data using data loader

Output: The currency exchange rates are loaded as shown below



Monday, July 11, 2022

Convert list into map in salesforce - Salesforce Globe For You

Solution: In order to convert list into map in salesforce, iterate the list and use the map.get() and map.put() to prepare the map

Example: In this example we will create map with AccountId as key and value as list of contacts by iterating the list of contacts

Map<String,List<contact>> mapAccountWithContacts = new Map<String,List<Contact>>();

for(contact objContact :[Select id,name,accountId from contact where accountId != null]) {

if(mapAccountWithContacts.containsKey(objContact.accountId)) {

mapAccountWithContacts.get(objContact.accountId).add(objContact);

} else {

mapAccountWithContacts.put(objContact.accountId,new List<Contact>{objContact});

}

}

system.debug('Map :'+mapAccountWithContacts);

Output:



Thursday, July 7, 2022

How to change the datatype of standard name field in a custom object to auto number in salesforce - Salesforce Globe For You

Solution: In order to convert name field's datatype  to datatype auto number in salesforce, Go to the name field and click on Edit. In this example we are going to change the datatype of name field of Award__c custom object


change the data type to auto number, enter format, starting number as shown in the image below and save it.


That's it.

Output:



Assign permission sets to multiple users quickly in salesforce - Salesforce Globe For You

Solution: In order to assign permission sets to multiple users in salesforce, One of the solution is to use Data Loader to assign permission sets to users.

Below are the 2 permission sets to be assigned to users

Rating with id 0PS90000001oCOX

Testing with id 0PS900000018xJ7




PermissionSetAssignment is the standard salesforce object which represents the relationship between a user and a permissionset.

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_permissionsetassignment.htm

Create a csv file as shown below


If 3 permissionsets needs to be assigned to a user,then 3 rows to be inserted for 1 user with 1 permissionset in each row.

Using Dataloader ,insert the data into the PermissionSetAssignment object.

Output: