Salesforce Ant Migration
Sep20

Salesforce Ant Migration

Ant Migration tool is used to Create and Fetch Metadata to and from an organisation.  It’s a  command-line utility by which one can upload and download Metadata components. Benefits Its very useful for creating repetitive deployment or may be a large number of components just by executing a command in an command line interface. Useful for uploading test environment with a lot of configuration settings. Manually creating Fields, Objects may take a huge amount of time when you create them by clicking with the salesforce interface. These fields can be created with one command in the Command line interface and using Package.xml file in which you specify the information about all the fields. The Name of the components we can Deploy or retrieve are as follows: Custom Fields. Objects. Workflow rules. Apex Triggers. Apex Class. Visualforce Pages. Etc. The Whole list is mentioned in this link: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_types_list.htm   Installation Download Force.com migration tool from your salesforce organisation. Go to Setup. Type “Tool” and Click on Force.com Migration tool & Toolkits. Go to the Following Link for downloading Ant: https://gs0.salesforce.com/dwnld/SfdcAnt/salesforce_ant_36.0.zip Add the bin directory to your path. Set the ANT_HOME environment variable to the directory where you installed Ant. Set the JAVA_HOME environment variable to the directory where the JDK is installed. Run command in Command line Interface:   “ant -version” to check the version and confirm the installation. Usage Create three Files: Package.xml – Which consists the specifications for the components. Package.xml <?xml version=”1.0″ encoding=”UTF-8″?> <Package xmlns=”http://soap.sforce.com/2006/04/metadata”>    <types>        <members>*</members>        <name>CustomObject</name>    </types>    <version>37.0</version> </Package> Build.properties – Which consists the Credentials of the salesforce Organisation to & from which you want to Upload/Download. Build.properties sf.usernameDownload = Sf.User@Name.com sf.passwordDownload = Password122   sf.usernameUpload = Sf.User@Name.com sf.passwordUpload = aasfde@12131QV4cWJnmdflgBRdXsWznzohG sf.serverurlDownload = https://login.salesforce.com sf.serverurlUpload = https://login.salesforce.com sf.maxPoll = 100 Note: You have to mention Security token at the end of the password of the Org in which you want to Upload the metadata.   Build.xml – This file is used to set the attributes which will be used in the Command line interface such as “Project Name”,”Property File”,”retrieveTarget folder( where Downloaded metadata info will be saved)”,”unpackaged(Package.xml file)”. Build.xml <project name=”ANT Migration” default=”test” basedir=”.” xmlns:sf=”antlib:com.salesforce”>   <property file=”build.properties” /> <property environment=”env” /> <target name=”retrieve”> <mkdir dir=”Retrieve” /> <sf:retrieve username=”${sf.usernameDownload}” password=”${sf.passwordDownload}” serverurl=”${sf.serverurlDownload}” retrieveTarget=”Retrieve” unpackaged=”unpackaged/package.xml” pollWaitMillis=”10000″ maxPoll=”100″ /> </target> <target name=”upload”> <sf:deploy purgeOnDelete=”true” username=”${sf.usernameUpload}” password=”${sf.passwordUpload}” serverurl=”${sf.serverurlUpload}” deployroot=”Retrieve” pollWaitMillis=”10000″ maxPoll=”100″ /> </target> </project> Go to the path where you stored these files and then Run commands as follows: Upload(Which you mentioned in your build.xml file as target) – For uploading components you mentioned in the Package.xml file. Retrieve– For downloading the Components information you mentioned in the package.xml file...

Read More
Salesforce Metadata API
Aug23

Salesforce Metadata API

What is Metadata ? First you need to understand data. What is data in context with Salesforce. Data is anything which is stored in a database like records related to Contacts,  Accounts, Leads Opportunity etc. Metadata : Metadata can be defined as the set of data about another data. i.e., Configuration/Code/Logic of the underlying structure which is used to store the data (Records). Another definition is you can say the database structure in which you will be saving the data.  Metadata Api for Salesforce can do several things programmatically. Some of the tasks are mentioned below: You can read, create, update, delete following components in a Salesforce organization. Custom Objects/Fields. Visualforce pages. Page Layouts. Validation rules. Apex. Workflows. Approval processes. Profiles. Reports etc. Security.                   You can configure a Salesforce organization just by running a piece of code. It means that you can create Objects,Fields,Validation,Workflows, Profiles, Reports for a particular client organization just by running the piece of code so that you need not do all the customisation settings manually which will consume time if you have to do that several times for different clients for the same configuration settings. You can also take the backup of your organization customisation settings just by fetching the metadata WSDL from your Salesforce org. For this You need to click setup>type API-Click on API >Click Generate metadata WSDL and download the xml file. There are two types of Metadata Api calls: Synchronous – This will give the result immediately as soon as you call a method. Asynchronous – This will not give result immediately, it will take time. Asynchronous : There are four types of methods which we can use: Create();   Update(); Upsert(); Delete(); We will discuss only for synchronous method. Synchronous : There are five types of methods which we can use: (i) createMetadata(); saveResult[] = metadataConnection.createMetadata(Metadata[] metadata); (ii) readMetadata(); readResult = metadataConnection.readMetadata(string metadataType, string[] fullNames); (iii)updateMetadata(); saveResult[] = metadataConnection.updateMetadata(Metadata[] metadata); (iv)upsertMetadata(); spsertResult[] = metadataConnection.upsertMetadata(Metadata[] metadata); (v)deleteMetadata(); seleteResult[] = metadataConnection.delete(string metadataType, string[] fullNames); All these classes saveResult, readResult, upsertResult, deleteResult comes from a main class that is MetadataService.cls in which all the relevant methods are present to function Read, Create, Update, Upsert or Delete properly. Now I will demonstrate how to create Custom components. You can use following methods to create components: (A) To Create a Custom Object: You need to add this code to your class which you are using and call this method via class name to create the object. Note: MetadataService is also a class which have several methods and used in these methods. Create a Custom Object: public static void createObject() {  ...

Read More
Learning Salesforce in India
Aug01

Learning Salesforce in India

Its a casual day and some newbie in Salesforce asked me “Is Learning Salesforce in India worth”. Mine and everyone’s first answer would be “Do you have the budget to either fly to a western country or pay USD 2000 fees of Salesforce Training online?” Well that is not the cross question what I replied back with. I thought of giving an elaborative answer and wrote this blog. Here are few points I believe “Why Learning Salesforce in India is worth” Young India: We have 1000s of Salesforce enthusiast every year joining in the Salesforce community and 100s of Salesforce Experts in India. With Salesforce everyone is trying to show off and learn as much as possible. This thinking process of an Indian helps other to jump into the competition. With competition one either fails and learns or succeeded and teach others. Salesforce Community: I can see at least 40+ Salesforce Users and Developers group in India and several new groups coming up every day. In past 2 years there is an almost 300% rise in number of registered groups in India. These communities can definitely help you with learning Salesforce and several Recruiters target for bright minds in these groups. Salesforce in India: Salesforce is taking interest. With new announcements from Salesforce investing in hiring Developers and Experts in India it gives a better opportunity for every newbie/fresher. Thus a reason to Learn Salesforce in India is prominent. I believe in No Pain No Gain. To learn anything you should not expect spoonfeeding instead you should be brave and intelligent enough to go out and search for knowledge. The entire social media, youtube, blogs, trail heads, Quora is filled up with information and learning material. www.ajaydubedi.com Startups Hire Freshers: Several Companies startups like mine(www.cloudanalogy.com) are trying to hire freshers and train them in Salesforce. These companies give awesome opportunity to newbies and experienced upto a certain level to get trained and be productive in Salesforce. Salesforce Consultants and Admins: People who are not from a coding background but good at other areas like communication, consulting Testing, Problem solving and also be part of salesforce. Majority of Salesforce business runs around Admins and Consultants Read my blogs regularly to know about the 7th most important reason.www.ajaydubedi.com   I would request everyone reading this blog to share their experience with different Training institutes in India. Name of Institute, Fees, Time duration and Quality of Training. Submit this detail in the comments and win the following Salesforce development...

Read More
Day 4 Assignment (VFpage, JavaScript)
Jan26

Day 4 Assignment (VFpage, JavaScript)

I have created a 5 Days Salesforce based programming and configuration assignments for practice and improving your skills. This blog have the third day assignment. Since all the blogs are related I would recommend beginners to start from Day 2 assignment and not directly jump to this blog.     Requirement: We have a university “St Judes” which wants its salesforce account to get configured by us. Following are the requirement of this client.  1. Create a VF page listing a quick search for all the Professors. A quick search will be a on key press VF page. If the users press “V” in the field all the professors with starting name “V” like Vineet, Vinay .. etc will list down in the page. AJAX Toolkit Developer Guide SOLUTION: VisualForce Page Visual force page code. <apex:page id="page" controller="Basic2SearchProfessorsDynamically" sidebar="false"> <apex:form id="form"> <apex:pageMessages id="errors" /> <apex:pageBlock title="Find Me A Professor!" mode="edit" id="block"> <table width="100%" border="0"> <tr> <td width="200" valign="top"> <apex:pageBlock title="Parameters" mode="edit" id="criteria"> <script type="text/javascript"> function doSearch() { searchServer(document.getElementById("profName").value, document.getElementById("mail").value, document.getElementById("YOE").value ); } </script> <apex:actionFunction name="searchServer" action="{!runSearch}" reRender="results,errors,debug"> <apex:param name="profName" value="" /> <apex:param name="mail" value="" /> <apex:param name="YOE" value="" /> </apex:actionFunction> <table cellpadding="2" cellspacing="2" id="table"> <tr> <td style="font-weight:bold;">Name<br /> <input type="text" id="profName" onkeyup="doSearch();" /> </td> </tr> <tr> <td style="font-weight:bold;">Email<br /> <input type="text" id="mail" onkeyup="doSearch();" /> </td> </tr> <tr> <td style="font-weight:bold;">Year Of Experience<br /> <input type="text" id="YOE" onkeyup="doSearch();" /> </td> </tr> </table> </apex:pageBlock> </td> <td valign="top"> <apex:pageBlock mode="edit" id="results"> <apex:outputPanel id="panel" rendered="true"> <apex:pageBlockTable value="{!profList}" var="prof"> <apex:variable value="{!0}" var="cnt"/> <apex:column headerValue="Action"> <apex:commandButton value="Delete" style="background: red; color: white;" action="{!deleteProf}" rendered="true" reRender="panel"> <apex:param value="{!prof.Id}" name="profToRemove" assignTo="{!rowToRemove}"/> <apex:param name="index" value="{!cnt}"/> </apex:commandButton> <apex:variable var="cnt" value="{!cnt+1}"/> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Professor Name" action="{!toggleSort}" reRender="results"> <apex:param name="sortField" value="Name" assignTo="{!sortField}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!prof.Name}" /> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Professor Email" action="{!toggleSort}" reRender="results"> <apex:param name="sortField" value="Email__c" assignTo="{!sortField}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!prof.Email__c}" /> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Year of Experience" action="{!toggleSort}" reRender="results"> <apex:param name="sortField" value="Year_Of_Experience__c" assignTo="{!sortField}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!prof.Year_Of_Experience__c}" /> </apex:column> </apex:pageBlockTable> </apex:outputPanel> </apex:pageBlock> </td> </tr> </table> <apex:pageBlock title="Debug - SOQL" id="debug"> <apex:outputText value="{!debugSoql}" /> </apex:pageBlock> </apex:pageBlock> </apex:form> </apex:page> 2. The quick search will have a delete button beside each Professor row. This will delete a particular Professor. Once the Professor is deleted all the students from the Professors Course will get de-enrolled(Removed)  SOLUTION: VisualForce Page Controller public with sharing class Basic2SearchProfessorsDynamically { //the soql without the order and limit private String soql {get; set;} //the row to be delete public String rowToRemove{get; set;} //the collection of professors to display public List<Basic2Proffessor__c> profList {get; set;} //Required Professor(Dummy Professor) Basic2Proffessor__c reqProf = [SELECT Id, Name FROM Basic2Proffessor__c WHERE Name = ‘Professor Required’]; //the current sort direction. default...

Read More
Day 2 Assignment  Part-2
Dec22

Day 2 Assignment Part-2

I have created a 5 Days Salesforce based programming and configuration assignments for practice and improving your skills. This blog have the second day assignment part-2. The assignment is in format of a typical salesforce requirement, comparable to a small size project. To design and develop this project it is recommended that you register a fresh salesforce developer org. Please go through the requirements which are well defined and should be easily understood if you have a basic understanding of salesforce sales and service cloud. Your data model design or solution approach to the requirements might be different from the answers provided here. Every solution is correct if you are fulfilling all the requirements. It is highly recommended before working on this blog you must have completed the part-1 blog. Requirement: We have a university “St Judes” which wants its Salesforce account to get configured by us. Following are the requirement of this client.   2.1. A Course will have list of all the Students in it enrolled. Click here to learn more You don’t know it yet that you have already completed it. You just need to make them viewable from page layout and you know it now how to do it.   2.2.  Professor fields “DOB” “Years of Experience”, “Expertise”        Multipicklist(Java,English,Mechanical,..etc) Click here to learn more It is again a data model configuration question to create fields.   2.3. The University will display all the Professors experties. Hint: In University detail page your new section must look like—>   Click here to learn more We have to create a Inline Visualforce page to solve this problem. And here is the controller class for this problem: Class: public with sharing class ListOfProfessorInUniversity { public boolean flag{get; set;} public string ids{get; set;} public ListOfProfessorInUniversity(ApexPages.StandardController controller){ ids = controller.getId(); } public List<Professor__c> getAllProfessor() { List<Course__c> allCourses = [SELECT Name, Professor_del__c, Select_University__c FROM Course__c WHERE Professor_del__c != NULL AND Select_University__c =: ids]; Set<Id> CourseIdList = new Set<Id>(); for (Course__c courses : allCourses) { CourseIdList.add(courses.Professor_del__c); } system.debug(‘>>>>>>>>>>’ +CourseIdList); List<Class__c> allClass = [SELECT Name, Class_Teacher__c FROM Class__c WHERE Class_Teacher__c !=: CourseIdList OR Id IN : CourseIdList]; Set<Id> classIdList = new set<Id>(); for (Class__c classes : allClass){ classIdList.add(classes.Class_Teacher__c); } system.debug(‘>>>>>>>>>>’ +classIdList); List<Professor__c> professors = [SELECT Name, email__c, Experience__c, Expertise__c FROM Professor__c WHERE Id IN : CourseIdList OR Id IN : classIdList]; system.debug(‘*****************’ +professors); Set<Professor__c> IdSet = new Set<Professor__c>(); idSet.addAll(professors); system.debug(‘>>>>>>>>>>>’ + idSet); if (NULL != IdSet){ flag = true; } else{ flag = false; } return professors; } }   and here is the Visualforce page for this controller:   <apex:page standardController=”St_Judes_University__c” extensions=”ListOfProfessorInUniversity”> <apex:sectionHeader title=”All Professors Related to University”/> <apex:outputpanel rendered=”{!flag}” > These are the students which are teached by teacher. </apex:outputpanel> <apex:pageBlock > <apex:pageBlockTable value=”{!AllProfessor}” var=”professor”> <apex:column value=”{!professor.Name}”/> <apex:column value=”{!professor.email__c}”/> <apex:column value=”{!professor.Experience__c}”/> <apex:column value=”{!professor.Expertise__c}”/> </apex:pageBlockTable> </apex:pageBlock> </apex:page>   Now your work is done and now you just need to add the Visualforce page in the page layout section.   2.4. When ever a new student is added he is supposed to be registered at-least in a Course and a Class. Click here to learn more For this you must create the field on Student of Course mandatory and in Course the Class field make it mandatory too. That’s it your work is done.   2.5. When a new...

Read More