Hyperlink field to open Visualforce page from related list in Salesforce?

Sample Code:

Visualforce page:

<apex:page controller="Sample" tabStyle="Account">
<apex:form >
<apex:pageMessages />
    <apex:pageBlock id="pg">
        <apex:pageBlockSection columns="1">
            <apex:outputField value="{!con.FirstName}"/>
            <apex:outputField value="{!con.LastName}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

</apex:page>

Apex Class:

public class Sample {
    public Contact con {get;set;}
    Id conId {get;set;}
    
    public Sample() {
        conId = ApexPages.currentPage().getParameters().get('conId');
        con = [SELECT FirstName, LastName FROM Contact WHERE Id =: conId];
    }

}

Field:



Output:





Cheers!!!

What is the difference between outputfield and outputtext?

apex:outputText: Displays text on a Visualforce page.

apex:outputField: A read-only display of a label and value for a field on a Salesforce object.

Sample Code:

Visualforce Page:

<apex:page controller="Sample" tabStyle="Account">
<apex:form >
<apex:pageMessages />
    <apex:pageBlock id="pg">
        <apex:pageBlockSection columns="1">
            <apex:outputText >Sample Output Text</apex:outputText>
            <apex:outputField value="{!acct.Name}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

</apex:page>

Apex Class:

public class Sample {
    public Account acct {get;set;}
    
    public Sample() {
       acct = [SELECT Name, Industry FROM Account LIMIT 1];
    }
}

Output:


Cheers!!!

Line Break in Formula Field in Salesforce

Sample Formula Field:

IF( CONTAINS(Name, 'test'),
'Test' & BR() &  'Account',
'Not a Test Account'
)



Sample Output:


Cheers!!!

Query to get class name from Batch job

Sample SOQL:

SELECT Id, Status, MethodName, ApexClass.Name FROM AsyncApexJob 

Cheers!!!

How to find the number of Permission Set assigned to an user in Salesforce?

Sample Code:

Map<Id, List<PermissionSetAssignment>> mapUserIdPermAssignList = new Map<Id, List<PermissionSetAssignment>>();
List<PermissionSetAssignment> listPermAssign = [SELECT AssigneeId, PermissionSetId FROM PermissionSetAssignment];

for(PermissionSetAssignment PA : listPermAssign) {
if(!mapUserIdPermAssignList.containsKey()) {
mapUserIdPermAssignList.put(PA.AssigneeId, new List<PermissionSetAssignment>());
}
mapUserIdPermAssignList.get(PA.AssigneeId).add(PA);
}

here mapUserIdPermAssignList contains User Id and their related list of Permission Set.

Cheers!!!

Email Masking in Salesforce

Email Masking is nothing but appending some text to emails.

Whenever we refresh the Sandbox from the Production, in order to avoid sending emails, some text is appended to the email.

Cheers!!!

How many parallel sessions are allowed per user in Salesforce?

The parallel sessions in Salesforce depends upon the purpose. The purpose may be for API call or Integration call or Data loading call.

Please refer the below link for more information,

https://www.salesforce.com/developer/docs/api/Content/implementation_considerations.htm

The limit depends upon the Salesforce edition we are using.

Cheers!!!

Export Details button on Salesforce Report

You can export up to 256 columns and 65,536 rows of data in one report.

If the columns decreases, rows will be increased.


Cheers!!!

How to write test code coverage for private methods in Salesforce?

TestVisible annotation allow test methods to access private or protected members of another class outside the test class. These members include methods, member variables, and inner classes.

Sample Class:

public class TestVisibleExample {
    // Private member variable
    @TestVisible private static Integer recordNumber = 1;

    // Private method
    @TestVisible private static void updateRec() {
    }
}  

Test Class:

@isTest
private class TestVisibleExampleTest {
    @isTest static void test1() {
        // Accessing private variable annotated with TestVisible
        Integer i = TestVisibleExample.recordNumber;
        System.assertEquals(1, i);

        // Accessing private method annotated with TestVisible
        TestVisibleExample.updateRecord();
    }
}

Cheers!!!