Friday, January 20, 2012

Google Maps using Visualforce

VisualForce:

<apex:page standardController="Account" sidebar="false">
<HTML>
 <HEAD>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 
<script type="text/javascript"> 
$(document).ready(function() {  
  var myOptions = {
    zoom: 15,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControl: false
  }
  
  var map;
  var marker;
  
  var geocoder = new google.maps.Geocoder();
  //var address = "{!Account.BillingStreet}, " + "{!Account.BillingCity}, " + "{!Account.BillingPostalCode}, " + "{!Account.BillingCountry}";
  var address = "{!Account.BillingCity}";
  var infowindow = new google.maps.InfoWindow({
   content: "<b>{!Account.Name}</b><br>{!Account.BillingStreet}<br>{!Account.BillingCity}, {!Account.BillingPostalCode}<br>{!Account.BillingCountry}"
  });


  geocoder.geocode( { address: address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK && results.length) {
      if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {      
        //create map
        map = new google.maps.Map(document.getElementById("map"), myOptions);      
        //center map
        map.setCenter(results[0].geometry.location);        
        //create marker
        marker = new google.maps.Marker({
            position: results[0].geometry.location,
            map: map,
            title: "{!Account.Name}"
        });
        
        //add listeners
        google.maps.event.addListener(marker, 'click', function() {
          infowindow.open(map,marker);
        });
        google.maps.event.addListener(infowindow, 'closeclick', function() {
          map.setCenter(marker.getPosition()); 
        });        
      }
      
    } else {
      $('#map').css({'height' : '15px'});
      $('#map').html("Oops! test billing address could not be found, please make sure the address is correct.");
      resizeIframe();
    }
  });
  
  function resizeIframe() {
    var me = window.name;
    if (me) {
      var iframes = parent.document.getElementsByName(me);
      if (iframes && iframes.length == 1) {
        height = document.body.offsetHeight;
        iframes[0].style.height = height + "px";
      }
    }
  }
  
});
</script>
<style>
#map {
  font-family: Arial;
  font-size:12px;
  line-height:normal !important;
  height:250px;
  background:transparent;
}
</style>
</head> 
<body>
<div id="map"></div> 
 </BODY>
</HTML>
</apex:page>



Demo https://sfdevforce-developer-edition.na12.force.com/googleMap?id=001U0000002LdBi

Thursday, January 12, 2012

Deployment from Sandbox to Production using Change Sets

Sandbox :

Outbound Change Sets

An outbound change set contains customizations that you want to send from this organization to another organization. These customizations can include new components or modifications to existing components, such as apps, objects, reports, or Apex classes and triggers. An outbound change set can't be used to delete or rename components in another organization.
Example uses:
  • Deploy Apex classes and triggers developed in sandbox to production
  • Copy custom objects and other customizations to a sandbox without refreshing it
  • Migrate changes across environments, e.g. dev sandbox to QA sandbox to production

We need to create change sets in sandbox environment using below steps:

Step 1:
Deploy > Outbound Change Sets > New
Name : Apex and Visualforce

Step 2: 
Create new Components like (VF, Apex Class, Objects, Triggers, App, Reports, etc...) Using Add Button.
'Upload' button is disabled in the Change Set Details section. once added the component using Step 3 and 'Upload' button also enabled.



Step 3: 
Choose the component mention below screen and finally click 'Add To Change Set' button.

Step 4:
once component added, then we need to upload the component from sandbox to production using 'UPLOAD' button.


Step 5:
Once finished Step 4, It will be available shortly in Production, so that an administrator can deploy it in Production 'Inbound Change Sets'.

Production
Deploy > Inbound Change Sets > New

Inbound Change Sets

An inbound change set contains customizations sent from another organization to this one. These customizations can include new components or modifications to existing components, such as apps, objects, reports, or Apex classes and triggers. An inbound change set can't delete or rename components in this organization.Example uses:
  •     Deploy Apex classes and triggers developed in sandbox to production
  •     Apply changes from other environments to this organization, such as new objects and fields
  •     When planning to deploy on a schedule, validate pending changes ahead of time


Finally we need to Validate and Deploy it.



Monday, January 2, 2012

Salesforce PDF Links

View Document in Attachment Object using Visualforce and Apex Class

Apex Class :
//insertAttachment
public with sharing class insertAttachment {
    public blob attachVal {get; set;}
    public string attachName {get; set;}
    public Id AttachId;
   
    public insertAttachment() {
        AttachId = ApexPages.CurrentPage().getParameters().get('Id');
    }
   
    public PageReference insertNewFile() {
        try {
            delete [select Id from attachment where ParentId =: AttachId ];
            Blob b = attachVal;
            Attachment at = new Attachment(Name=attachName, body=b, ParentId=AttachId);
            insert at;           
        } catch(Exception e){ }
        return null;
    }
   
    public List<attachment> getAttachmentList() {
        List<attachment> attachList = new List<attachment>();
       if(AttachId != null) {
            string attachQry = 'Select Id, Name, Body, ParentId from Attachment where ParentId =: AttachId';
            attachList = (List<Attachment>) Database.query(attachQry);
        }
        return attachList;
    }
}
VisualForce Page:
<apex:page controller="insertAttachment">
  <apex:form >
      <apex:pageBlock >
          <apex:pageBlockButtons >
              <apex:commandButton value="Attach New File" action="{!insertNewFile}"/>
          </apex:pageBlockButtons>
          <apex:pageBlockSection >
              <apex:inputFile value="{!attachVal}" fileName="{!attachName}"></apex:inputFile>
          </apex:pageBlockSection>
      </apex:pageBlock>
      <apex:outputPanel >
      <apex:pageBlock title="Attach File List">
      <apex:repeat value="{!AttachmentList}" var="a">
          <a href="{!URLFOR($Action.Attachment.Download, a.Id)}">{!a.Name}</a> <br />
      </apex:repeat>
      </apex:pageBlock>
      </apex:outputPanel>
  </apex:form>
</apex:page>

Insert Document in Attachment Object using Visualforce and Apex Class

Apex Class :
//insertAttachment
public with sharing class insertAttachment {
    public blob attachVal {get; set;}
    public string attachName {get; set;}
    public Id AttachId;
   
    public insertAttachment() {
        AttachId = ApexPages.CurrentPage().getParameters().get('Id');
    }
   
    public PageReference insertNewFile() {
        try {
            delete [select Id from attachment where ParentId =: AttachId ];
            Blob b = attachVal;
            Attachment at = new Attachment(Name=attachName, body=b, ParentId=AttachId);
            insert at;           
        } catch(Exception e){ }
        return null;
    }
   
    public List<attachment> getAttachmentList() {
        List<attachment> attachList = new List<attachment>();
       if(AttachId != null) {
            string attachQry = 'Select Id, Name, Body, ParentId from Attachment where ParentId =: AttachId';
            attachList = (List<Attachment>) Database.query(attachQry);
        }
        return attachList;
    }
}
VisualForce Page:
<apex:page controller="insertAttachment">
  <apex:form >
      <apex:pageBlock >
          <apex:pageBlockButtons >
              <apex:commandButton value="Attach New File" action="{!insertNewFile}"/>
          </apex:pageBlockButtons>
          <apex:pageBlockSection >
              <apex:inputFile value="{!attachVal}" fileName="{!attachName}"></apex:inputFile>
          </apex:pageBlockSection>
      </apex:pageBlock>
      <apex:outputPanel >
      <apex:pageBlock title="Attach File List">
      <apex:repeat value="{!AttachmentList}" var="a">
          <a href="{!URLFOR($Action.Attachment.Download, a.Id)}">{!a.Name}</a> <br />
      </apex:repeat>
      </apex:pageBlock>
      </apex:outputPanel>
  </apex:form>
</apex:page>

Sunday, January 1, 2012

What is Salesforce?

Salesforce CRM is a web-based Customer Relationship Management (CRM) service. It allows you to create a single view of your customers and leads, coordinate your sales, marketing and customer service activities and provides an overview into how your business is operating.
You can generate, manage, and report on leads, opportunities and track results from first contact to won or lost business. You can see the results of your marketing campaigns and understand their impact using real-time analytics.
It helps to improves efficiency, reduces administration time and lets you focus more on your business by reducing the time taken to search for information by providing a centralized service.
Salesforce has several products and service categories such as Sales cloud, Service cloud, Data cloud, Collaboration Cloud (including Chatter) and Custom Cloud (Force.com).