Tuesday, 24 March 2015

Process Builder With Email Alerts (Spring 15)

Just got a chance of working with Process builder, amazing stuff, covering everything that a workflow can do as well more than that, you can create records or you can call your Apex class to perform you custom logic.

It is fast, easy to use and awesome look and feel. I am assuring you once you start using it, you will stop using workflow.

So I am going to start an easy use of Process Builder with Email Alerts

1. First of All go to workflow & Approval section and click on Process Builder


2. Click "New" button in right corner.



3. Write the name of the process and Description




4. Here is the way process builder shows the logic in the way of a flow diagram, too easy to understand.




5. Click on the Add Object down to Start box, there is a picklist of all the objects and click "Save"



6. Select Field of the selected Object from the picklist for the criteria and click "Save"




7. Now you have selected the Object, now click on the Add Criteria to add criteria same as workflow you can use formula as well, I tried that one and that is also easy to create.



8. Now you are done with criteria, it is highlighted, time to add the action, click on action.



9. While adding the action I was amazed to see when there was an Option of Apex Class + Update Record + Insert Record, none of these you can do in workflow that is best property of the Process Builder. I choosed Email Alert, for Email Alert you need to have an Email Alert on the Object that you are using, their is auto complete on the last text box, which will show the related Email Alerts, as in below snapshot



10. Now you are done, isn't that quick and easy, now in the right corner of the screen there is Activate button, click on it, and you will get confirmation like below. Click OK now you have created you first workflow using Process Builder.


11. Click on "View All Process" to see the process.


Few thing need to take care of :

1. You cannot delete a process builder data, if it is Active, you need to Deactivate it and wait to 12 hours to delete it.
2. You cannot modify it again, you need to clone it and re-create ( I don't know why this restriction, I tried to modify but didn't succeeded).

Try it now, May the force.com be with you!!

Monday, 23 March 2015

Calling Apex method from List View button having Parameters

Recently I was trying to call an Apex method in List view method and want to pass the parameters from the method from the List View button whatever the records have been selected.

You can say I am dump, but when I selected a single record in the List view it works perfect, but when I selected more then one, it started showing error. I tried putting alerts and tried to check why its not taking the multiple record Ids, this is the code I wrote

1:  //Fetch Id of the selected Record  
2:  var records = {!GETRECORDIDS($ObjectType.Contact)};   
3:  //Check for selected record size  
4:  if(records.length <= 4) {   
5:       //Calling Apex method  
6:       sforce.apex.execute("MyApexClass","myApexMethod", {ids:records });   
7:  } else {   
8:       alert('You can validate only 4 records at a time');   
9:  }  

Above code was not working with the multiple records, it was showing error


So finally I got the thing that RECORDS was returning a list of Ids of the selected records, then the code needs manipulation, I end up doing this below code and this was working like charm

1:  //Fetch Id of the selected Record   
2:  var records = {!GETRECORDIDS($ObjectType.Contact)};   
3:  if(records.length <= 4) {   
4:       var res = "";   
5:       var i;   
6:       //Loop through the records Id selected by the user  
7:       for (i = 0; i < records.length; i++) {   
8:            res += records[i] + ";";   
9:       }   
10:       sforce.apex.execute("MyApexClass","myApexMethod", {ids:res });   
11:  } else {   
12:       alert('You can validate only 4 records at a time');   
13:  }  

Happy Coding!!