Saturday, January 28, 2017

Salesforce for Newbies



 This post is for the newbies who is looking for how to start their journey as a salesforce developer. When I started my career in Salesforce, the first help which I got is from this link - SF Dev Site. We can get all types of information like Salesforce documentation, workbooks, webinars, cheatsheets,  blogs etc., all in one place. This will give you an idea about the Salesforce products and what is required to get started.


When I started my career, we dint have such an interactive gamified site to learn salesforce. But now you the lucky people got a treasure called " Trailhead ". It is for anyone and everyone who wants to know A-Z in Salesforce. You can find trails for all levels say beginner,  intermediates and advanced developers. It is not only for the developers but it is also for the end users, marketing users, and administrators.

Then I got introduced to the Salesforce Developer Meetup group in Chennai by one of my colleague. Don’t worry if you don’t have one to find you a group. We, the community members here for you to guide you. You can find  Salesforce meetup groups from wherever you live. Here is the link on the list of meetup groups that are available -  Salesforce Meetup



So what is Salesforce meetup group and what does it give you? It is a place where you can  meet developers, business consultants, administrators, salesforce users and appexchange vendors. So what this will give you? You can learn new releases on Salesforce, some key topics, developer workshops, trailhead workshops, appexchange products and best thing is you can meet Salesforce MVPs and Evangelists from Salesforce. Loving na? J.

When you started working on a project and you got stuck up, thinking where to go and whom to ask. No worries, salesforce has Developer Forum  , Success Community, Twitter – #askforce – This twitter hashtag to ask your questions, Salesforce Stack Exchange, Stack Overflow where you can post your questions and get answers from the community members. Most of the time when I stuck up, community came up for my rescue and I learnt things from them J We have an awesome community to help the fellow community members.
    
If you want to share knowledge on Salesforce development, write blog posts. There are many blogs by our Salesforce developers which gives us lots of information on Salesforce. I would like to mention few of my favourite blogs.

Salesforce Help and Training resources is also one of the site I look up for information and this helped me a lot when I prepared for salesforce certification examinations. Like an ocean, we have lots of resources on Salesforce for the newbies. The list goes on. With this I finish up my blog post and wish you all the success in your Salesforce Journey J

Thursday, August 18, 2016

Lightning Component on GeoLocation

The main objective of this blog post is to understand the location based queries and automatic geocodes for addresses. Salesforce has introduced this feature "Automatically get Geocodes for the addresses" in Summer '16 release. This feature allows you to find the nearby accounts,track distance,location based reminders and much more. To know more about this feature please visit this link  https://releasenotes.docs.salesforce.com/en-us/summer16/release-notes/rn_general_geocodes_aloha.htm.

To get the geocodes to be automatically added to the existing records for the addresses follow this link Geocode clean rules.

Get the geocodes to your existing records in your org by following the above link. Once that is done, lets create a lightning component that will display the nearby accounts based on the user location. For which, first we need an apex class that will return the account list based on the current user's latitude and longitude. We get the list of accounts by using the location based query which is as follows,

List<Account> accountList = [Select Id,Name,BillingLatitude,BillingLongitude From Account Where Distance(BillingAddress,GeoLocation(:latitude, :longitude),'km') <10];


The above query fetches the accounts which is lesser than 10KM distance from the user's location.

We need to find the current user location by adding the following code in the controller of your component,

if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(success);
            function success(position) {
                 var lat = position.coords.latitude;
                 component.set("v.userLatitude",lat);
                 var long = position.coords.longitude;
                 component.set("v.userLongitude",long);
 }
} else {
          error('Geo Location is not supported');
}

To display the list of accounts in the map for which I used the leaflet library. I added leaflet library to the static resource and created a controller method to set the map view and multiple markers for the account.

loadMap: function(component, event, helper) {
        var lat = component.get("v.userLatitude");         var long = component.get("v.userLongitude");         var acc = component.get("v.Accounts");         setTimeout(function() {             var map = L.map('map', {zoomControl: false}).setView([lat,long], 14);             L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',             {                 attribution: 'Tiles © Esri'             }).addTo(map);         if (acc.length> 0) {                 for (var i=0; i<acc.length; i++) {                     var account = acc[i];                     var accName = acc[i].Name;                     L.marker([acc[i].BillingLatitude,acc[i].BillingLongitude]).addTo(map);             .bindPopup(accName);
         }
       }           
    });
}

Then add this component to the aura application to check for the end result. Once the aura application is loaded, a page with the map is displayed which will show the nearby accounts with marker icons and popover displaying account name. 



You can find the source code in the github link https://github.com/then90/GeoLocation-Lightning-Component

To get this component deployed to your org click the deploy to button.

Deploy to Salesforce


Monday, November 24, 2014

Design a Visualforce Mail Template


Are you looking around on "how to design a Visualforce mail template?" Let’s see how we can design the template with images and styles.

    Steps to create a Visualforce Email Template:
  1.  Administer – Communication TemplatesEmail TemplatesNew Template
  2.  Select the type of email template as Visualforce.
  3.  Select the folder where you want to store your template.     
  4.  Select the Available for use check box to make it available to users when sending mail.
  5.  Name your email template.     
  6.  Select an Encoding setting to determine the character set for the template.
  7.   Enter the Email Subject(i.e., Here I entered it as Welcome)      
  8.  Select the Recipient type (Contact, Lead and User – One who receives the mail)
  9.  If you want to merge fields in your template then select the object you want in the  Related to  Type.      
  10.  Once you click save, click edit template to write Visualforce to design the template.
      Code Snippet:
      
<messaging:emailTemplate subject="Welcome" recipientType="Contact" >
  <messaging:htmlEmailBody>
      <html>
         <body>
           <table border="0" cellpadding="0" cellspacing="0">
              <tr>
               <td><apex:imageurl="https://instanceurl/servlet/servlet.ImageServer?id=yourimagedocumentid&oid=Organizationid"
width="38" height="38"/></td>
              </tr>
          </table>
       </body> 
     </html>
  </messaging:htmlEmailBody>
</messaging:emailTemplate>






For complete code visit the github link here.

Note:
 
Add an image to the documents tab. (To add image in the Visualforce mail template)
Once saved the image, get the image URL by right click on it.
Add that image URL to the following apex tag,
<apex:image url="https://instanceurl/servlet/servlet.ImageServer?id=your imagedocumentid&oid=Organizationid" width="38" height="38"/>



Screenshot for the Visualforce Mail Template