Tuesday 16 June 2015

Google Map Integration in Salesforce

VF Page Name : GMAPINT


<apex:page standardController="Account">

<script src="http://maps.google.com/maps?file=api">
</script>

<script type="text/javascript">

var map = null;
var geocoder = null;

var address = "{!Account.BillingStreet}, {!Account.BillingPostalCode} {!Account.BillingCity}, {!Account.BillingState}, {!Account.BillingCountry}";

function initialize() {
if(GBrowserIsCompatible())
{
map = new GMap2(document.getElementById("MyMap"));
map.addControl(new GMapTypeControl());
map.addControl(new GLargeMapControl3D());

geocoder = new GClientGeocoder();
geocoder.getLatLng(
address,
function(point) {
if (!point) {
document.getElementById("MyMap").innerHTML = address + " not found";
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.bindInfoWindowHtml("Account Name : <b><i> {!Account.Name} </i></b>
Address : "+address);
}
}
);
}
}
</script>
<div id="MyMap" style="width:100%;height:300px"></div>
<script>
initialize() ;
</script>

</apex:page>


Now type in URL ".../apex/GMAPINT?id=YOUR_ACCOUNT_ID".

e.g. ".../apex/GMAPINT?id=001k000001QUrSR".

Salesforce Visualforce Page Code Generator

Visualforce page code with a button click, reduces time to write VF page again and again.

Install the package : https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000Pqos

After installation just append “/apex/vfgenerator__codegenerator” in URL.






Object Name : Valid object API name (include namespace if any)
Record Type : Record type Id of object selected in Object Name
Type of Page :
  1. Edit : Code will be generated for the edit page of the object (according to “Record Type” layout if selected any).
  2. Detail : Code will be generated for the detail page of the object (according to “Record Type” layout if selected any)
  3. Custom Detail : Code will be generated for detail page according to the fields selected from UI
  4. Custom Edit : Code will be generated for edit page according to the fields selected from UI

In the above screen I have selected “Edit” as the type of page and “Account” in object, also provided my email. When I click “Generate Code” it displays like this



Just copy the code and paste it in new visualforce page. For get full formatted code enter your email address in given field.

Now lets try creating some custom visualforce page. Select “Custom Edit” in “Type of Page” and “Account” in “Object Name”. It will display a section “Select Fields”. Click on “Display Fields”, it will display all fields which are up datable by present user.