How to deploy platform events using Apache ANT tool in Salesforce?

Sample package.xml:

    <types>
<members>EventName__e</members>
        <name>CustomObject</name>
    </types>

Cheers!!!

How to deploy sharing rules using Apache ANT tool in Salesforce?

Sample package.xml:
   
 <types>
        <members>Account.*</members>
        <name>SharingCriteriaRule</name>
    </types>
    <types>
        <members>Account.*</members>
        <name>SharingOwnerRule</name>
    </types>

Cheers!!!

Salesforce Interview Questions with Answers Part 45

1. Performance Testing in Salesforce

http://www.infallibletechie.com/2017/07/performance-testing-in-salesforce.html

2. PK Chunking in Salesforce

http://www.infallibletechie.com/2017/07/pk-chunking-in-salesforce.html

3. Divisions in Salesforce

http://www.infallibletechie.com/2017/07/divisions-in-salesforce.html

4. Community user unable view articles?

a. Check the Article type access to community user profile.
b. Make sure articles are shared to customer or partner or just Internal App.

5. How to create Global Picklist Value Sets from existing pick list field in Salesforce?

http://www.infallibletechie.com/2017/08/how-to-create-global-picklist-value.html

6. Default Values formula in Picklist Fields Salesforce

http://www.infallibletechie.com/2017/08/default-values-formula-in-picklist.html

7. Session-Based Permission Sets in Salesforce

http://www.infallibletechie.com/2017/08/session-based-permission-sets-in.html

8. Chatter Streams in Salesforce

http://www.infallibletechie.com/2017/08/chatter-streams-in-salesforce.html

9. Grant Access Using Hierarchies in Public Group in Salesforce

http://www.infallibletechie.com/2017/10/grant-access-using-hierarchies-in.html

10. Dynamic Apex

http://www.infallibletechie.com/2012/10/dyanamic-apex.html

11. JavaScript in Strict Mode

http://www.infallibletechie.com/2017/10/javascript-in-strict-mode.html

12. Are CRUD and FLS considered in Lightning component?

No. Visualforce enforces the active user’s CRUD and FLS permissions when a page renders a Salesforce object. Lightning doesn’t do any client-side authorization, so it doesn’t respect these

permissions. The following code shows data to all users, even those who aren’t authorized to see it.

<b>Hello <i>{!v.User.FirstName}</i>.</b>

13. How to use JAVASCRIPT file stored in Static Resources in custom Lightning component?

http://www.infallibletechie.com/2017/10/how-to-use-javascript-file-stored-in.html

14. {! } and {# } delimiters in Salesforce Lightning

http://www.infallibletechie.com/2017/10/and-delimiters-in-salesforce-lightning.html

15. force:createRecord in Salesforce Lightning 

http://www.infallibletechie.com/2017/11/forcecreaterecord-example-in-salesforce.html

16. How does Platform events trigger fire?

Unlike triggers on standard or custom objects, triggers on platform events don’t execute in the same Apex transaction as the one that published the event. The trigger runs asynchronously in its own process under the Automated Process entity. As a result, there might be a delay between when an event is published and when the trigger processes the event. Also, debug logs corresponding to the trigger execution are created by Automated Process. System fields, such as CreatedById and LastModifiedById, reference the Automated Process entity.

Cheers!!!

force:createRecord example in Salesforce Lightning

Sample Code:

CreateAccountComponent.cmp

<aura:component implements="flexipage:availableForAllPageTypes">
    <lightning:button label="Create Account" variant="brand" onclick="{!c.createAccount}"/>
</aura:component>

CreateAccountComponentcontroller.js

({
createAccount: function (component) {
        var createRecordEvent = $A.get('e.force:createRecord');
        if ( createRecordEvent ) {
            createRecordEvent.setParams({
                'entityApiName': 'Account',
                'defaultFieldValues': {
                    'Type' : 'Prospect',
                    'Industry' : 'Apparel',
                    'Rating' : 'Hot'
                }
            });
            createRecordEvent.fire();
        } else {
            /* Create Record Event is not supported */
            alert("Account creation not supported");
        }
    }
})

Add the lightning component to any page. I have added it to the Account detail page.

Output:



Cheers!!!

How to query all non portal user roles in Salesforce?

SOQL:

SELECT Id, Name FROM UserRole WHERE PortalType = 'None'

Output:


Cheers!!!

lightning:layout in Salesforce

Represents a responsive grid system for arranging containers on a page. A lightning:layout is a flexible grid system for arranging containers within a page or inside another container. The default layout is mobile-first and can be easily configured to work on different devices.

Sample Code:

<aura:component implements="flexipage:availableForAllPageTypes" >
    <div class="c-container">
        <lightning:layout horizontalAlign="center">
            <lightning:layoutItem flexibility="auto" padding="around-small">
                <ui:inputSelect multiple="false">
                    <ui:inputSelectOption label="All Types" text="" value="true"/>
                </ui:inputSelect>
            </lightning:layoutItem>
            <lightning:layoutItem flexibility="auto" padding="around-small">
                <button class="slds-button slds-button_brand">Search</button>
            </lightning:layoutItem>
            <lightning:layoutItem flexibility="auto" padding="around-small">
    <ui:button label="New"/>
            </lightning:layoutItem>
        </lightning:layout>
    </div>    

</aura:component>

Output:


Cheers!!!

How to set default value in picklist in Lightning Component in Salesforce?

Lightning Component:

<aura:component access="global">
    <ui:inputSelect aura:Id="makeId" multiple="false" label="Select Make">
        <ui:inputSelectOption label="Acura" text="acura" value="true"/>
        <ui:inputSelectOption label="Audi" text="Audi"/>
        <ui:inputSelectOption label="BMW" text="bmw"/>
        <ui:inputSelectOption label="Honda" text="honda"/>
        <ui:inputSelectOption label="Hyundai" text="hyundai"/>
        <ui:inputSelectOption label="Mercedes Benz" text="merc"/>
        <ui:inputSelectOption label="Nissan" text="nissan"/>
    </ui:inputSelect><br/><br/>
    <ui:button label="Find Vehicles" press="{!c.findVehicles}"/>
</aura:component>

here value="true" is used to set the default value.

Lightning Component Controller:

({
findVehicles : function(component, event, helper) {
        alert(component.find("makeId").get("v.value"));
}
})

Output:


When Find Vehicles button is clicked, selected value will be alerted on the screen.

Cheers!!!

How to set Email Signature in Salesforce?

1. Go to My Settings.


2. Set the Email Signature in My Email Settings.


Cheers!!!

How to find who last modified the report in Salesforce?

1. Create a report with Reports report type.


2. Check Last Modified By and Last Modified to find who last modified the report and when.


Cheers!!!

Salesforce Support for Non System Administrators or Regular Users

1. Go to Login Access Policies.


2. Enable Available to Users.


Cheers!!!

Files Component in Community Builder in Salesforce

In Community Builder, drag the new Files List component onto a page. This gives your community members a one-stop view of all their files while letting them do useful things like uploading and previewing.

Use the Property Editor to customize the Files List display. Choose the number of records to display on the page at once. Try out different settings to get the look you want.


Cheers!!!

When manual sharing will be removed in Salesforce?

1. It is possible to manually share a record to a user or a group using Apex or the SOAP API. If the owner of the record changes, the sharing is automatically deleted. Salesforce currently removes all manual sharing from a record when the owner changes. If you are manipulating sharing via apex code or simply sharing to portal users, you might want the sharing to remain when the record owner is changed.

2. Changing your sharing model deletes any manual shares your users have created.

Vote for the below idea

https://success.salesforce.com/ideaView?id=08730000000BqA4

Cheers!!!

Simple Outbound SOAP API using Apex in Salesforce

1. Go to the below link.

http://ec.europa.eu/taxation_customs/vies/checkVatTestService.wsdl

2. Right click and save the XML.


3. Go to Apex Classes.


4. Click Generate From WSDL button.


5. Select the downloaded file from step 2.

6. Click Parse WSDL and Done.

7. Remove Test from the endpoint in the class which was generated.

Note:
Apex class - ecEuropaEuTaxudViesServicesCheckva


Sample Code:

Visualforce page:

<apex:page controller="TestingVAT">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:PageBlockSectionItem >
                    Enter Country Code<apex:inputText value="{!strCountryCode}"  />
                </apex:PageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Enter VAT Number<apex:inputText value="{!strVATNum}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Check VAT" action="{!checkVAT}" reRender="infoblock"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
        
    <apex:outputPanel id="infoblock">
        <apex:pageBlock rendered="{!NOT(ISBLANK(vatNumber))}" >
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    Country Code
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    {!countryCode}
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    VAT Number
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    {!vatNumber}
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Request Date
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    {!requestDate}
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Valid
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    {!valid}
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Name
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    {!name}
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Address
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    {!address}
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:outputPanel>
</apex:page>

Apex Class:

ppublic class TestingVAT {

    public String strCountryCode {get;set;}
    public String strVATNum {get;set;}
    public String countryCode {get;set;}
    public String vatNumber {get;set;}
    public Date requestDate {get;set;}
    public Boolean valid {get;set;}
    public String name {get;set;}
    public String address {get;set;}

    public TestingVAT() {
        strCountryCode = 'RO';
        strVATNum = '9311280';
    }
    
    public void checkVAT() {
        ecEuropaEuTaxudViesServicesCheckva.checkVatResponse_element res = new ecEuropaEuTaxudViesServicesCheckva.checkVatResponse_element();
        ecEuropaEuTaxudViesServicesCheckva.checkVatPort obj = new ecEuropaEuTaxudViesServicesCheckva.checkVatPort();
        res = obj.checkVat(strCountryCode, strVATNum);
        countryCode = res.countryCode;
        vatNumber = res.vatNumber;
        requestDate = res.requestDate;
        valid = res.valid;
        name = res.name;
        address = res.address;
    }
    
}

Output:



Cheers!!!

{! } and {# } delimiters in Salesforce Lightning

Anything inside the {! } or {# } delimiters is evaluated and replaced when the component is rendered or when it uses the value. Unbound attributes are designated by {# } and do not update if the underlying object or attribute has changed.

Unbound Attribute Example:

Child Component

<aura:component>
    <aura:attribute name="childAttr" type="String" />
    <p>childAttr: {!v.childAttr}</p>
</aura:component>

Parent Component

<aura:component>
    <aura:attribute name="parentAttr" type="String" default="parent attribute"/>

    <!-- Instantiate the child component -->
    <c:childComponent childAttr="{#v.parentAttr}" />
    <br/><br/>
    <p>parentAttr: {!v.parentAttr}</p>
    <br/><br/>
    <p><lightning:button label="Update parentAttr" onclick="{!c.updateParentAttr}"/></p>
</aura:component>

({
    updateParentAttr: function(cmp) {
        cmp.set("v.parentAttr", "updated parent attribute");
    }
})

App

<aura:application >
    <c:parentComponent />
</aura:application>

Output:

Before clicking Update parentAtt:


After clicking Update parentAtt:



Bound Attribute Example:

Child Component

<aura:component>
    <aura:attribute name="childAttr" type="String" />
    <p>childAttr: {!v.childAttr}</p>
</aura:component>

Parent Component

<aura:component>
    <aura:attribute name="parentAttr" type="String" default="parent attribute"/>

    <!-- Instantiate the child component -->
    <c:childComponent childAttr="{!v.parentAttr}" />
    <br/><br/>
    <p>parentAttr: {!v.parentAttr}</p>
    <br/><br/>
    <p><lightning:button label="Update parentAttr" onclick="{!c.updateParentAttr}"/></p>
</aura:component>

({
    updateParentAttr: function(cmp) {
        cmp.set("v.parentAttr", "updated parent attribute");
    }
})

App

<aura:application >
    <c:parentComponent />
</aura:application>

Output:

Before clicking Update parentAtt:


After clicking Update parentAtt:


Check the below link for more information

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

Cheers!!!

How to use JAVASCRIPT file stored in Static Resources in custom Lightning component?

Sample Code:

<aura:component implements="flexipage:availableForAllPageTypes" access="global"> 
<ltng:require scripts="{!$Resource.myJavaScriptLib}"/> 
<div class="main-content"> 
<aura:outputText value="Hello World!">
</div> 

</aura:component>

Cheers!!!

JavaScript in Strict Mode

JavaScript code that runs in a browser can access a user's private information. To protect this information, LockerService requires you to use ECMAScript (ES5) strict mode, and enforces it in your code. This mode makes it easier to write secure JavaScript. A few code tweaks to comply with ES5 can substantially reduce the need for checking data at runtime.

Here’s a simple example of how strict mode prevents JavaScript from traversing the call-stack and modifying other functions. Without strict mode, the following function would have returned the name of the function that called primaryFunction().

JavaScript code:
function primaryFunction() {
  'use strict'
  console.log("The function calling the current method is: “+ primaryFunction.caller.name);
}
function callerFunction() {
  return primaryFunction(); 
}
callerFunction();

Output:
Uncaught TypeError: 'caller' and 'arguments' are restricted function properties and cannot be accessed in this context.
at primaryFunction (<anonymous>:3:72) at callerFunction (<anonymous>:6:10) at <anonymous>:8:1

Strict mode restricts access to several other entities. When it is enforced, you can no longer reference the window object through the JavaScript variable this, for example. These restrictions eliminate a lot of potential security vulnerabilities.

Cheers!!!

Salesforce Lightning Inspector Chrome Extension

The Salesforce Lightning Inspector is a Google Chrome DevTools extension that enables you to navigate the component tree, inspect component attributes, and profile component performance. The extension also helps you to understand the sequence of event firing and handling.

1. Go to https://chrome.google.com/webstore/detail/salesforce-lightning-insp/pcpmcffcomlcjgpcheokdfcjipanjdpc.

2. Install it by clicking "Add to Chrome".


3. Right-click Lightning Component and select Inspect.


4. Click Lightning Tab.


Cheers!!!

Lightning Login for Password-Free Logins in Salesforce

Say goodbye to the hassle of weak passwords, forgotten passwords, and locked-out accounts. Give your users the enhanced speed, convenience, and security of password-free logins. Enable Lightning Login, assign the required permission to your users, and encourage them to individually enroll in Lightning Login.

Lightning Login isn’t limited to orgs using Lightning Experience. It works in Salesforce Classic, too.

1. Go to Session Settings.


2. Enable Allow Lightning Login.


3. Enroll Lightning Login.


4. Click Register.

5. Enter the code received.

6. Download Salesforce Authenticator app.

7. Click + New account to add an account.

8. Enter the two words shown in the App.

9. Click Connect and Approve.

10. You will see success message.


11. Go to login.salesforce.com or your domain.


12. You will see Login Approval Required.


13. Go to Salesforce Authenticator Mobile app to approve the login.

Check the below link for more information

https://help.salesforce.com/articleView?id=security_ll_enable.htm&type=0

Cheers!!!

Salesforce Service Cloud

Key Features of Salesforce Service Cloud

1. Case Management - http://www.infallibletechie.com/2014/12/case-management-in-salesforce.html

2. Knowledge - http://www.infallibletechie.com/2014/12/salesforce-knowledge.html

3. Live Agent Web Chat - http://www.infallibletechie.com/2013/06/live-agent-implementation-in-salesforce.html

4. Entitlement Management - http://www.infallibletechie.com/2013/06/entitlement-management-in-salesforce.html

5. Chatter for Agent & Team Collaboration

6. Email to Case - http://www.infallibletechie.com/2012/10/email-to-case-in-salesforce.html

7. Web to Case - http://www.infallibletechie.com/2012/12/web-to-case-in-salesforce.html

8. Case Management (Auto-assignment, rules & queues)

9. Customizable Service Console - http://www.infallibletechie.com/2013/04/service-cloud-console-in-salesforce.html

10. Self-Service Portal - http://www.infallibletechie.com/2013/06/self-service-portal-in-salesforce.html

11. Snap In Chat - http://www.infallibletechie.com/2017/05/service-cloud-snap-ins-salesforce.html

12. Case Escalation - http://www.infallibletechie.com/2013/08/escalation-rule-in-salesforce.html

13. Omni Channel - http://www.infallibletechie.com/2017/04/omni-channel-in-salesforce.html

14. Macros - http://www.infallibletechie.com/2015/07/implementing-macros-in-salesforce.html

Cheers!!!

How to change the color in apex:toolBar?

Sample Code:

<apex:page sidebar="false">
    <apex:form >
        <apex:toolbar style="background-color:red;background-image:none;">
            <apex:inputText /> 
            <apex:commandButton value="Search"/>
        </apex:toolbar>
    </apex:form>

</apex:page>

Output:


Cheers!!!

How to change the color in apex:panelBar?

Sample Code:

<apex:page sidebar="false">
    <apex:panelBar style="background-color:pink;" headerStyle="background-color:gray;background-image:none;">
        <apex:panelBarItem label="Test 1">
            Test 1
        </apex:panelBarItem>
        <apex:panelBarItem label="Test 2">
            Test 2
        </apex:panelBarItem>
        <apex:panelBarItem label="Test 3">
            Test 3
        </apex:panelBarItem>
    </apex:panelBar>

</apex:page>

Output:


Cheers!!!

Grant Access Using Hierarchies in Public Group in Salesforce

When selected, any records shared with users in this group are also shared with users higher in the role hierarchy.

Grant Access Using Hierarchies for public group Determine whether users have access to records they don’t own, including records to which they don’t have sharing access, but someone below them in the hierarchy does.


Note:
If an user is added to the public group. All the users above his role hierarcy will all also be added to the public group with Reason For Membership as "Manager of Group Member".

Cheers!!!

Debugging and Troubleshooting Lightning components Salesforce

JavaScript Is Case-Sensitive. If the API name of your object is Expense__c and a field is Amount__c, and you try to reference it with expense__c.amount__c (which works in Visualforce), it’s going to fail in JavaScript.

JSON.stringify() gives you a human-readable representation of even complex structured data. The console.log() command outputs a string in your browser’s JavaScript console.

JavaScript Controller in Lightning

1. This isn’t a class. It’s a JSON object containing a map of name:value pairs. It can contain only action handlers, which you’ll never invoke directly.

2. Your action handlers are declared as anonymous functions assigned to the action name (here, myAction and anotherAction). Your functions can accept up to three parameters, and only these parameters (component, event, and helper though you can name them differently). The framework supplies them when it calls the handler.

3. Most importantly, you separate your name:value pairs with a comma.

Handling Server-Side Errors

If your Apex code encounters an error, you can create and throw an AuraHandledException. Catching other exceptions, such as a DML exception, and rethrowing them as an AuraHandledException also results in much better experience on the client side.

Cheers!!!

How to stop getting emails from Comments on an item I bookmarked in Salesforce?

1. Go to My Settings.


2. Go to Email Notifications in Chatter.


3. Disable Comments on an item I bookmarked check box.


Cheers!!!

How to find whether my Salesforce org is Lightning Ready?

1. Click "Get Started" in Lightning Experience Migration Assistant.


2. Click "Check Readiness" button.


3. You will be receiving an email with the readiness report. The report will contain almost all the information to be executed before migrating to Lightning.

Check the below link for more information

https://www.salesforce.com/blog/2016/09/is-your-org-ready-for-lightning-experience.html

Cheers!!!

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 = 'Test@test.com');
/* Code to convert Contact to JSON string */
String strJSON = JSON.serialize(con);
system.debug('JSON String is ' + strJSON);
/* Code to convert JSON string to Contact */
Contact con1 = (Contact)JSON.deserialize(strJSON, Contact.Class);
system.debug('Contact is ' + con1);

Output:


Cheers!!!

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

Sample Code:

Visualforce page:

<apex:page standardController="Account" sidebar="false">
 <style>
    .bPageBlock .pbBody .dataCol {
        border:0px;
    }
    .bPageBlock .pbBody .labelCol {
        border:0px;
    }
</style>
    <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:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Output:


Cheers!!!

How to convert String to sObject using Apex in Salesforce?

Sample code:

//Setting String str as Account
String str = 'Account';
//Casting String to sObject
sObject obj = Schema.getGlobalDescribe().get(str).newSObject();
obj.put('Name', 'Test');
obj.put('Description', 'Testing');

system.debug('obj is ' + obj);

Output:


Cheers!!!

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.


Cheers!!!

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.

document.cookie="debug_logs=debug_logs;domain=.force.com";


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

Cheers!!!