Lightning Videos

Refer the below link to get the complete series of the video

http://www.sfdcpanther.com/lightning-tutorial/

Advertisements

Salesforce: Sharing Cheat Sheet

Awesome writeup.

The Silver Lining

Sharing is caring.

Sharing is complex, but necessarily so. It gives you incredibly fine-grained control over data access through it’s flexibility but requires quite a deep understanding to do it properly.

There are great articles out there that describe sharing in detail e.g.

Force.com object and record level security

An Overview of Force.com Security

I don’t want to recreate what’s in those articles, instead I’m providing a short, sharp cheat sheet of the major topics you need to understand. So without further ado…

Sharing Cheat Sheet

Sharing Metadata Records

  • “Object[Share]” for standard objects
  • “Object[__Share]” for custom objects
  • Fields: access level, record ID, user or group ID
  • Share records are not created for for OWDs, role hierchies or the “View All” or “Modify All” permissions

Implicit Sharing

  • For Accounts, Contacts, Cases and Opportunities only.
  • A platform feature, cannot be disabled.
  • Access to a parent account—If you have access to a child…

View original post 681 more words

Things to keep in mind while developing the Salesforce App-exchange Application

In this post, I will discuss what are the important parameters that need to be taken care while developing the App-Exchange Application using Salesforce. Before we dive into the concepts I would like to tell you that after developing the application, every application goes with the below security checks

  1. Checkmarx: – It is a free tool available to scan the Complete Code that is in your org where development has been done.
  2. Security Review: – The second step after submitting the code to the checkmarx and resolving all the issues is to Submit the package for the security review where salesforce representatives check the Quality of the code and functionality as well.

So, In order to develop the application which is secure and minimize the risk of data compromise or any other confidential information a developer must need to keep the following points into the mind while developing the application

1Cross-Site Scripting 
2S(O)QL Injection 
3Cross Site Request Forgery 
4Secure Communications and Cookies 
5Storing Secrets 
6Arbitrary Redirects 
7Access Control 
8Lightning Security Best Practices 
9Marketing Cloud App Security
10Secure PostMessage
11Secure WebSockets

Here is a Link to Trailhead module which explains everything about secure coding guidelines with the practical example

https://trailhead.salesforce.com/en/modules/secdev_injection_vulnerabilities/units/secdev_inject_get_started_wappsec

Resources: – 

  1. Salesforce Document
  2. Salesforce Security Guide
  3. An Overview of Force.com Security

Implement Omni Channel from Scratch – Salesforce

In this post, we will learn how to implement Omni Channel and in my previous post, we have implemented the Live Agent if you have not read yet then Read Here.

Prerequisite: Live agent must be enabled in order to use Omni Channel.

Problems

Problem while using Live Agent: – The company XYZ has now successfully enabled the live agent at their company site and it was working fine however as business growing company  the Global Support VP is getting complaints

  1. Some agents are getting many cases and some are not getting any cases at all.
  2. Agents need to Case manually from the Queues if the case is created manually or any other resource like Email-to-Case. And assigning the cases manually leads the wastage of time.
  3. Also, it is hard to manage what is the capacity of the particular agent and what is the traffic. 

Salesforce Admin has come up with an idea to implement the Omni Channel which will resolve all above problem and will increase the efficiency of the Support Agent.

Solution.gif

Introduction to Omni Channel:- Omni-Channel is a flexible, customizable feature, and you can configure it declaratively—that is, without writing code. Use Omni-Channel to manage the priority of work items, which makes it a cinch to route important work items to agents quickly. Manage your agents’ capacity to take on work items so that they’re given only the number of assignments that they can handle.

Best of all, Omni-Channel routes all these assignments to the correct agents automatically. Agents no longer have to pick and choose work assignments manually from a queue, which saves everyone in your call center time, effort, and brainpower.

Permission to set up the Omni Channel is Customize Application at profile level.

Omni Channel.png

Step1 – Enable Omni Channel:- Setup -> Build -> Customize -> Omni-Channel -> Omni-Channel Settings -> Select Enable Omni-Channel Checkbox -> Save

Enable Omni Channel.png

Setp2 – Create Service Channel:- Service Channels let you turn any Salesforce object―such as a case, lead, SOS session, or even a custom object―into a work record. Omni-Channel then plucks these work items from their queues―like flowers from the garden of agent productivity―and routes them to your agents in real time.

omnichannel_service_channels.png

Setup -> Build -> Customize -> Omni-Channel ->  Service Channels -> New -> 

Service Channel.png

Step3 – Create Routing Configurations: – Routing Configurations determine how work items are routed to agents. They let you prioritize the relative importance and size of work items across your Omni-Channel Queues. That way, the most important work items are handled accordingly, and work is evenly distributed to your agents. After all, we want to make sure every agent gets to have an equal amount of fun, right?

Setup -> Build -> Customize -> Omni-Channel -> Routing Configurations -> New -> 

Routing Configurations.png

Explanation of above Screenshot

  1. Overflow Assignee:- Sets the user or queue that Omni-Channel routes items to when your org reaches Omni-Channel limits.
  2. Routing Priority: – The order in which work items from the queue that are associated with this routing configuration are routed to agents.
  3. Routing Model: Specify how incoming work items are directed to agents using Omni-Channel.
    1. Least Active: – Incoming work items are routed to the agent with the least amount of open work. 
    2. Most Available: – Incoming work items are routed to the agent with the greatest difference between work item capacity and open work items. 

Step4 – Create Queue and Associated with Routing Configurations: – 

Setup -> Administrator -> Manage Users -> Queues -> New ->

Create Queue.png

Step5 – Add Omni Channel to the Console Application: – 

Setup -> Create -> Apps -> Edit Next to Sample Console App(OR You may Select your) -> Scroos Down to “Choose Console Components” Section -> Add Omni Channel From “Available Items” to “Selected Items”

Add Omni Channel.png

Now, as we have done almost part of implementing the Omni Channel. Let’s have a look how our console application looks like

Click on App Launcher and Select Sample Application

Console.png

Step6 – Add Presence Status to Omni Channel: – 

To see the list of available status like Online, Offline, Away, Available For Cases, Available For Chat and etc. We need to create the Presence Status.

Setup -> Build -> Customize -> Omni-Channel -> Presence Status -> New -> 

Presence Status

Repeat the above process to add more presence status.

Step7 – Add Presence Status to Correct Users Profile: – 

Adding the presence status to the Omni Channel that does not mean it will be available in Omni Channel Utility. To make visible these statuses we need to add to the appropriate user’s profile or permission set.

Setup -> Manage Users -> Profiles -> Select the profile on which you want to enable the status (in this demo we will add in System Administrator Profile)->  Scroll down to “Enabled Service Presence Status Access”  section and Click Edit -> 

Presence Status to profile.png

Add presence status from “Available Service Presence Statuses” to “Enabled Service Presence Statuses” Section and save.

Add Presence Status to profile

Step8 – See if presence status is available in Omni Channel utility or Not: – 

Click on App Launcher and Select Sample App

Omni Channel Sttus.png

Now, in Final let us test the App. Copy and paste the code if Live Chat Deployment and Chat Button that we did create in our previous post and save as .html file. if you have not implemented the Live Agent refer this link to implement the same.

From Omni channel Select any online statue and run the HTML file of Live Agent that we did save earlier.

OutPut.png

OutPut 1.png

If you are facing any issues please come up in the comments section with.

Sharing is Caring 🙂

Resources:- 

  1. Live Agent
  2. Omni Channel
  3. Trailhead

 

 

 

Create Lightning Charts With Chart.Js

Create Dynamic Chart using Chart.Js

ABSYZ

Everyone loves a smooth and slick UI. And what if, if you have an awesome UI for which you have to design once and will work across the devices, which is nothing but responsive. One such library which was great but not supported in Lightning experience was Chart.js. As some of its external libraries had older versions, Chart.js wasn’t supported in Lightning Locker Service. Oh, wait a min, what is a Locker Service? That itself is a story to tell about for another day. Anyways you can check out the documentation here (Lightning locker service).

But that is not the situation now. Due to the latest version updates of Chart.js, it is finally compatible with Lightning Locker Service. You may be wondering how can I implement Chart.js in my org? Well, through this blog post am going to explain how to build a Generic Chart.js Lightning component and by…

View original post 197 more words

Dynamic Binding Salesforce Lightning Component(Generic)

Welcome back All, here we will learn about the dynamic field of Lightning Component. As Most of you must be aware of that In Lightning, Component Dynamic component is not available. Recently I was working on one of my projects and implemented the Dynamic binding using the lightning component so I am going to share how I implemented the same so that it may help others.

As we all know that we can use the Dynamic Binding in the VisualForce page but in Lightning Component it is not Possible. 

In this example, We will show the list of Objects in a picklist and when user will select any object it will dynamically show the TOP 15 records in a table.

Output 

OutPut.png

Step1 – Create Apex Class

DynamicBindingDemoController.class

Step2 – Create the Lightning Component

DynamicBindingDemo.cmp

See the comments into the component.

Step3: – Click on Controller from the right and paste the below code for Controller Javascript

DynamicBindingDemoController.js


({
doInit : function(component, event, helper) {
helper.onInit(component, event, helper);
},
doHandleChange : function(component, event, helper) {
helper.onHandleChange(component, event, helper);
},
})

Step4: – Click on Helper from the right and paste the below code for Helper Javascript

DynamicBindingDemoHelper.js


({
onInit : function(component, event, helper) {
/* Call the Apex class method to fetch the List of all object */
var action = component.get('c.listAllObject');
action.setCallback(this, function(response){
var state = response.getState();
if(state === 'SUCCESS' && component.isValid()){
/* set the value to the attribute of the component */
var responseValue = response.getReturnValue();
var lstOptions = [];
for(var i=0; i < responseValue.length; i++){
lstOptions.push({
value : responseValue[i].split('####')[1],
key : responseValue[i].split('####')[0]
});
}
lstOptions.sort();
component.set('v.objectList', lstOptions);

}else{
var errors = response.getError();
$A.log(errors);
if(errors || errors[0].message){
console(errors[0].message);
}
}
});
$A.enqueueAction(action);
},
onHandleChange : function(component, event, helper){
/* Call this method whenever user will select the Obejct
* and show the Dynamic Content */
var selObject = component.find('selectObject').get('v.value');
var action = component.get('c.listAllFields');
if(selObject!=null && selObject!='' && selObject!=undefined){
action.setParams({
"objectName" : selObject
});
action.setCallback(this, function(response){
var state = response.getState();
if( state === 'SUCCESS' && component.isValid()){
//component.find("dynamicBody").set("v.body",[]);
component.find('sfdcDiv').set("v.body",[]);
var responseValue = response.getReturnValue();
var objectValue = responseValue.sObjectData;
var fieldList = responseValue.fieldList;

/* Create Dynamic Table */
var sObjectDataTableHeader = [];
// Create table Header
for (var i=0; i < fieldList.length; i++) {
sObjectDataTableHeader.push(fieldList[i].label);
}
console.log(sObjectDataTableHeader);
//Get the count of columns.
var columnCount = sObjectDataTableHeader.length;
//Create a HTML Table element.
var table = document.createElement("TABLE");
//table.border = "1";
//Add the header row.
var row = table.insertRow(-1);
for (var i = 0; i < columnCount; i++) {
var headerCell = document.createElement("TH");
headerCell.innerHTML = sObjectDataTableHeader[i];
headerCell.className='hearderClass';
row.appendChild(headerCell);
}
var dvTable = document.getElementById("sfdctable");
dvTable.innerHTML = "";
dvTable.appendChild(table);
/* Create Dynamic Table End */

if(objectValue.length){
for(var j=0; j < objectValue.length; j++){
// Dynamic table Row
row = table.insertRow(-1);
// Dynamic Table Row End
for (var i=0; i < fieldList.length; i++) {
// Dynamic table Row
var cell = row.insertCell(-1);
cell.innerHTML = objectValue[j][fieldList[i].apiName];
component.set('v.isSending' , false);

}
}
}else{

}
}else{
var errors = response.getError();
$A.log('Error Details '+errors);
if( errors || errors[0].message){
console.log('Error Details '+errors[0].message);
}
}
});
$A.enqueueAction(action);
}else{
component.set('v.isSending' , false);
}
},
})

See the comments.

Step5: – Create Lightning Application

DynamicBindingDemoApplication.app

<aura:application access=”Global” extends=”force:slds” >
<c:DynamicBindingDemo />
</aura:application>

Click on Preview to see the output of the component.

Happy learning 🙂

Sharing is caring 🙂 😉

Resource:- 

OPFOCOUS Blog

Complete Code

 

 

 

How to implement Live Agent into Salesforce From Scratch

To Create a Basic Live Agent Implementation into Salesforce we need to follow the 7 easy steps that are given below:

Step1 – Enable Live Agent: In order to enable Live agent user must have Customize Application permission

  1. From Setup in Salesforce Classic, enter Live Agent Settings in the Quick Find box, then select Live Agent Settings.
  2. Select Enable Live Agent.
  3. Click Save.

Enable Live Agent.png

Step2 – Create Live Agent Users :

  1. From Setup in Salesforce Classic, enter Users in the Quick Find box, then select Users.
  2. Click Edit next to a user’s name.
  3. Select Live Agent User. If you don’t see this checkbox, verify that your support organization has purchased enough Live Agent feature licenses.
  4. Click Save.

Create Live Agent Users.png

Step3 – Create And Assign Live Agent Skills :

  1. From Setup, enter Skills in the Quick Find box, then select Skills.
  2. Click New.
  3. Enter a name for the skill.
    For example, you can create a skill that’s called “Accounts” for agents who specialize in questions about customer accounts.
  4. In the Assign Users area, select the users whom you want to associate with the skill.
  5. In the Assign Profiles area, select the profiles that you want to associate with the skill.
  6. Click Save.
To enable supervisors to assign skills, enable the “Assign Live Agent Skills to Users” permission on their profiles.
Create Skills.png
Step4 – Create Live Agent Configuration :
  1. From Setup in Salesforce Classic, enter Live Agent Configurations in the Quick Find box, then select Live Agent Configurations.
  2. Click New.
  3. Choose the settings for your Live Agent configuration.
  4. Click Save.

Step5 – Create Live Agent Deployments :

  1. From Setup in Salesforce Classic, enter Deployments in the Quick Find box, then select Deployments.
  2. Click New.
  3. Choose the settings for your deployment.
  4. Click Save. Salesforce generates the deployment code.
  5. Copy the deployment code, and then paste it on each Web page where you want to deploy Live Agent. For best performance, paste the code immediately before the closing body tag (that is, ).

Deployment

Step6 – Create Chat Button :

  1. From Setup in Salesforce Classic, enter Chat Buttons in the Quick Find box, then select Chat Buttons & Invitations.
  2. Click New.
  3. Select Chat Button from the Type field.
  4. Choose the remaining settings for your chat button.
  5. Click Save.
  6. Copy the button code, and then paste it on each Web page where you’ve deployed Live Agent. Make sure that you paste the code in the area on the page where you want the button to appear.

If you have any problem then please come up into comment section with

Resource

Salesforce Atricle

 

How to Call Salesforce API from Lightning Component

You may have heard about that we can not make the Salesforce API Call directly from the lightning component. If you do make the callout from the lightning component then you will get the below error

INVALID_SESSION_ID:This session is not valid for use with the API.

For Example when you will execute the below code from the Developer Console then you will get the Valid Response


HTTP h = new HTTP();
HTTPRequest req = new HTTPRequest();
HttpResponse resp = new HttpResponse();

req.setMethod('GET');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v41.0/query?q=Select+Id,+Name+From+Account');
resp = h.send(req);
System.debug('#### Response Status '+resp.getStatus());
System.debug('#### Response Status Code '+resp.getStatusCOde());
System.debug(resp.getBody());

But if you will call the same block from the Lightning Component then you will get INVALID_SESSION_ID:This session is not valid for use with the API. Error.

I gone through with this error and found THIS SALESFORCE DOCUMENT where they have specified why we can not make API Call from JavaScript Code.

After reading the document, I have come up with 2 Solutions that are given below: –

1 – Connected App and Named Credentials as Callout Endpoints and Auth Providers

2 – Using VF Page – VF page will be used to get the Session Id of the current log in user and this VF page will be used into Apex class for fetching the Session Id.

In this tutorial we will use VF page for making callout because it is an easy and simple method method. Follow the below steps

Step1 – Open Developer Console, File -> New -> VisualForce Page -> Enter Name “GetSessionIdVF” -> OK. Use below code for VF Page


<apex:page >
 Start_Of_Session_Id{!$Api.Session_ID}End_Of_Session_Id
</apex:page>

Step2 – Create a New Class which will use this VF page to get the Session Id and making API Call Out. File -> New -> Apex Class -> Name it “ApiCallLightningComponent” -> OK. Use below code for the class.


public class ApiCallLightningComponent {
 /*
 * @Name : - fetchUserSessionId
 * @Description: - Call the VF page and get the Log In Use Session Id
 * @Params : - none
 * @ReturnType : - String
 */
 public static String fetchUserSessionId(){
 String sessionId = '';
 // Refer to the Page
 PageReference reportPage = Page.GetSessionIdVF;
 // Get the content of the VF page
 String vfContent = reportPage.getContent().toString();
 System.debug('vfContent '+vfContent);
 // Find the position of Start_Of_Session_Id and End_Of_Session_Id
 Integer startP = vfContent.indexOf('Start_Of_Session_Id') + 'Start_Of_Session_Id'.length(),
 endP = vfContent.indexOf('End_Of_Session_Id');
 // Get the Session Id
 sessionId = vfContent.substring(startP, endP);
 System.debug('sessionId '+sessionId);
 // Return Session Id
 return sessionId;
 }
 /*
 * @Name - makeAPICall
 * @Description - Responsible for making API Call out
 * @params - None
 * @ReturnType - String
 */
 @AuraEnabled
 public static String makeAPICall(){
 String sessionId = fetchUserSessionId();
 HTTP h = new HTTP();
 HTTPRequest req = new HTTPRequest();
 HttpResponse resp = new HttpResponse();
 req.setMethod('GET');
 req.setHeader('Authorization', 'Bearer ' + sessionId);
 req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v41.0/query?q=Select+Id,+Name+From+Account');
 resp = h.send(req);
 System.debug('#### Response Status '+resp.getStatus());
 System.debug('#### Response Status Code '+resp.getStatusCOde());
 System.debug(resp.getBody());
 return JSON.serialize(resp.getBody());
 }
}

See the comments.

ApiCallLightningComponent class contains 2 methods fetchUserSessionId and makeAPICall, One for getting the Session Id and Other for making the Callout that will be called from the JavaScript.

Step3 – Create a lightning component, File -> New -> Lightning Component -> Name it “MakiAPICall” -> OK. Use below code for the Component


<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes, flexipage:availableForRecordHome,force:hasRecordId, forceCommunity:availableForAllPageTypes, force:lightningQuickAction" controller="ApiCallLightningComponent" access="global" >
<div class="slds-m-around_x-small">
			<lightning:button variant="brand" label="Make CallOut" iconName="action:apex" iconPosition="left" onclick="{!c.doHandleClick }" /></div>
</aura:component>

Click on the Controller and use below code


({
doHandleClick : function(component, event, helper) {
helper.onHandleClick(component, event, helper);
}
})

Click on the helper and then use below code for helper


({
onHandleClick : function(component, event, helper) {
// Get the action of Controller (Apex) Class
var action = component.get('c.makeAPICall');

// set the callback which will return the response from apex
action.setCallback(this, function(response){
// get the state
var state = response.getState();
if( (state === 'SUCCESS' || state ==='DRAFT') && component.isValid()){
// get the response
var responseValue = response.getReturnValue();
// Parse the respose
var responseData = JSON.parse(responseValue);
alert(responseData);
//alert(responseData.totalSize);
console.log(responseData);
} else if( state === 'INCOMPLETE'){
console.log("User is offline, device doesn't support drafts.");
} else if( state === 'ERROR'){
console.log('Problem saving record, error: ' +
JSON.stringify(response.getError()));
} else{
console.log('Unknown problem, state: ' + state +
', error: ' + JSON.stringify(response.getError()));
}
});
// send the action to the server which will call the apex and will return the response
$A.enqueueAction(action);
}
})

Step4 – In Final Step Test the Component using Lightning Application. File -> New -> Lightning Application -> Enter Name -> Submit -> Use below Code


<aura:application extends='force:slds' >
<c:MakiAPICall/>
</aura:application>

Note: – If Your component name is different then use the name of your component instead of MakiAPICall.

Output of the above code

Call API From Lightning Component

You can find the complete Here.

Happy Learning 🙂

Happy Coding 😉

Sharing is Caring

Resources –

 

Configure Force.com Migration Tool for deployment Apache ANT

Force.com Migration Tool

Prerequisites for Using the Force.com Migration Tool

Before you can use the Force.com Migration Tool, Java and Ant must be installed and configured correctly. If you already have Java and Ant on your computer, you don’t need to install them, so first verify the installation from a command prompt.

 

Step 1 – Download and Install Java – Many of you have already installed the JDK in your system if not then you can download JDK from Here.

Download Java
Step 2 – Download Apache Ant – Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. You can Download Apache Ant From Here

Download ANT.png
Step 3 – Set the path for ANT_HOME and JAVA_HOME :- After you have downloaded the Java and Apache Ant and JDK then place the Apache Ant into C drive for convenience.Now, let us set the path for both Java and Ant. Go to

  • Control Panel -> System and Security -> System -> Advance System Settings ->
  • a Popup will open Click Environment Variables – >

ANT_HOME.png

  • Click New under user variable and enter “ANT_HOME” for variable name and use ant location for variable value for example if you have pasted the ant into c drive then it will look like “C:\ant” click OK.

ANT_PATH.png

  • Again Click New under user variable and enter “JAVA_HOME” for variable name, use jdk location for variable value for example – “C:\Program Files\Java\jdk1.8.0_51”

JAVA_HOME.png
Step 4 – Set the PATH:- Now, we have added the path for Ant and Java. We need to add one more variable name PATH. Click New under user variable and enter “PATH” for variable name, use “%ANT_HOME%\bin;%JAVA_HOME%\bin;” for variable value.

PAHT_HOME.png
Now, time to do some testing for the above steps that we have setup until now. Open command prompt and type java -version hit enter, again type javac -version and hit enter. Now, type ant -version and hit enter you see the message like in below image.

Note: – If you receive Tools.jar not found error, go to “/Ant/manual/api/org/apache/tools/ant/util/JavaEnvUtils.html” and replace “java.home” with “java_home”.

CMD.png

Step 5 – Download Force.com Migration Tool: – In this step you need to download the force.com migration tool and can be downloaded from “Here“. After download unzip the file using 7Zip winrar or any other tool. You will see find a .jar file a html file and a folder name sample.

Salesforce ANT
Step 6 – Copy “ant-salesforce.jar” file from the file that you downloaded into step 5 (folder name “salesforce_ant_41.0”) and paste it to ant lib folder

Ant _ Salesforce

Download the required files from “Here” for the demo purpose.

Step 7 – After you downloaded the file from the above link place the file into your suitable location and unzip the file. Now, open build.properties file into any text editor and provide the credentials for the source and target Org then save as using properties extension of the file.

Step 8 – Open command prompt if you have closed this other wise use the same. Navigate to the directory where you have located this folder and then go to deploymentFolder folder.

Directory.png
Step 9 – It’s time to retrieve the data from the test Org type ant retrieve and hit enter

Retrieve.png

File Location

Step10 – Deploy the retrieved components into the Production Org. Type ant deploy

Deploy.png

If you have any problem then come up in the comment section with.

Hurray you have setup the ANT with Salesforce for Deployment.

Happy Learning 🙂 😉