Sunday, 2 November 2014

Salesforce Entitlement, Entitlement Process & Milestone Handling

Entitlement : 

Entitlements are the same as the normal objects we use in Salesforce like Account, Contacts etc.
Adding to it, its a child object to Case, Contracts etc.


Purpose of Entitlement in Salesforce is specifically for
  • Enforce service levels with time-dependent, automated processes that instruct agents how to resolve cases.
  • Defining Service levels.

Entitlement according to Salesforce-phere
Entitlement is driven by "Entitlement Process" Object (Look-up on Entitlement Object ) where we set "Milestones" and "Business Hours"

1. Milestones :- Milestones are actually automated time dependent workflow, which run on the time set by the user, in other words to automate the SLA, this is the key of whole Entitlement thing in Salesforce. You can define the actions in Milestone i.e. Field Update, Email Alerts same like normal workflow. 

2. Business Hours : It is used to define the limits of the Milestone Time that have been set by the user like working hours in which a case should be handled.

Enabling & Setting-up Entitlement

Go to Setup --> App Setup --> Customize --> Entitlement Management --> Entitlements

Click Check and Save

after saving you'll get this check according to your requirement and Save. Do check last check-box of Enable Milestone Feed Items, this will add milestone box in your feed item, where Milestone Status will be more visible to the users.


Now go to Entitlement Process create one Entitlement Process

Here is the Entitlement Process created


Above in the setup list there is Milestones, create one

Now create an Apex class, that will set the Trigger time for the milestone, create a custom Number field on Case named as "Milestone Time" and create this class which implements "Support.MilestoneTriggerTimeCalculator"


























Now whatever will be the value in the this field will be set as Time trigger of Case Milestone
We will use this class, while adding Milestone with an Entitlement Process.

Now return back to Entitlement that we have created earlier and and down to it click "new" button in Milestone section, and fill the values same as shown in below


We have done all the setup for the Entitlement Process and Milestone
Now we will create an Entitlement Record, (Don't get confused with Entitlement Process and Entitlement)

Entitlement Process

System object that have Milestones and is used while creating Entitlement (API name SLAProcess ) record.


Entitlement: 


Its an object, that will be associated with Case. It is as normal as other objects like Account, Contact. This is used to attach Case Milestone to the object.

We will create Entitlement record now, that we will attach to the case, search for the Entitlement Tab and click  new, create a new record as shown below, as marked below these field should be field to make Entitlement active otherwise you can't attache it to the Case as shown Status Icon it green check that means its active, you need to provide Start Date  for it, Entitlement process also need to be provided otherwise no Milestone Time will be on the Case, after saving entitlement record you can see the Milestone will be visible under the Milestone.


Now go the case, in the below snapshot, all those field which is used in Entitlement process are shown, we will create a new record of Case and in the Entitlement Name we will put the record that we have created above,
There is a Timeline field on Case layout,which show scale view of the Time that have been setup. Modify the layout and set Case Milestone related list as well

If user didn't close the case or whatever is the procedure to be done to close the case then case will be Violated that automated process, and then Milestone Status will be change.

Look we are done with Entitlement and Milestone thing of Salesforce
You can Milestone actions as well, go to the Entitlement process and Click on the related Milestone of it where you can action like Field Update and Emails alerts etc.

The biggest problem I faced with this functionality when I tried writing trigger on Case Milestone Violation, and attaching other Milestone with the Case. you can write on case on check of "Milestone Status" field that when the status changed to Open violation. but attaching other Milestone on the violation of the first one is not happening.

This is what I learned while working with Entitlement and Milestone of Salesforce.
Thank you, any queries will be appreciated, keep learning-keep coding.

Happy Coding!

Tuesday, 1 July 2014

Basics of Apex Batch Class in Salesforce

What is batch class?

Batch class is just similar to Apex class except that batch class includes the Salesforce provide interface “Database.Batchable”.

Why we use batch class?

When we want to perform DML operations for bulk records or hit the web service then batch class comes in the picture.

Database.Batchable interface contains three method.
  • Start
  • Execute
  • Finish


Start Method

               global Database.QueryLocater start(Database.BatchableContext bc) {}

  • Use this method to get the records from database or object to be passed to “Execute” method.
  • This method returns Database.QueryLocater object that contains the records.
  • Query fired in the start method will return maximum 5,000,0000 records in a transaction.


Execute Method

           global void execute(Database.BatchableContext bc , List scope) {}


  • This method is used for do all the processing for data.
  • This method takes two arguments.
  • A reference of Database.BatchableContext object.
  • A list of sObject records.
  • The logical part of the code to process the data will be write in the execute method.


Finish Method

                global void finish(Database.BatchableContext bc) {}

  • This method takes only one argument a reference of Database.BatchableContext object.
  • This method is called when all the batches are processed.
  • This method is used for sending confirmation email to user or post-processing operations.


Here is the sample code

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

global class batchAccountUpdate implements Database.Batchable<sObject> {

    global Database.QueryLocator start(Database.BatchableContext BC){

        String query = 'SELECT Id,Name FROM Account';
        return Database.getQueryLocator(query);
    }

   global void execute(Database.BatchableContext BC, List<Account> scope) {

        for(Account a : scope) {

             a.Name = a.Name + 'Updated';
         }
         update scope;
   }  

   global void finish(Database.BatchableContext BC) {
    }
}

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


How to execute/run batch class?

                   Id batchID = Database.executeBatch(new BatchClass() , Batch_Size);

  • This method is used for execute the Batch class.
  • This method returns the ID of the AsyncApexJob object.
  • This method takes two arguments.
  • An instance of the batch class
  • Batch size(Optional)
  • User can see the batch status or abort the batch anytime from the Apex Jobs.


How to schedule batch class ?

      Id schJobId = System.ScheduleBatch(new BatchClass() , ‘Job Name’ , Time_Interval , Batch_Size)

  • This method is used for schedule the batch job to run once in a specific time period in future.
  • This method will return the Scheduled Job Id(CronTrigger Id) click here for CRON.
  • This method takes four arguments                    
                              1. An instance of batch class
                              2. Job Name
                              3. Time Interval
                              4. Batch_Size(Optional)

  • To schedule batch class at a specific time scheduler class will be used.
  • Schedule class similar to Apex class except that it also includes Salesforce Provide Interface “Schedulable”.
  • Next, schedule the class either using Salesforce Apex page in user interface or using System.schedule method.


Why Database.Stateful ?

  • This is used for maintain the state across the transactions.
  • If you don’t specify the Database.Stateful, all Static and Instance member variables are set back to their original values.


Why Database.AllowCallouts ?

  • To use web service callouts in the batch apex, you must specify Database.AllowCallouts interface in the batch class definition.


Governor Limits for Batch Apex

  • Default batch size is 200.
  • Avoid SOQL queries inside for loop.
  • Maximum 5 batches can be run at a time in org.
  • Total number of sendEmail methods allowed per transaction is 10.
  • Total number of future methods allowed per transaction is 10.
  • Always use database methods like insert,update,upsert in the batch class.

Saturday, 21 June 2014

#Salesforce Integration With Twilio

I was searching Twilio integration with salesforce on the web but didn't find any, so am posting this a simple POC of sending SMS to the mobile using Twilio from the Salesforce UI.


Its simple but just you need to do something extra two make this functionality working.

We will go step by step for this
First of all create a new account on Twilio click here 
Twilio will provide you a number, via which it will sent you SMS.

Now login to your salesforce account and create a Remote Site Setting.
In Remote Site URL enter https://api.twilio.com, like shown below

And then create a custom setting named as Twilio Configuration.
We are gonna use them in our apex classes.
Create fields on the custom setting you've just created, with same API name as below shown.


Now we need to provide some values to the fields ofthe custom setting click on Manage button shown above.

Before entering any values to the fields click on these links
For Auth Token and Account SID Click Here
For Test Credetials i.e. Test Account SID and Test Auth Token Click Here

For Account Name enter the name from which you registered like your email id.
For From Phone Number enter that number which got when you created account on Twilio.
After that save your custom setting.

Custom Setting should look something like this


After that you can save the code provided here GitHub 

Page will look something like this




See that was a piece of cake :)
Hope everything works just fine.
Happy coding..!!!

Tuesday, 17 June 2014

Basics of Apex Trigger for beginners

The basic logic of trigger is too huge to cover, I have tried a bit to make everyone understand that how this Apex trigger, a "pain in ass" works, I'll go step by step process of writing apex triggers.

What is Apex Triggers ?

A Trigger is Apex code that executes before or after the following types of operations:
  • insert
  • update
  • delete
  • merge
  • upsert
  • undelete

Types of Apex Triggers


  • Before Triggers: Before triggers can be used to update or validate record values before they are saved to the database.
  • After Triggers: After triggers can be used to access field values that are set by the database (such as a record's Id or last Updated field), and to affect changes in other records, such as logging into an audit table or firing asynchronous events with a queue.
Example : before insert, after insert, before update, after update, before delete, after delete

Syntax of Trigger

Things to keep in mind while writing apex trigger

  • Bulkify your Code : Use Looping through Trigger’s collections variables instead of process through particular indexing.
  • All triggers are bulk triggers by default, and can process multiple records at a time.
  • Bulk triggers can handle both single record updates and bulk operations like: Data import, Force.com Bulk API calls.
  • Bulkify your Code : Use Looping through Trigger’s collections variables instead of process through particular indexing.
  • Avoid SOQL Queries or DML statements inside FOR Loops: An individual Apex request gets a maximum of 100 SOQL queries before exceeding that governor limit. 
  • Bulkify your Helper Methods: if a trigger uses some Apex methods written in a helper class, it's important that those shared Apex methods are properly designed to handle bulk records. These methods should be written to be invoked with a set of records, especially if the method has a SOQL query or DML operation.
Use @future appropriately:
Here is a list of governor limits specific to the @future annotation:
  • No more than 10 method calls per Apex invocation.
  • No more than 200 method calls per Salesforce license per 24 hours.
  • The parameters specified must be primitive datatypes, arrays of primitive datatypes, or collections of primitive datatypes.
  • Methods with the future annotation cannot take sObjects or objects as arguments.
  • Methods with the future annotation cannot be used in Visualforce.

Use efficient collection variable of apex triggers




Try using sets and maps to handle bulk record processing.



TRIGGER BEST PRACTICE

  • Always use helper class in your trigger, and in helper class perform all your logic. like below
  • Don't write more then one trigger on an object, try to add up all your new trigger in a single trigger using different-different helper classes to read more click Order of Execution
There is allot to take care of when writing apex triggers, but I found these to helpful.
Hope this helps 
Happy coding.!!!




Sunday, 1 June 2014

Salesforce Multi-Select Picklist Using JQuery

I have implemented this good looking mulkti-select picklist on our Salesforce Visualforce pages.
It is so easy to handle and more user friendly as it looks.


User can select multiple option as it does in Salesforce Mutli-picklist fields, and values will be succesfully get saved in database.

User can choose more then one option by check options write in the front of the values.


You need to refer Jquery and Javascript from the static resource.

Here is the Visualforce Page code Visualforce Page

Here is the Apex class

Here is the link of github repo https://github.com/abhitripathi/MultiSelect-Jquery

Happy Coding..!!!

Wednesday, 28 May 2014

Book Review : Getting started with SOQL

Recently I got an opportunity to review the book "Getting started with SOQL"by Magulan D.
The book contains all the aspects of Salesforce Object Query Language(SOQL). Here are my thoughts...

The books starts with the basics of SOQL, difference of SOQL and SQL and valuable implementation of SOQL and then all the clauses that we use in SOQL.
Most of the time developers didn't know what they can do with SOQL. As a developer or as an administrator in Salesforce.com, we write many SOQL statements to fetch and validate the data present in the objects.

The sample queries used in the book will help you to understand the SOQL features easily. the sample queries are intended for beginners and for developers or administrators who are new to Salesforce.com.
This book also addresses the standards and guidelines to be followed when writing SOQL statements. The standards and guidelines discussed in this book will help you to write SOQL statements without hitting any limitation set by Salesforce.com and to avoid unwanted data fetched through the queries.

Feature of SOQL is so vast, but for the beginners as well as for experts this book will teach something, even I learned allot those things that I was not using most of the time in SOQL like toLabel() method. The use of Date literals with their example implementation in the queries.

The traditional method of explaining clauses like how to write SOQL, Where to use Caps and where not, that we need to take care of whenever writing an apex class. Limitation is the one difficult thing to handle in salesforce and if we are talking about SOQL then its limitation are most important thing to take care off. In the book limitation of SOQL have been explained in a brief way.

In the end of the book author explained the some tools that we can use to execute queries, he have explained the steps of installation and how to take their best use with SOQL queries, I never used Force.com Explorer software but now am gonna to use this one.

I recommend especially those who want to expertise in SOQL or want to know the key things of SOQL at first place, surely it will help them out.
Book can be purchased from Packt, Goodreads, Amazon, Books.google

Monday, 26 May 2014

Lazy loading tree with Force.com

I was trying to find something new to work, but nothing was making me eager to do that thing, and then I found out Jeff Douglas post of Original Post
Its an awesome post like he post every time, then I tried that thing in my personal salesforce org, and within few minutes I can see that tree in my org.

He's is using Jstree, its a jquery plugin, that provides interactive trees.
To know more about JsTree www.jstree.com

So that was so simple, and too much awesome, I would love to thank Jeff for doing such great things.
What he's exactly doing is to load an Objects tree, using Jquery, jsTree and Rest Javascript and using Lazy Loading.
There is a component that he created and called that component on the page.

Here how the tree looks

Here is the Steps need to perform

1. Create an Object named Parent Object.
2. Add a parallel look-up to the Parent Object of its own. Name the field "Parent Object".
3. Create a component named as "lazyLoadingTree". paste this code LazyLoadingTree
4. Create a Visualforce Page, name it ParentObject, paste this code ParentObject

5. Here is the Static Resource that you need to create, this is called from the Component that we created earlier, you cannot save your component without this restJavascript

Cheers..!!!
Happy Coding :)

Friday, 16 May 2014

reCaptcha Using HTML and Javascript ONLY...

Googles reCaptcha , its so easy to use it using PHP and .NET plugins, but I was trying to make it work only by HTML codes,

You can read this post of for reCaptcha without plugin CLICK ME
Unfortunately I tried to search, but everybody is using PHP, and upload that PHP file on server, to use it and make reCaptcha working, but I want a single code to make reCaptha working.

Here how it looks


As my code is not perfect, I have not done anything for the errors, but yes the reCaptcha's verification is working just perfect, it fetches response and shows it to you.
Here is the code(just paste it buddy)
reCaptch HTML

Hope I've helped..!!!

CHEERS :)



Tuesday, 6 May 2014

Opportunity "Probability" Field value assignment via "Stage" Field on VF Page

As you go to the Opportunity standard edit page, when you change the value of Stage field, the Probability fields value change accordingly like 10% or 30%. But the same functionality is not inherited by the VF page, so to perform this standard functionality we need to modify our VF page, as I have done.

This post is all about setting up the values of the Probability field of Opportunity associated to the Stage fields, as if you try this normally using VF page, this functionality doesn't work as standard salesforce functionality does, but doing some javascript stuffs, it can be done.

Here how it looks on VF page, by default these values are shown

Now change the Stage field value

Here the Probability field values changes with Stage value, as salesforce Standard functionality does.

Here is the small code for this,
VF Page Code


Happy Coding..!!!

Wednesday, 23 April 2014

Branding Of Your Salesforce Login Page

Login Page Branding:
Salesforce winter 14 release Bring a New Feature Login Page Branding, able to customize salesforce login page with their own Brand. Now you can change the look and feel of your login page by adding a background color, custom logo, and right-frame content.
Follow the Below Simple Steps to Do It.

Step 1 :

Your Name --> Setup --> Domain Mangement --> My Domain


Step 2 :
Provide your Domain Name


Step 3:

You will receive an email on your Email which you have provided in Salesforce Org, Click on that URL and get Logged in.


Step 4:

GO TO --> Your Name --> Setup --> Domain Mangement --> My Domain

Then click on Deploy To Users


Step 5:

Click on Edit button under Login Page Branding Section.


Step 6:

Upload a Logo and Click Save


Step 7:

Go to your Domain URL, that you got in email, and you can have some thing like this.


Isn't is looks good :)

Monday, 14 April 2014

Login Page With CSS Styling in Salesforce


Once I need to create a login page for salesforce sites, but it should look nice, so I used CSS to make my Login page look good, am sharing this, so that you don't waste time in just styling a Page.

Its as simply and perfect as it looks


Isn't it looks good,

Here is the CSS Style code, save this file in CSS format and make it a Zip file and save it in static resource.
"LoginStyles.css"

Here is the Apex Class (this is not perfect, You need to make changes to save)
"LoginController"

Here is Visualforce page.
"LoginPage"

Hope it will save some ones time.

Happy Coding..!!! CHEERS :)