October 28, 2014

Copying Billing Address to Shipping Address Using Custom Functionality

Description:
  • Billing Address and Shipping Address are the fields present in the Address Information of Account, Contact object in Salesforce.
  • Most probably both addresses will be similar and there is a option for us “Copying Billing Address to Shipping Address” in the Account, Contact object so that by clicking that address will be copied automatically.
  • Now the scenario is creating visual force page for the Copying of Billing Address to Shipping Address without using the standard functionality.

Step 1: Create Visual force Page
https://c.ap1.visual.force.com/apex/ BillingtoShipping
VF Page Name: BillingtoShipping 
Visualforce Code:
 <apex:page controller="Billing_Shipping_Con" >
   <apex:form id="myform">
    <script type="text/javascript">
        function addressCopy(bstreet1, bcity1, bstate1, bPostalCode1, bcountry1, sstreet1, scity1, sstate1, SPostalCode1, scountry1) {
    document.getElementById(sstreet1).value = document.getElementById(bstreet1).value;
    document.getElementById(scity1).value = document.getElementById(bcity1).value;
  document.getElementById(sstate1).value = document.getElementById(bstate1).value;
document.getElementById(SPostalCode1).value=document.getElementById(bPostalCode1).value;
 document.getElementById(scountry1).value = document.getElementById(bcountry1).value;
     return false;
  }
    </script>
     <apex:pageBlock title="Billing Address to Shipping Address" id="page">
        <apex:pageBlockSection columns="2" id="pgblock">
          <apex:facet name="header">
                   <span class="pbSubExtra">
                        <span class="bodySmall">
    <a href="javascript:addressCopy('{!$Component.bstreet1}','{!$Component.bcity1}', 
                 '{!$Component.bstate1}','{!$Component.bPostalCode1}',
              '{!$Component.bcountry1}','{!$Component.sstreet1}','{!$Component.scity1}', 
       '{!$Component.sstate1}','{!$Component.SPostalCode1}','{!$Component.scountry1}')">
                      Copy Billing Address to Shipping Address</a>
                        </span> </span>
                   <h3>Address Information<span class="titleSeparatingColon">:</span></h3>   
            </apex:facet>
          <apex:inputTextarea label="Billing Street" value="{!BStreet}" id="bstreet1" />
          <apex:inputTextarea label="Shipping Street" value="{!SStreet}" id="sstreet1" />
          <apex:inputText label="Billing City" value="{!BCity}" id="bcity1"/>
          <apex:inputText label="Shipping City" value="{!SCity}" id="scity1"/>
          <apex:inputText label="Billing State" value="{!BState}" id="bstate1"/>
        <apex:inputText label="Shipping State" value="{!SState}" id="sstate1"/>
         <apex:inputText label="Billing Postal Code" value="{!BZip}" id="bPostalCode1"/>
          <apex:inputText label="Shipping Postal Code" value="{!SZip}" id="SPostalCode1"/>
          <apex:inputtext label="Billing Country" value="{!BCountry}" id="bcountry1"/>
          <apex:inputtext label="Shipping Country" value="{!SCountry}" id="scountry1"/>
        </apex:pageBlockSection>
     </apex:pageBlock>
  </apex:form>
</apex:page>

Step 2: Write a  Custom Controller for the visualforce page
Class Name: Billing_Shipping_Con
Controller:
public class Billing_Shipping_Con {
    public String BCountry { get; set; }
    public String BZip { get; set; }
    public String BState { get; set; }
    public String BCity { get; set; }
    public String BStreet { get; set; }
    public String SCountry { get; set; }
    public string SZip { get; set; }
    public String SState { get; set; }
    public String SCity { get; set; }
    public String SStreet { get; set; }
}

Step 3: Output of the Page


Step 4: Enter the data in the Billing Address (i.e. left side of the page) and click the Copy Billing Address to Shipping Address link.


Step 5: Now the data is copied to Shipping address.


 Interview Questions
  •  Difference between Standard Controller and Custom Controller?
  •  Difference between <apex: inputtext> and <apex: inputtextarea> tags?
  •  How many Controllers in Visualforce page?
  •  What is <apex:facet>?
  •  What is Javascript?



October 27, 2014

Disable Reset My Security Token option in Salesforce

Description
  • For Enterprise, Performance, Unlimited, Developer, and Database.com editions, we can set the Login IP Range addresses from which users can log in on an individual profile.
  • Users outside of the Login IP Range set on a profile can’t access your Salesforce organization.
  • We can remove the requirement for the security token based on IP address, either at the organization level or the Profile level.
  • If all of the users of this app are the same Profile, add a Login IP Range (at the Profile, not Organizational level) that includes the IP addresses they will be using. You could even add the range 0.0.0.0 through 255.255.255.255

Steps to Disable the Option:

Step 1 : Goto -> My Settings -> Personal

Here you can see Reset My Security Token option



Step 2 : Goto -> Setup -> Manage Users -> Profiles -> Login Ip Ranges



Step 3 : Enter the Start IP, End IP Address and save it



Step 4 : Check it whether the Reset Security option is disable or not.

Output: The option is disable now.



Interview Questions
  • Why Login IP Ranges is required in Salesforce?
  • What is the use of Security Token?

October 26, 2014

Deleting child records automatically when parent records are deleted using Lookup Relationship

Description

Generally we have relationships in Salesforce i.e. Master-Detail and Lookup Relationships. The main difference between these two relationships is when we delete parent record the child record will delete automatically in Master-Detail but not in Lookup. Now the scenario is, by using Lookup relationship also the records should delete as in Master-Detail. This we can achieve by writing trigger on Parent Object.

Steps for the scenario

Step 1: Create Custom Object,Fields and Records

Object Name : Parent__c



Step 2 : Create Custom Object,Fields and Records
Object Name : Child__c



Step 3 : Create Lookup Relationship between the two objects(i.e. Parent and Child) which you have created.



Step 4 : Write Trigger on Parent Object. Check the active check box



Step 5 : Delete the record in Parent object and check the child object records

Output:






Interview Questions

  • What is the difference between Master-Detail and Lookup Relationship?
  • What is the relationship between Account and Contact objects?
  • What is Trigger and its syntax ?
  • How many events present in Trigger?
  • What is the difference between Trigger.new and Trigger.old?
  • Why we are using before event in this Trigger?
  • Why we are using Trigger.old in this scenario?