First of all thanks for your support and response for the posts I have been authoring for short span of time in this blog. But amazing thing happened. Since I got so many request to enhance my blog. I have decided to upgrade to my own domain ForceWizard.com .
I am trying to build a community for salesforce developers over there (have some crazy road maps in mind).
In order to cover wide range of topics and frequent posts I am joining hands with other salesforce developers/bloggers (most of them are more experienced than me ). So it’s going to be good learning cure.
During my college days I have great passion towards web development so I am going to develop the whole site on my own. We are constantly working on the site please update your suggestion in contact us page of the site . So see you guys there. Once again thanks for the responses its the only thing that kept me going.
Installing mavensmate in windows with lightning support
Salesforce recently Introduced lightning components for multi screen tech world. It is a client-server framework that accelerates development, as well as app performance, and is ideal for use with the Salesforce1 mobile app for now (spring 15).
I have been playing around it for last one month . I am writing my custom components in developer console directly because there is no plugin available for eclipse which is my primary Force.com IDE . Writing code directly in developer console makes some process very tedious like pushing the code to version control system , to take backup in my local drive.
So I searched for a solution, occasionally I have used mavensmate as Force.com IDE in sublime text editor which is my favorite text editor and there is plugin available for lightning components. In this post I will walk you through how to install mavensmate , lightning plugin in sublime in windows.
Installation steps
Installing sublime text editor 3
Installing package control
Installing mavensmate and lightning plugin
Placing Force.com CLI
Installing sublime text editor
Installing sublime text editor is as usual as installing a program in windows.
Go to http://www.sublimetext.com/3 .
Download the setup file for windows .
Open the setup file and follow the instructions.
You are good to go for the sublime text editor.
Installing package control
Package control is the package manager for sublime text editor. It makes exceedingly simple to find, install and keep packages up-to-date.
Got to this link https://packagecontrol.io/installation
Copy the code for sublime text 3 as shown in the screens shot.
Open the console using clt + ‘ or View > Show Console.
Paste the above code and press enter. Package control should be installed in your sublime editor.
Restart you sublime (just close and reopen).
Installing mavensmate and lightning plugin
Mavensmate is an open source Force.com IDE. Which can be integrates to various text editors like sublime and Atom .
For installing mavensmate follow these instructions
Open package control using clt + shift + P and type install
Select the Package Control : Install Package
Now type mavesnmate and press enter
Mavensmate should be installed in your sublime .
For installing lightning plugin follow these instructions
Open package control using clt + shift + P and type install .
Select the Package Control : Install Package .
Now type lightning and press enter.
Lightning plugin should be installed in your sublime.
After spring 15 release salesforce made so many changes to its new javascript component framework lightning component . It has a rich, elegant event driven architecture that appeals to JavaScript developers and all of the power of the Force.com platform. Unlike other component frameworks where you typically have to design your own backend functionality, authentication and connectivity, with Lightning you simply expose server-side Apex functionality with a single annotation (@AuraEnabled) and then tell the component to utilize it. That’s all you have to do!!! Now you have the power of salesforce like workflow, data validation, queues, bulk processing, reporting, dashboards and much, much more in your hand.
Lightning component encapsulates its even driven functionality, markup and CSS into single reusable functional units called lightning bundle (component , controller , helper , css , renderer , design , svg and documentation) . Using the bundles you can assemble it to larger components or into a complete enterprise application. By adding a appHostable tag you can expose your component to salesforce1 mobile application. You can also expose you component to lightning app builder by adding flexipage:availableForAllPageTypes to your component.
The lightning app builder allows developer and non-developer to drag and drop your lightning components to build enterprise grade applications and easily push it production with out having to write unit test code.
As a whole lightning component is a power pack to build your enterprise application on top of it.
The Process Builder is a new workflow tool from spring release 15 that promises you to easily automate your business processes by providing a powerful and user-friendly visual representation of your process as you build it. The Process Builder’s simple and powerful design which not only creates, updates records, send emails, Call a Flow, Post to Chatter and Submit for approval but also calls apex class in order to achieve requirements which cant be done by any of the above.
What are the classes which can be called from the process builder ?
To answer this question @InvocableMethod comes into play. A process builder can call only apex classes which implemented @InvocableMethod annotation for a static method in it.
How many @InvocableMethod a class can have?
Only one @InvocableMethod is allowed for one class.
How many arguments does a @InvocableMethod can receive ?
At the time of writing this post the current release is summer 15, until now the method accepts only one argument.
What if i want to pass multiple variables to apex class?
In order to pass more than one argument from process builder you want to create a class with @InvocableVariable this allows you to pass multiple variables from process builder.
Requirement :
Delete the related contacts of an account when a checkbox is checked in account.
Solution :
Create a process that executes when that checkbox value is true which calls an apex class to delete the related contacts.
* Don’t forget to Activate the process after you have created it.
The process builder will look like this
Create a class named as DeleteRelatedContacts and copy paste the below code.
To display the values in pie chart you want to first construct the data in the format of string and Integer in a Wrapper class then pass that list of the wrapper class to the apex:chart . Height , Width and data are required parameters in apex:chart.
In apex:pieSeries the labelField parameter should be the name of the string variable in Wrapper class and dataField parameter should be the name of the Integer value in the wrapper class. Both the parameter names should match properly otherwise the chart will not be displayed.
You can use wrapper class as noraml class in apex.
Eg: WrapperExample firstAccount = new WrapperExample();
3) When to use ?
You can go for wrapper class when you want to perform some operation in the records using other then object fileds in that case you can use it. There are more scenarios you want to think logically inorder ot use it .
Hope this is helpful for you if you want any deep dive let me know in comments.
It's an age old question: "Where the hell am I?" I don't like to stop and ask for directions and neither does my code. I'm surprised it took me this long to require some way for my code to be able to detect the environment in which it was running.
I needed to answer these two questions:
Is this a sandbox?
What edition is this? (enterprise, developer, etc)
I'll make the recipe a little more universally helpful. The idea is that you can use this class to easily help your code answer these questions when it's running all over the cloud like a banshee.
So obviously you want to copy and paste the code below into a new Apex Class. Then call any one of the methods from within your own code to get the info you need.
For example: String myEdition = WhereAmI.getEdition();
Boolean isSandbox = WhereAmI.isSandbox();
Class:
public class WhereAmI {
//Tell me am i in sandbox or production
public static Boolean isSandbox(){
Organization org = new Organization();
org = [ select IsSandbox from Organization limit 1];
return org.IsSandbox;
}
//Tell me which edition am i in.
public static String getEdition(){
Organization org = new Organization();
org = [ select OrganizationType from Organization limit 1];
return org.OrganizationType;
}
}
Ant is a command-line utility tool used for moving metadata between a local directory and a Salesforce organization and vice versa.
Ant Tool is useful in the following scenarios:
When you need to populate an environment with large amounts of setup changes.
Multistage release processes — A typical development process requires iterative building, testing, and staging before releasing to a production environment. Scripted retrieval and deployment of components can make this process much more efficient.
Repetitive deployment using the same parameters — You can retrieve all the metadata in your organization, make changes, and deploy a subset of components. If you need to repeat this process, it's as simple as calling the same deployment target again.
When migrating from stage to production is done by IT — Anyone that prefers deploying in a scripting environment will find the Force.com Migration Tool a familiar process.
Prerequisites :
Java
Ant
Installing java
Check whether java is installed or not in your machine using the following command in your terminal.
java -version
If you get the follwing kind of output then java is installed in your machine.
java version "1.7.0_75"
OpenJDK Runtime Environment (IcedTea 2.5.4) (7u75-2.5.4-1~trusty1)
OpenJDK Server VM (build 24.75-b04, mixed mode)
Otherwise install using the following commands
sudo apt-get install default-jre
sudo apt-get install default-jdk
This will install JDK and JRE in your machine.
Installing Ant
Check wheather Ant is installed or not in your machine using the following command in your terminal.
ant -version
If you get the follwing kind of output then ant is installed in your machine.
Apache Ant(TM) version 1.9.3 compiled on April 8 2014
Otherwise install using the following commands
sudo apt-get install ant
This will install ant in your machine.
Integrating salesforce with ant :
Login to your org go to Setup --> Develop --> Tools and click on Force.com Migration Tool
It downloads a zip file which contains a Sample folder , ant-salesforce.jar and Readme.html
ant-salesforce.jar is used to integrate ant tool with salesforce and the sample folder contains some example files to practise.
A qucik check whether everything is ready to go:
Download these files from this link and enter your org credentials in build.properties . I have configured it to extract all apex classes and apex triggers from your org.
Open your terminal and go to the location where you have extracted your downloaded file and type the following command
ant retrive
Your terminal will look something like this
Now when you look at your folder structure it will look like this and all your apex classes and apex triggers will be present inside.
A new folder named retrieveOutput has been created.
Inside retrieveOutput folder classes folder , triggers folder and package.xml will be present.
Inside classes folder all your class files and its corresponding meta data information (xml files) will be present.
Inside triggers folder all your trigger files and its corresponding meta data information (xml files) will be present.
If you face any errors during your installation process put that in comment section I will help you as soon as possible .
Pagination using list in custom controller in salesforce
Use case :
Add pagination to display more than 2000 records in a VisualForce page.
Solution :
Query all records using SOQL and store it in a list. Parse the list and store the specified number of records in a new list and dispaly the new list in the page.
Code :
controller
public class ContactPagination { //List to store all the contacts according to requirement public List AllContacts = new list(); //List to show the limited records on the page public List ContactsToShow{get;set;} //Navigation variables Integer counter = 0;//TO track the number of records parsed Integer limitSize = 10;//Number of records to be displayed Integer totalSize =0; //To Store the total number of records available //Constructor public ContactPagination(){ ContactsToShow = new list(); //Get all the contacts which are from Public realations lead source AllContacts = [select id , name, LeadSource from contact where LeadSource='Public Relations']; //Store the total size totalSize = AllContacts.size(); //Intial adding of contacts to ContactsToShow //check the total records are more than limitSize and assign the records if((counter+limitSize) <= totalSize){ for(Integer i=0;i<limitSize;i++){ ContactsToShow.add(AllContacts.get(i)); } }else{ for(Integer i=0;i<totalSize;i++){ ContactsToShow.add(AllContacts.get(i)); } } } //Navigation methods public void beginning(){ ContactsToShow.clear(); counter=0; if((counter + limitSize) <= totalSize){ for(Integer i=0;i<limitSize;i++){ ContactsToShow.add(AllContacts.get(i)); } } else{ for(Integer i=0;i<totalSize;i++){ ContactsToShow.add(AllContacts.get(i)); } } } public void next(){ ContactsToShow.clear(); counter=counter+limitSize; if((counter+limitSize) <= totalSize){ for(Integer i=counter-1;i<(counter+limitSize);i++){ ContactsToShow.add(AllContacts.get(i)); } } else{ for(Integer i=counter;i<totalSize;i++){ ContactsToShow.add(AllContacts.get(i)); } } } public void previous(){ ContactsToShow.clear(); counter=counter-limitSize; for(Integer i=counter;i<(counter+limitSize); i++){ ContactsToShow.add(AllContacts.get(i)); } } public void last (){ ContactsToShow.clear(); if(math.mod(totalSize , limitSize) == 0){ counter = limitSize * ((totalSize/limitSize)-1); } else if (math.mod(totalSize , limitSize) != 0){ counter = limitSize * ((totalSize/limitSize)); } for(Integer i=counter-1;i<totalSize-1;i++){ ContactsToShow.add(AllContacts.get(i)); } } public Boolean getDisableNext(){ if((counter + limitSize) >= totalSize ) return true ; else return false ; } public Boolean getDisablePrevious(){ if(counter == 0) return true ; else return false ; } }
If you copy paste this code in your org your output will be like the follwing image.
Comparison:
Standard pagination: You can display only the records that is strictly belongs to the object. No custom list cannot be shown. For example : you can display only the account objects no custom objects related to the account cannot be show in pagination.
Pagination using offset: You can display only records upto 2000. OFFSET keywords does not support more than 2000 records to skip in SOQL.
Pagination using list: You can parse more than 2000 records but you can query only the maximum number of records a singe SOQL can retrieve and put it in a list.
Lets get to know some lightning feature that salesforce has pushed it in Spring 15 relaese.
Lightning has Four major features
Lightning Connect.
Lightning Process Builder.
Lightning Components.
Lightning App Builder.
Lightning Connect
Used to connect salesforce with other platform easily (Surely will write a post about deep dive in connect in near future) with just some couple of clicks.The important feature is salesforce now concerns about clients data privacy which seriously affects financial industry getting into salesforce. Salesforce copies only the metadata from the client system which you are integrating with. So your data resides only in your system. For example if you are connecting a Oracle system with salesforce, the table structure in the oracle only is copied and not your data in the table.
Lightning Process Builder
You can say Lightning Process Builder is an extension of workflow. Now you replace your little coding to create and update related records using the process builder. There are so much to cover in Lightning Process Builder this is just an intro .
Lightning Components
This where developer can have some adrenaline flow. Lightning Components are using Aura framework for its UI and has client side javascript controllers . Surely there will be some learning process for developers like me who are completely started their carrier with salesforce. Java developers can easily get to know the system. Does Apex have a role in lightning ??? YES . Lightning Components use apex controllers in server side to fetch and handle data from salesforce. Lightning Components are currently in beta state.
Lightning App Builder
This tools helps us to create apps using a drag and drop interface . You can view how your app’s UI looks in mobile and tablet currently . Wearable devices like watch will come in near future. App builder is currently in Pilot phase. I do not have hands on experience with app builder . Waiting to play around with it.
If you want to learn more about lightning play this TrialHead .
Guys this is just an intro post surely you can see some post on deep dive in every topic. Have a Good Day ahead guys :)
Yesteday went to Salesforce Lightning Developer meet organised by Bangalore Salesforce Developer Group. The venue was at Tavant technologies . Getting to venue from my place was a unquie experience with my colleague .There are multiple branches they have near by so we got confused and finally reached the correct venue.
The event was scheuled from 2.00 PM - 6.00 PM (14-03-2015). We reached by 1.30 PM there. They have created a registration app which was cool that was first time in Salesforce dev meet that a developer community has automated the registration process . Salesforce gave one lighting T-shirt and a lightning sticker , Tavant gave a notbook , pen and 8 GB pendrive which was un-expected. Bangalore has the worlds largest salesforce developer community and nearly 550 people were registered for the event and 350+ attended it . This is the largest meet up salesforce seen in its develoepr meet up history :) . Cheers bangalore !!! we had created mutliple records in one shot.
Then me and my colleague waited for the event to begin before that we had some socialization with other developers then finally the event started on 2.20 PM . A short intro from the host company Tavant and lightning host Pratik M. Munot started the Lightning Intro clean and sleak with their PPT. And there comes a little refreshment a sip of coke (my fav ) .
The following topics are covered during the discussion,
Lightning Connect.
Lightning Process Builder.
Lightning Components.
Lightning App Builder.
Then they shown a simple expense app using lightining. Which was cool beacause really you can create apps in lightning speed and push it to production at lightning speed. And here comes the intresting part Hand on !!! Which was really cool most of them are getting irritated with their internet connection . We had not taken laptop so no worries :P . Hands on went well and uselful for the newbies in lightning . I already went through lighitning completely beacuse there are some lightning projects are in the queue in my work :) and i am really excited to play around with it . The hands on is familar to me and i helped couple of devs with their doubts .
Then they had cloud trivia where questions where they ask technical questions about the session and the prizes are Lightning T-Shirt and Lightning hoodies . I was Lucky and i got one T-Shirt :) Which was still in customs in bangalore airport :( ... . After the event was over they have ordered some pizzas from Dominos and pizza hut . But i missed it :( because i was busy with my socialzation with other developers.
In a word the meet up was AWESOME.
Only con i felt is people are less social than i expected :’( it has nothing to do with the event but it will be more fun if people are more social . Next time if guys are there in meet up get to know the people from other company , know their work culture , their work experience and their way of development. It helps both of them to have some fun and technical knowledge.
I shared some resource links they have shared during the meet up. I dont know weather they have taken these links down when you read this post.
Spring 15 dev org with some packages installed for workouts.
Salesforce Object Search Language (SOSL) is used to search the whole salesforce organization data. Unlike SOQL you can search data in more than one object. You can search both standard and custom object fields.
Genral syntax:
FIND 'SearchQuery' IN SearchGroup RETURNING ObjectsAndFields
SearchQuery : Is the term that is searched across the objects. You can use string , more than one string with logical operataors and wildcard search. Example : string - 'SFDC' , more than one string with logical operataors - 'SFDC OR TEST' , wildcard search - 'SFDC* ' .
SearchGroup : It is the scope of the fields to search. If not specified, the default search scope is ALL FIELDS. SearchGroup can take one of the following values.
ALL FIELDS : Search all fields in the org.
NAME FIELDS : Search only name fileds in the org.
EMAIL FIELDS : Search only e-mail fields in the org.
PHONE FIELDS : Search only the phone fileds in the org
SIDEBAR FIELDS : Search only the fileds that is associated with sidebar search.
ObjectsAndFields : Used to specify the which objects and its fileds to be returned in the query result. Its is optional. If not specified it return all the found object IDs.
Example :
FIND {Wingo} IN ALL FIELDS RETURNING Account(Name), Contact(FirstName,LastName,Department)
put this above sosl query in query editor of developer console it will return a list<list<SObject>> .
Since we have specified Account and Contact object and its corresponding fileds it returns only the mentioned objects and the correspponding column values as shown below.
Note : While using SOSL in the apex code replace the SearchQuery {} with '' .
Example Apex Snippet :
//Returns the list of account list and contact list.
List<List<sObject>> searchList = [FIND 'Wingo OR SFDC' IN ALL FIELDS
RETURNING Account(Name), Contact(FirstName,LastName,Department)];
//Extracting only account list from the query result.
Account[] searchAccounts = (Account[])searchList[0];
//Extracting only contact list from the query result.
Contact[] searchContacts = (Contact[])searchList[1];
Add pagination to display limited number of records in a VisualForce page.
Solution :
Query only limited set of records using the offset in SOQL.
Code :
Controller
Private Integer listSize=50; //listSize determines the number of records to display.
Private Integer accountCounter=0; // Determines how many records to be skipped
Private Integer accountTotalSize=0; // Stores the total number of records in the org
Public list<Account> allCompanyList = new list<Account>(); //Account list to display the current set of records
public PageReference accountList(){
if(allCompanyList !=null){
allCompanyList.clear();
}
if(accountTotalSize != 0){
accountTotalSize = [Select count() from Account ];
}
allCompanyList = [Select Id,Name from Account order by Name limit : listSize offset : accountCounter]; return null;} //account navigation methods
//Diables the previous buttons if there is no record previous than current list public Boolean getDisablePreviousAccount(){
if(accountCounter==0) return true; else return false;
}
//Diables the next buttons if there is no record next to current list public Boolean getDisableNextAccount(){
if((accountTotalSize <= listSize) || ((accountCounter + listSize) >= accountTotalSize)) return true; else return false;
}
//Displays the next set of records public void nextAccount(){
accountCounter=accountCounter+listSize; accountList();
}
//Displays the previous set of records public void previousAccount(){
accountCounter=accountCounter-listSize; accountList(); }
//Displays the last set of records irrespective of current position public void nextLastAccount(){
if(math.mod(accountTotalSize, listSize) ==0){ accountCounter = ((accountTotalSize/listSize)-1)_listSize; } else if(math.mod(accountTotalSize, listSize) !=0) { accountCounter = (accountTotalSize/listSize)_listSize; } accountList(); }
//Displays the first set of records irrespective of current position public void previousFirstAccount(){
accountCounter=0; accountList();
}