Tuesday, April 14, 2020

Flow Builder and Other Salesforce Declarative Tool


Different Declarative Automation tool in Salesforce

This post will give you complete overview of different declarative automation tool in salesforce to use and where Flow builder stands among them.

If Want to learn in detail about Flow builder with many live scenario- Enroll my Complete tutorial from below link



Friday, April 10, 2020

Real Time Integration - Salesforce - Indian Postal system


This post to implement realtime integration between salesforce and Indian Postal  to get details of Post Office by searching Postal PIN Code or Post Office Branch Name of India.

There are many such real time integration are explained in my Step by step Guide for Salesforce Integration which you can enroll from udemy to learn in details.

Link to my all real time integration (90% off to enroll) https://www.udemy.com/course/salesforce-integration-bydebasis/?couponCode=APRIL20OFF


overview of Salesforce And Indian Postal API:



Invoke REST service from Salesforce Lightning Component to get Post Office details by PIN Code or Branch Name




Link to My Complete Tutorial: https://www.udemy.com/course/salesforce-integration-bydebasis/?couponCode=APRIL20OFF


Sunday, March 29, 2020

Salesforce - Covid19 Corona integration to get country status


Coronavirus disease (COVID-19) is an infectious disease caused by a new virus.
The disease causes respiratory illness (like the flu) with symptoms such as a cough, fever, and in more severe cases, difficulty breathing. You can protect yourself by washing your hands frequently, avoiding touching your face, and avoiding close contact (1 meter or 3 feet) with people who are unwell.
In this post, we will integrate to get live data to display in salesforce for affecting country with their statistics.

if you want to learn complete integration with various live examples enroll my Udemy course



Sunday, December 22, 2019

Basic Trigger examples


Basic Trigger examples


 Populate contact description when user creates contact

trigger ContactBeforeInsert on Contact (before insert) {
// Trigger.New hold new version of Contacts
for(Contact contact: Trigger.new){
contact.Description = ‘Contact created successfully by using ContactBeforeInsert trigger’;
}
// No Need to write DML statement, trigger. New will be take care.
}

Populate contact description with modified user name when user updates contact.

trigger ContactBeforeUpdate on Contact (before update) {
// Trigger.New hold new version of Contacts
for(Contact contact: Trigger.new){
contact.Description = ‘Contact updated successfully by ‘+ userInfo.getUserName() ;
}
// No Need to write DML statement, trigger. New will be take care.
}

 How to write a trigger to inject the above 2 scenarios in one trigger

trigger ContactBeforeInsertUpdate on Contact (before insert, before update) {
// Trigger.New hold new version of Contacts
for(Contact contact: Trigger.new){
if(trigger.isInsert){
contact.Description = ‘Contact created successfully by using ContactBeforeInsert trigger’;
}
If(trigger.isUpdate){
contact.Description = ‘Contact updated successfully by ‘+ userInfo.getUserName() ;
}
}
// No Need to write DML statement, trigger. New will be take care.
}

Throw an error whenever the user try to delete the contact which is not associated to account

trigger contactBeforeDelete on Contact(before delete){
for(Contact contact: trigger.old){
if(contact.accountId == null){
contact.addError(“Hey! You are not authorized to perform this action.”);
}
}
}

when the leads are inserted into the data base it would add Doctor prefixed for all lead names. This is applicable for both inserting and updating the lead records


trigger PrefixDoctor on Lead (before insert,before update)
{

 List<Lead> leadList = trigger.new;

 for(Lead l: leadList)

 {

 l.firstname = 'Dr.'+ l.firstname;

 }


 }


The following trigger adds the Opportunity Owner into the sales team automatically whenever the Opportunity is created.

trigger OppTeam on Opportunity (after insert) {
 List<OpportunityShare> sharesToCreate = new List<OpportunityShare>();

 List<OpportunityTeamMember> oppteam = new List<OpportunityTeamMember

 > ();

 OpportunityShare oshare = new OpportunityShare();

 oshare.OpportunityAccessLevel = 'Edit';

 oshare.OpportunityId = trigger.new”0”.Id;

 oshare.UserOrGroupId = trigger.new”0”.createdbyid;

 sharesToCreate.add(oshare);

 OpportunityTeamMember ot = new OpportunityTeamMember();

 ot.OpportunityId = trigger.new”0”.Id;

 ot.UserId = trigger.new”0”.OwnerId;

 ot.TeamMemberRole = 'Account Manager';

 oppteam.add(ot);

 if(Oppteam!=null && Oppteam.size()>0)

 {

 insert Oppteam;

 }

 if(sharesToCreate!=null && sharesToCreate.size()>0)

 {

 list<Database.SaveResult> sr = Database.insert(sharesToCreate,false);

}


 }

Create “Sales Rep” field with data type (Text) on the Account Object. When we create the Account record, the Account Owner will be automatically added to Sales Rep field. When we update the Account owner of the record, then also the Sales Rep will be automatically updated.

triggerUpdateSalesRep on Account (Before insert,Before Update){
Set<Id>setAccOwner=new Set<Id>();
for(Account Acc: trigger.new)
{
setAccOwner.add(Acc.OwnerId);
}
Map<Id,User>User_map = new Map<Id,User>(“select Name from User where id
in:setAccOwner”);
for(Account Acc: Trigger.new)
{
User usr=User_map.get(Acc.OwnerId);
Acc.sales_Rep1__c=usr.Name;
}
}

Sunday, April 7, 2019

LightningOut in Salesforce

Expose Lightning component outside of lightning/salesforce

We can expose any component to outside of salesforce(it may be PHP/Wordpress/Sharepoint) or to classic VF page with usage of lightning Out.

We will directly jump to code and will see how to setup this.

Lets create a Component which you want to expose to VF page.

Component :LightningDataTableExample.cmp

<aura:component controller="AccountDataTableController" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" > <aura:attribute type="Account[]" name="acctList"/> <aura:attribute name="mycolumns" type="List"/> <aura:handler name="init" value="{!this}" action="{!c.fetchAcc}"/> <lightning:datatable data="{! v.acctList }" columns="{! v.mycolumns }" keyField="id" hideCheckboxColumn="true"/> </aura:component>

Add apex controller for the component 

public class AccountDataTableController { @AuraEnabled public static List <Account> fetchAccounts() { //Qyery 10 accounts List<Account> accList = [SELECT Id, Name, BillingState, Website, Phone, Industry, Type from Account LIMIT 10]; //return list of accounts return accList; } }

Lets add controller code for the component

({
    fetchAcc : function(component, event, helper) {
        helper.fetchAccHelper(component, event, helper);
    }
})


Lets add helpercode for the component

({ fetchAccHelper : function(component, event, helper) { component.set('v.mycolumns', [ {label: 'Account Name', fieldName: 'Name', type: 'text'}, {label: 'Industry', fieldName: 'Industry', type: 'text'}, {label: 'Phone', fieldName: 'Phone', type: 'Phone'}, {label: 'Website', fieldName: 'Website', type: 'url '} ]); var action = component.get("c.fetchAccounts"); action.setParams({ }); action.setCallback(this, function(response){ var state = response.getState(); if (state === "SUCCESS") { component.set("v.acctList", response.getReturnValue()); } }); $A.enqueueAction(action); } })
Add this component in Page and it will look like below


Now lets expose this component in classic VF page. To achieve this we wil luse lightning out with lightning dependency app

Create a new Lightning app with below code to expose the component to app

App:LoutDataTableApp.app

<aura:application extends="ltng:outApp" access="GLOBAL">
<aura:dependency resource="c:LightningDataTableExample"/>
</aura:application>

Lets create a vf page and display this component in VF page.

Vf Page: LODataTable.vfp

<apex:page >
    <apex:includeLightning />   
    <div id="LcDisplayId"></div>     
 <script>     
    $Lightning.use("c:LoutDataTableApp", function() {      
    $Lightning.createComponent("c:LightningDataTableExample",
    {
       
  },
   "LcDisplayId",
    function(component) {
        
    });
 });
 </script>
</apex:page>

Lets see the same Lightning component in classic VF page






Saturday, September 2, 2017

Macro Examples

 We have already discussed about Macro and its best practice to use. Lets check out few implementation of macro.

Add and Replace Field Values in a Case Using Macros


lets assume our support agent always need to repeat a task such as updating/replacing a  field value in a record. instead of click on edit button then change the field value and then save which need so much interactions with systems and obviously it consumes some time.

 Lets write a small macro for this which will perform all task on a single click with peace of mind.

Steps:
1. Create a macro
2. Add instructions  as below
 - click on Add instruction 
- first instruction tells on which object this macro to work on, select Active case tab
- next instruction tells the macros which action in case feed publisher to interact with, select "Select Email actions"
-  next what to do with Email actions, Select replace subject , and in text field write the subject line.
- add another instruction to add a specific email in CC address.
- add one instruction to replace BCC address.
 - select submit action and save macro 
Now you can open the case for which you want to execute this macro and go to macro widget select this macro click on run .

Friday, September 1, 2017

Bulk Macro in Salesforce


Bulk Macro


We have already posted about basic on Macro and step by step guide for creating and managing  macro on @ Macros in Salesforce

Lets discuss on bulk macro, what is it and how it will be helpful for support agent.


A bulk macro is a macro that can run on multiple records at a same time. One macro performing same action on multiple record at a time on a single click of a support agent. Like, if a support agent want to send a notification to all customers having opened case.

Prerequisites  for bulk macro

Bulk macros are supported for the 
 - Email publisher in case feed on the saelsforce console for services
 - All quick actions except for social quick actions

Bulk actions are not supported for the 
 - salesforce knowledge actions
 - community actions
 - social post actions
 - Add and insert instructions 

If bulk macro interacts with the email publisher, it can contain only one email publisher action.
A bulk macro must contain at least one submit action instruction.


Create a bulk Macro 

lets consider an example, support agent need to send a notification to all all customers who have opened a case.

lets create a bulk macro to perform the same action on multiple case records.

1. Create a macro

    - Go to your service console  Application from app    menu. 

  - click on Macro on the bottom of the page and then click on "Create a Macro" 

 2. Enter Macro name, description and add instructions to this macro to execute. Select the context for the macro then select object that macro interacts with and then select the action that want to be performed by macro.

This created macro creates and sends an email to the contact person for the selected cases. This macro can be run as simple macro and bulk macro because it meets all criteria for a bulk macro.

To identify a macro as a bulk macro, please check if your macro comes with a green lightning bolt icon.

 Run a Bulk Macro on Multiple Records

To run bulk macros, the Enable Enhanced Lists setting must be enabled in your org.

you can run a bulk macro only on records in one object list view at a time.

Bulk macros are processed in increments of 10 macros at a time. You can run a bulk macro on more than 10 cases, but the system
processes the macro in groups of 10 at a time.
- create a list view for the records you want to run macro on
- open macro widget
- select the macro with green lightning bolt icon in widget and click on run.

Once macro ran successfully, you will get macro status in list view as below

Tips:

Keyboard Shortcuts for macro

M - Open Macro widhet
S - highlight searchbar
E - Edit selected macro
V - view macro details page
ENTER - Run selected Macro
Space Bar - Expand/collapse selected macro instruction
UP Arrow - scroll up macro list
Down Arrow - scroll down macro list 


Next post coming soon for few more working examples/implementation on Macro. Stay tuned..