Apex Exception Email in Salesforce

Set the email addresses that receive notifications when your Apex code encounters unhandled exceptions. Emails can be sent to your Salesforce org’s users and to external email addresses.

Salesforce sends two types of notification mails when potential issues with APEX code are detected:

APEX warning mails, which are sent when a class or trigger exceeds 50% of an APEX governor limit
APEX exception mails, which are sent when an unhandled exception occurs in a trigger or class

1. Go to Email --> Apex Exception Email.


2. Click Add Salesforce user to add user to start receiving exception or add External Address in Email Addresses Not in Salesforce section.


defaultTokens Lightning Token in Salesforce

defaultTokens.tokens

<aura:tokens>

    <aura:token name="brandedFont" value="#9400d3"/>

</aura:tokens>

Component:

<aura:component implements="force:appHostable">
   
    <div class="slds-box slds-theme_default">
       
        <p>
           
            Testing
           
        </p>
       
    </div>
   
</aura:component>

CSS:

.THIS p {
   
    color: token(brandedFont);
   
}

Output:


Salesforce Interview Questions with Answers Part 52

1. Record type restrictions.

If the user profile doesn't have access to a record type and if they have View all permission, then they will be able to view the record.
If the user profile doesn't have access to a record type and if OWD of the object is Public Read or Public Read/Write, they will be able to view the record.
If the user profile doesn't have access to a record type and if the record is shared through manual sharing or sharing rules, they will be able to view the record.

Record type is usually used for different page layout and picklist values.

2. Channel Manager Role

Channel managers are internal users who manage your partner accounts and partner users. Before setting up a partner community, identify an internal user to play the channel manager role.
Available in: Salesforce Classic and Lightning Experience
Available in: Enterprise, Performance, Unlimited, and Developer Editions

Ideally, channel managers should create all the partner accounts for the partner organizations they manage. All partner users associated with a partner account automatically fall below the channel manager in the partner role hierarchy. So all the data owned by those partner users rolls up and is visible to the channel manager.

3. Moderate Chatter Free Users

A moderator is a Chatter user with some additional privileges.

These privileges include:
Activate or deactivate Chatter Free users
Assign a Chatter Free user as moderator or take the privilege away
Delete posts and comments that they can see

http://www.infallibletechie.com/2018/04/moderate-chatter-free-users-in.html

4. How to tackle technical debt in Salesforce?

Technical debt (also known as design debt or code debt) is a concept in software development that reflects the implied cost of additional rework caused by choosing an easy solution now instead of using a better approach that would take longer.

http://www.infallibletechie.com/2018/04/how-to-tackle-technical-debt-in.html

5. Continuation Class Example in Salesforce

Use the Continuation class to make callouts asynchronously to a SOAP or REST Web service. It can be used only from a Visualforce page and helps us to avoid Concurrent Apex limit for long running callouts.

http://www.infallibletechie.com/2018/04/continuation-class-example-in-salesforce.html

6. Difference between lightning:input and ui:input in Lightning in Salesforce

lightning:input
Base Lightning components are the building blocks that make up the modern Lightning Experience, Salesforce1, and Lightning Communities user interfaces.
Beyond being equipped with the Lightning Design System styling, they handle accessibility, real-time interaction, and enhanced error messages.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/lightning_overview.htm

ui:input
Lightning Design System styling is not applied by default.

7. Difference between component.find() component.get() in Salesforce Lightning

Component.get()

component.get(String key) and component.set(String key, Object value) retrieves and assigns values associated with the specified key on the component. Keys are passed in as an expression, which represents attribute values.

component.find()

find() returns different types depending on the result.

1. If the local ID is unique, find() returns the component.
2. If there are multiple components with the same local ID, find() returns an array of the components.
3. If there is no matching local ID, find() returns undefined.

component.find() works in a more broader way whereas component.get() is associated with attributes. find() method can be used to work on tags having same id's simultaneously.

8. What happens if time-dependent actions sets the trigger date to past date in Salesforce?

If Salesforce recalculates the time triggers to a date in the past, Salesforce triggers the associated actions shortly after you save the record.

9. Can users create apex triggers on Knowledgebase article object?

Unlike other standard or custom objects that allows user to create triggers, this featured is not enabled for Knowledgebase object.

10. Rich Publisher Apps platform

The Rich Publisher Apps platform gives you all the necessary tools for creating and integrating interactive apps into your feed’s publisher.

Sample Code - http://www.infallibletechie.com/2018/08/rich-publisher-apps-platform.html

11. What is the use of selectedRows in lightning:dataTable?

selectedRows list global Enables programmatic row selection with a list of keyField values.

Rich Publisher Apps platform

The Rich Publisher Apps platform gives you all the necessary tools for creating and integrating interactive apps into your feed’s publisher.

There are three ways to add a Rich Publisher App to your community.

1. Get it from AppExchange.

2. Build a custom app in your org.

3. Port an app through change sets or packages.

Creating Rich Publisher App:

1. Create the below Lightning Components.

Composer Component:

<aura:component implements="lightning:availableForChatterExtensionComposer">
    
    <aura:attribute name="options" type="List" default="[
    {'label': 'Thank You', 'value': 'Thank You'},
    {'label': 'Amazing Work', 'value': 'Amazing Work'}
    ]"/>
    <aura:attribute name="selectedVal" type="String"/>
    
    <lightning:radioGroup label="Radio Button Group"
                          options="{! v.options }"
                          value="{! v.selectedVal }"
                          onchange="{!c.appreciate}"/>
    
</aura:component>

Composer Component Contrller:

({
    
appreciate: function(cmp, event, helper) {
        var compEvent = cmp.getEvent("sendChatterExtensionPayload");
        var selectedValObj = {value : cmp.get("v.selectedVal")};
        compEvent.setParams({
            "payload" : selectedValObj,
            "extensionTitle" : "Apprecication",
            "extensionDescription" : "Appreciation"
        });
        compEvent.fire(); 
    }
    
})

Renderer Component:

<aura:component implements="lightning:availableForChatterExtensionRenderer">
    
    {!v.payload.value}
    
</aura:component>

2. Go to Chatter Tab.Upload an icon to refer. In my example I have used Appreciation icon.

3. Get the File Id.

4. Go to https://workbench.developerforce.com/login.php and log in.

5. Go to Utilities --> REST Explorer.

6. Do a POST request with the below URL and body as {}.

/services/data/v43.0/connect/files/069f40000017eed/asset

069f40000017eed is the file id from step 3.

7. Get the fileAsset id.


8. Go to Data --> Insert.

9. Select ChatterExtension. Select Single Record. Click Next button.


10. Enter the values as below and click Confirm Insert.


Adding Rich Publisher App to Community:

1. Go to All Communities.

2. Select the Community for which you want Rich Publisher Apps.

3. Select Administration.

4. Click Rich Publisher Apps.


5. Select the apps and save.


Output:





Adding View All button in lightning:datatable

Sample Code:

Component:

<aura:component implements="force:appHostable"
    controller="AccountListController">
                
    <aura:attribute type="Account[]" name="acctList"/>
    <aura:attribute name="mycolumns" type="List"/>
    <aura:attribute name="viewAllBool" type="Boolean" default="true"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    
    <div class="slds-box slds-theme_default">
        
        <lightning:datatable data="{! v.acctList }" 
                             columns="{! v.mycolumns }" 
                             keyField="id"
                             hideCheckboxColumn="true"/>
        
        <br/>
        
        <aura:if isTrue="{!v.viewAllBool}">
            
            <div>
                
                <center><lightning:button label="View All" title="Neutral action" onclick="{! c.loadAll }"/></center>
                
            </div>
            
        </aura:if>
        
    </div>
    
</aura:component>

Controller:

({
    
    init : function(component, event, helper) {
        
        component.set('v.mycolumns', [
            {label: 'Account Name', fieldName: 'linkName', type: 'url', 
            typeAttributes: {label: { fieldName: 'Name' }, target: '_blank'}},
            {label: 'Industry', fieldName: 'Industry', type: 'text'},
            {label: 'Type', fieldName: 'Type', type: 'Text'}
        ]);
        
        helper.fetchAccounts(component, event, 3);
        
    },
    loadAll : function(component, event, helper) {
        
        component.set("v.viewAllBool", false);
        helper.fetchAccounts(component, event, 100);
        
    }

})

Helper:

({
    
fetchAccounts : function(component, event, intLimit) {

        var action = component.get("c.fetchAccts");
        action.setParams({
            
            "intLimit" : intLimit
            
        });
        
        action.setCallback(this, function(response) {
            
            var state = response.getState();
            
            if (state === "SUCCESS") {
                
                var records = response.getReturnValue();
                records.forEach(function(record){
                    record.linkName = '/'+record.Id;
                });   
                
                component.set("v.acctList", records);
                
            }            
            
        });
        
        $A.enqueueAction(action);
        
}
    
})

Apex Class:

public class AccountListController {
    
    @AuraEnabled
    public static List < Account > fetchAccts(Integer intLimit) {
        
        return [ SELECT Id, Name, Industry, Type FROM Account LIMIT : Integer.valueOf(intLimit) ];
        
    }
    
}

Output:


How to Hyperlink a Record in lightning:datatable?

Sample Code:

Component:

<aura:component implements="force:appHostable"
    controller="AccountListController">
                
    <aura:attribute type="Account[]" name="acctList"/>
    <aura:attribute name="mycolumns" type="List"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.fetchAccounts}"/>
    
    <lightning:datatable data="{! v.acctList }" 
                         columns="{! v.mycolumns }" 
                         keyField="id"
                         hideCheckboxColumn="true"/>
    
</aura:component>

Component Controller:

({
    
    fetchAccounts : function(component, event, helper) {
        component.set('v.mycolumns', [
            {label: 'Account Name', fieldName: 'linkName', type: 'url', 
            typeAttributes: {label: { fieldName: 'Name' }, target: '_blank'}},
            {label: 'Industry', fieldName: 'Industry', type: 'text'},
            {label: 'Type', fieldName: 'Type', type: 'Text'}
        ]);
        var action = component.get("c.fetchAccts");
        action.setParams({
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var records =response.getReturnValue();
                records.forEach(function(record){
                    record.linkName = '/'+record.Id;
                });
                component.set("v.acctList", records);
            }
        });
        $A.enqueueAction(action);
    }


})

Apex Class:

public class AccountListController {
    
    @AuraEnabled
    public static List < Account > fetchAccts() {
        
        return [ SELECT Id, Name, Industry, Type FROM Account LIMIT 10 ];
        
    }
    

}

Output:


How to cover PageReference method in test class with assertions in Salesforce?

Sample Code:

Apex Class:

public class Sample {

    public Sample() {
    }
    
    public PageReference goToInfallible() {
    
        PageReference pg = new PageReference('http://www.infallibletechie.com');
        pg.setRedirect(true);
        return pg;
        
    }
    
}

Test Class:

@isTest
private class SampleTest {

    @isTest static void test() {
    
        Sample s = new Sample();
        PageReference pg = s.goToInfallible();
        system.assertEquals('http://www.infallibletechie.com', pg.getUrl());
        system.assertEquals(true, pg.getRedirect());
        system.assertEquals(new Map < String, String >(), pg.getParameters());
        system.assertEquals(new Map < String, String >(), pg.getHeaders());
        
    }
    
}

Lightning Workshop in Florida

Join Kelly Walker, Lightning Adoption Consultant, and local Lightning Champions for a half-day Lightning Workshop August 10! 

In this workshop, Lightning experts will guide you through the steps to move your org to Lightning Experience. You will also hear how Lightning Champions have transformed their orgs and improved adoption and engagement with their users by making the move! 

Enhanced Profile User Interface Salesforce

The enhanced profile user interface provides a streamlined experience for managing profiles. You can easily navigate, search, and modify settings for a profile. Salesforce org can use one profile user interface at a time.

To enable and disable enhanced profile user interface in Salesforce, check the below link

http://www.infallibletechie.com/2013/08/how-to-enable-and-disable-enhanced.html

Enhanced Profile User Interface enabled


Enhanced Profile User Interface disabled


How to get field values in onsuccess method of lightning:recordeditform?

Sample Code:

Component:

<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable" >
    
    <div class="slds-box slds-theme_default">
        <lightning:recordEditForm recordId="003f200002R3OtxAAF" objectApiName="Contact" onsuccess="{!c.callSuccess}">
            <lightning:messages />
            <lightning:inputField fieldName="FirstName" />
            <lightning:inputField fieldName="LastName" />
            <lightning:inputField fieldName="Email" />
            <lightning:button class="slds-m-top_small" variant="brand" type="submit" name="update" label="Update"/>                          
        </lightning:recordEditForm>
    </div>
    
</aura:component>

Controller:

({
    
    callSuccess : function ( component, event, helper ) {
        
        var payload = event.getParams().response;
        var objJSON = JSON.parse(JSON.stringify(payload));
        alert(objJSON["fields"]["Email"]["value"]);
        alert(objJSON["fields"]["FirstName"]["value"]);
        alert(objJSON["fields"]["LastName"]["value"]);
        alert(objJSON["fields"]["AccountId"]["value"]); 
        
    }

})


Output:








How to assign users already assigned to roles to a new role or change their role?

I am writing this post since I saw many admins asking how to assign already assigned users to a new role. Since by default the list view is Unassigned Users, many are manually editing the users to assign them to the new role or change their role.

1. Go to Roles.


2. Click Assign.


3. Select the All Users list view or prior to this create a list view with your filter conditions.


Sample Inbound REST API Test Class in Salesforce

Sample REST Class

@RestResource(urlMapping='/Account/*')
global with sharing class SampleRest {
  
    @HttpGet
    global static Account doGet() {
        RestRequest req = RestContext.request;
        String acctId = req.requestURI.substring(req.requestURI.lastIndexOf('/') + 1);
        Account result = [SELECT Id, Name FROM Account WHERE Id =: acctId];
        return result;
    }
  
    @HttpPost
    global static String doPost(String name, String descrp) {
        Account a = new Account(Name = name, Description = descrp);        
        insert a;
        return a.Id;
    }

    @HttpDelete
    global static void doDelete() {
        RestRequest req = RestContext.request;
        String memberId = req.requestURI.substring(req.requestURI.lastIndexOf('/') + 1);
        Account memb = [SELECT Id FROM Account WHERE Id = :memberId];
        delete memb;
    }
    
}

Sample Test Class

@isTest
private class SampleRestTest {

    @testSetup
    static void dataSetup() {
        Account acc = new Account(Name = 'Testing');
        insert acc;
    }

    static testMethod void testGet() {
        Account acc = [ SELECT Id FROM Account LIMIT 1 ];
        RestRequest req = new RestRequest(); 
        RestResponse res = new RestResponse();             
        req.requestURI = '/services/apexrest/Account/' + acc.Id;
        req.httpMethod = 'GET';
        RestContext.request = req;
        RestContext.response= res;
        Account acctResp = SampleRest.doGet();
        system.assertEquals(acctResp.Name, 'Testing');
    }
    
    static testMethod void testPost() {
        RestRequest req = new RestRequest(); 
        RestResponse res = new RestResponse();             
        req.requestURI = '/services/apexrest/Account/';
        req.httpMethod = 'POST';
        RestContext.request = req;
        RestContext.response= res;
        String acctId = SampleRest.doPost('Test', 'Testing');
        Account acc = [ SELECT Id, Name, Description FROM Account WHERE Id =: acctId ];
        system.assertEquals(acc.Name, 'Test');
        system.assertEquals(acc.Description, 'Testing');
    }
    
    static testMethod void testDelete() {
        Account acc = [ SELECT Id FROM Account LIMIT 1 ];
        RestRequest req = new RestRequest(); 
        RestResponse res = new RestResponse();             
        req.requestURI = '/services/apexrest/Account/' + acc.Id;
        req.httpMethod = 'DELETE';
        RestContext.request = req;
        RestContext.response= res;
        SampleRest.doDelete();
        system.assertEquals( [ SELECT COUNT() FROM Account ], 0);
    }
    
}


Mass Quick Actions in Salesforce Lightning

1. Go to Object Manager.

2. Select the Object in which you want Mass Quick Action.

3. Select Buttons, Links, and Actions.


4. Click New to create one.

5. Select Create New Record or Update a record. In my example I have used Update a record.


6. Select the fields that should be available to the users to update.


7. Go to Search Layouts.


8. Click Edit next to List View.


9. Add the Quick Action created.


10. Go to the object tab. Select list view except recent and select the records and click the Quick Action.


11. Select the value to update. In this example I have selected support queue.


How Single Sign On user download and install Salesforce Data Loader?

1. Use the below links to download Data Loader.

Windows OS:
https://login.salesforce.com/dwnld/DataLoader/ApexDataLoader.exe

MAC OS:
https://login.salesforce.com/dwnld/DataLoader/ApexDataLoader.dmg

2. Once installed use the Data Loader shortcut icon in the Desktop.

3. Select the action(Insert or update or upsert, etc).

4. Select the Environment(Sandbox or Production) and click Login Button.


5. Click Use Custom Domain.


6. Enter the domain and click Continue.


7. Click Allow button.


8. Check whether the login in successful.


How to create and share Report Folders in Salesforce Lightning?

To create the Report Folder:

1. Go to Reports tab.

2. Click New Folder button.


3. Enter Label and Name.

To share the Report Folders:

1. Go to Reports tab.

2. Select All Folders.


3. Select Share from the action menu.


4. Select User or Roles or Roles and Subordinates or Public Group in Share With. Select the name from the Names. Select the Access level from Access menu. Click the Share button to share.


Lightning for Gmail in Salesforce

Get data from rep’s Gmail, Google Contacts, and Google Calendar into Salesforce. Reps can view and search relevant Salesforce records from their Gmail, then relate important email to Salesforce records using Lightning for Gmail.

1. Go to Lightning for Gmail and Sync Settings.


2. Enable Lightning for Gmail.


3. Add Salesforce Lightning for Gmail Google Chrome extension.

4. Open Gmail in Google Chrome browser.

5. Click Log In to Salesforce.


6. Click Use Custom Domain if your organization is SSO enabled or enter username and password and click Log In.


7. Enter the Custom Domain. Click continue.

8. Click Continue to access.


9. Enter Google Email credentials.

10. Click Continue.

11. Link to Salesforce.