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..!!!