Salesforce Google Map Integration
Sep02

Salesforce Google Map Integration

Google Map Integration Integrating google maps into Salesforce                         Description of the requirement: Starting with description of the Project we have worked upon, there’s an app we created for searching and showing Account’s location on the Map and knowing a route map from one location to another location via some locations(Checkpoints).                            Solution we came with: For the requirement we used Google maps api which is in Javascript format. There are some predefined javascript functions used in the Google map api. We used Google Maps library whoz source is coming from a link i.e., “https://maps.google.com/maps/api/”.                                 There are several Javascript functions we used here which are as follows: Function to get the current location of the User by using the browser’s location. Get the current location of the User by using the browser’s location:                  var geocoder;            var map;            function initialize(){                geocoder = new google.maps.Geocoder();                    console.log(lon+’***latlon–‘+lat );                var latlng = new google.maps.LatLng(lat, lon);                console.log(‘***latlon–‘+latlng);                var myOptions = {                  zoom: 12,                  center: latlng,                  mapTypeId: ‘roadmap’ /* ,                  mapTypeId: google.maps.MapTypeId.TERRAIN */                }                                         map = new google.maps.Map(document.getElementById(“map”), myOptions);   Here we used “google.maps.Geocoder();” to access Google Maps API geocoding service.    We created an apex class method which will take Address of the Account as a string and will return a Geolocation for that address i.e., in Latitude and longitude of the string  address passed in the function as a parameter to it.   Suppose a string will be as shown below: public Account accObj{get;set;} // This is a getter setter method contains Account record. String address = accObj.BillingStreet+accObj.BillingCity+accObj.BillingPostalCode+accObj.BillingCountry;   Now we used the below method to get the Latitude & Longitude: Get the Latitude & Longitude: public static String getLatitudeLongitude(String address){        String location=”;         try{                Double latitude = null;                Double longitude = null;                            Http httpGetRequest = new Http();                HttpRequest httpReq = new HttpRequest();                system.debug(‘******Address—‘+address);                address=address.replaceAll(‘ ‘,’+’);                address = address.replace(‘\r\n’, ‘ ‘);                        address = address.replace(‘\n’, ‘ ‘);                        address = address.replace(‘\r’, ‘ ‘);                        system.debug(‘******After       Address—‘+address);       httpReq.setEndpoint(‘https://maps.googleapis.com/maps/api/geocode/json?key=’+key+’&address=’ +address + ‘&sensor=false’);                                                                                            //Authentication to google api            httpReq.setMethod(‘GET’);            httpReq.setTimeout(6000);            HttpResponse httpResponseAddress = httpGetRequest.send(httpReq);                system.debug(‘res body: ‘ + httpResponseAddress.getBody());                JSONParser parser = JSON.createParser(httpResponseAddress.getBody());                                    while...

Read More
Salesforce REST integration JAVA Application
Jun15

Salesforce REST integration JAVA Application

Force.com REST API PROBLEM: How to connect/query/SOQL to any Salesforce.com account using REST API and JSON Payloads. This application will provide a great help in testing all kinds of Salesforce object queries in SOQLs and creating or updating various Salesforce custom as well as standard objects by the help of JSON Stings. SOLUTION: We build a small java based application which will achieve the following objectives. User enters the Client Id, Client Secret and the file name. Connect to the Salesforce Account using the above information. After a Successful connection the User can do any of the below Operations. Enter a SOQL Query to view the Results/Working. Enter a JSON String to Create/Update/Delete a Salesforce Object (Standard/Custom). The Solution is divided into various Blogs having all the Screenshots, Data flow diagrams, Flowcharts and Java/Html source codes. You can easily understand all the steps and can create the application on your end by the help of the various resources. The solution gives an in depth understanding of all the steps of REST authorization from Salesforce and generation of the access Token for further REST calls. The core part of our solution is the initial authorization of the Rest Application. User can also test almost any Salesforce object query and can also transfer the Record information to be created on salesforce in the JSON String format.   REQUIREMENTS: Apache Server, Eclipse IDE and Salesforce Developer Edition account. The User should also have some information about Salesforce force REST cUrls or it can be learnt almost instantly while testing the Rest Application being created in this blog. WE PROVIDE: We provide all the Screenshots, Data flow diagrams, Flowcharts and Java/Html source codes, URLs and Steps to perform. http://developer.force.com/REST   STEP 1. Enable Remote Access in SFDC. Log in to Salesforce.com with your developer account, navigate to Top Right corner, Your Name ➤ Setup ➤ Develop ➤ Remote Access, and click New to create a new remote access application if you have not already done so.   If you are running the application server on your own machine (the most common case for a development environment), then the URL will look like https://localhost:8443/Rest/oauth/_callback. After clicking Save, you will see your new application’s credentials: Click the link to reveal the consumer secret. Note – OAuth 1.0 terminology is currently used in the Remote Access screen. The OAuth 2.0 specification uses ‘client’ in place of ‘consumer’.Copy the consumer key and consumer secret, we will use them inorder to connect and receive the Authorization token.:   STEP 2. Enable SSL in Apache. If you already have an Apache Tomcat server with SSL Enable then Jump to...

Read More