How to convert sObject to JSON String and JSON string to sObject using apex in Salesforce?

Sample Code:

Contact con = new Contact(FirstName = 'First', LastName = 'Last', Phone = '9999999999', Email = '');
/* Code to convert Contact to JSON string */
String strJSON = JSON.serialize(con);
system.debug('JSON String is ' + strJSON);
/* Code to conver JSON string to Contact */
Contact con1 = (Contact)JSON.deserialize(strJSON, Contact.Class);
system.debug('Contact is ' + con1);



How to hide lines and borders in pageBlock tag in Visualforce?

Sample Code:

Visualforce page:

<apex:page standardController="Account" sidebar="false">
    .bPageBlock .pbBody .dataCol {
    .bPageBlock .pbBody .labelCol {
    <apex:form >
        <apex:pageBlock mode="maindetail"  >
            <apex:pageBlockSection columns="2" >
                <apex:inputField value="{!Account.Name}"/>
                <apex:inputField value="{!Account.Industry}"/>
                <apex:inputField value="{!Account.Description}"/>
                <apex:inputField value="{!Account.Phone}"/>
                <apex:inputField value="{!Account.Rating}"/>
                <apex:inputField value="{!Account.Fax}"/>
                <apex:inputField value="{!Account.Type}"/>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>



Approval Post Templates in Salesforce

Approval post templates allow you to customize the content of approval request posts in an assigned approver's feed. Approval request posts are not private. Anyone with access to the approval object can view and comment on an approval request post.

1. Go to Chatter Settings.

2. Enable Allow Approvals through Chatter.

3. Create Approval Process.

4. Go to Post Templates.

5. Create a Post Templates.

6. Select Post Template created in the Approval Process.

7. Post Template feed will be looking like below.


How to set debug log for Community Guest User?

1. Go to Domains.

2. Select the URL of Community

3. Select the Community.

4. Click Public Access Settings button.

5. Click Assigned Users. Get the username.

6. Go to Debug Logs.

7. Click New and select the user.

8. If you are in chrome execute the below command in the console.


9. You will start seeing debug logs for the community guest user.


How to dynamically determine Calling Context using Apex in Salesforce?

Batch - System.isBatch()
@future - System.isFuture()
Queueable - System.isQueueable()
Schedulable - System.isScheduled()
Trigger - Trigger.isExecuting

Visualforce - ApexPages.currentPage() != null
Apex REST - RestContext.request != null

Sample code to execute in Developer Console

system.debug('Batch is ' + System.isBatch());
system.debug('@future is ' + System.isFuture());
system.debug('Queueable is ' + System.isQueueable());
system.debug('Schedulable is ' + System.isScheduled());
system.debug('Trigger is ' + Trigger.isExecuting);
system.debug('Visualforce is ' + ApexPages.currentPage());
system.debug('Apex REST is ' + RestContext.request);