Monday, April 27, 2015

Salesforce to Salesforce Integration using rest api

HttpRequest req=new HttpRequest();
    req.setMethod('POST');
    req.setEndpoint('https://login.salesforce.com/services/oauth2/token');
    String str1='grant_type=password&';
    String str2='client_id=3MVG9Y6d_Btp4xp43IbeBaeCHQlfOiMTB3JhATKM9alz1Za2J.6ZGtnUdaDstYHy_uzU0deVIznH5NX4h3e7i&';
    String str3='client_secret=464548859367584338&';
    String str4='username=thimma.castiron@gmail.com&';
    String str6='password=XXXXXXXXXXXXvtkdno8cYOq8H1Noa0uN4Jpu';
    String str=str1+str2+str3+str4+str6;
    req.setBody(str);
    System.debug('HttpRequest :' +req);
    HttpResponse response = null;
    Http http = new Http();
    response = http.send(req);
    system.debug('@@@@@@@@@@@'+response.getBody());

    string srg=response.getBody();
system.debug('&&&&&srg&&&&'+srg);
    string srg1=srg.substringAfter( 'access_token ' );
system.debug('&&&&&&&&&'+srg1);
Map<String, Object> m =
   (Map<String, Object>)
      JSON.deserializeUntyped(srg);

system.debug('%%%%%%%%%%%%%%%%%'+m);
Object acesstoken=m.get('access_token');
system.debug('%%%%%%%%%acesstoken%%%%%%%%'+acesstoken);

string xyz=(string)acesstoken;


system.debug('%%%%%%%%%acesstoken x%%%%%%%%'+xyz);


//--------------------------------------------------------------------------------------------------------------------------------------------------------

HttpRequest req1=new HttpRequest();
    req1.setMethod('POST');
req1.setEndpoint('https://ap1.salesforce.com/services/async/29/job');
req1.setHeader('Content-Type','application/xml');
req1.setHeader('X-SFDC-Session', ' ' + UserInfo.getSessionId());
//req1.setHeader('x-SFDC-Session:',xyz);
String str9='<?xml version="1.0" encoding="UTF-8"?><jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload"><operation>query</operation><object>Account</object><contentType>CSV</contentType></jobInfo>';

req1.setBody(str9);
HttpResponse response1 = null;
    Http http1 = new Http();
    response1 = http1.send(req1);
system.debug('@@@@@responsejflsflsdflsdfks@@@@@@'+response1.getBody());

 string srg12=response1.getBody();
JSONParser parser = JSON.createParser(response1.getBody());


string ss=UserInfo.getSessionId();

system.debug('%%%%%%%%%parser %%%%%%%%%%'+parser );

  DOM.Document doc = response1.getBodyDocument();


system.debug('%%%%%%%%%parser  doc %%%%%%%%%%'+doc );

 Dom.XMLNode address = doc.getRootElement();


string id1;
     for(DOM.XMLNode xmlnodeobj:doc.getRootElement().getChildElements()){
          if(xmlnodeobj.getName()=='id')
          {
 id1=xmlnodeobj.getText();
          }


       }
 
  system.debug('%%%%%%%$$$$$$$$$$$$$$$$$$$$$$$$$$'+id1);
 
 
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  
 
 


 HttpRequest req2=new HttpRequest();
    req2.setMethod('POST');

//'https://ap1.salesforce.com/services/async/29/job/75090000002MUlPAAW/batch'


string sss='https://ap1.salesforce.com/services/async/29/job/' +id1+'/batch';
req2.setEndpoint(sss);
req2.setHeader('Content-Type','text/csv');
req2.setHeader('X-SFDC-Session', ' ' + UserInfo.getSessionId());

String str11='select name ,id from account ';

req2.setBody(str11);
HttpResponse response2 = null;
    Http http2 = new Http();
    response2 = http2.send(req2);
system.debug('@@@@@@@@@@@'+response2.getBody());



 DOM.Document doc1 = response2.getBodyDocument();


system.debug('%%%%%%%%%parser  doc %%%%%%%%%%'+doc );
 
  address = doc1.getRootElement();

string batchid;

     for(DOM.XMLNode xmlnodeobj1:doc1.getRootElement().getChildElements()){
          if(xmlnodeobj1.getName()=='id')
          {
 //id1=xmlnodeobj1.getText();
 batchid=xmlnodeobj1.getText();
          }


       }
 

system.debug('%%%%%%%%%jobid  doc %%%%%%%%%%'+id1 );

system.debug('%%%%%%%%%batchid  doc %%%%%%%%%%'+batchid );

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

HttpRequest req3=new HttpRequest();
    req3.setMethod('GET');
//sss=sss+'/'+batchid+'/result';
//https://ap1.salesforce.com/services/async/29/job/75090000002MVvuAAG/batch/75190000004CCiZAAW/result
//req3.setEndpoint('https://ap1.salesforce.com/services/async/29/job/75090000002MVvuAAG/batch/75190000004CCiZAAW/result');

system.debug('################################################################'+sss);

system.debug('%%%%%%%%%jobid  doc %%%%%%%%%%'+id1 );

system.debug('%%%%%%%%%batchid  doc %%%%%%%%%%'+batchid );



string id2=string(id1);
string batchid2=string(batchid);
system.debug('%%%%%%%%%jobid2  doc %%%%%%%%%%'+id2 );

system.debug('%%%%%%%%%batchid2  doc %%%%%%%%%%'+batchid2 );

sss='https://ap1.salesforce.com/services/async/29/job/' + id2+'/batch'+'/'+ batchid2+'/result';
req3.setEndpoint(sss);
req3.setHeader('X-SFDC-Session', ' ' + UserInfo.getSessionId());

HttpResponse response3 = null;
    Http http3 = new Http();
    response3 = http3.send(req3);
system.debug('@@@@@@5555555555555555555555555555555555555555555555555@@@@@'+response3.getBody());
 DOM.Document doc2 = response3.getBodyDocument();

  address = doc2.getRootElement();



     for(DOM.XMLNode xmlnodeobj2:doc2.getRootElement().getChildElements()){
          if(xmlnodeobj2.getName()=='result')
          {
 id1=xmlnodeobj2.getText();
          }


       }


//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


HttpRequest req4=new HttpRequest();
    req4.setMethod('GET');

sss=sss+'/'+id1;
req4.setEndpoint(sss);

req4.setHeader('X-SFDC-Session', ' ' + UserInfo.getSessionId());

HttpResponse response4 = null;
    Http http4 = new Http();
    response4 = http4.send(req4);
system.debug('@@@@@@@@@@@'+response4.getBody());

Integration


/**     Description    :    Ths class will Integrate Salesforce with Klout. 



**/




public with sharing class KloutWithSalesforceTwitterRatingUpdate {




  //Wrapper Class for First Response


  public class firstResponseParsingWrapper {


   


    //Response variables


    public String id;


    public String network;


   


    //Constructor


    public firstResponseParsingWrapper(String id, String network) {


      this.id = id;


      this.network = network;


    }


  }




  //Wrapper for second response


  public class KloutFinalResponseWrapper {


   


    //Score from the response


    public String score;


   


    //Constructor


    public KloutFinalResponseWrapper(String score) {


      this.score = score;


    }


  }






  //account


  public Account account { get; set; }


  public String twitterScore { get; set; }




  //constructor


  public KloutWithSalesforceTwitterRatingUpdate(ApexPages.StandardController stdController){


   


    //Initiallize


    twitterScore = '';




    //account record


    this.account = (Account)stdController.getRecord(); 


  }


   


    //Method for making callout and populating values retrieved from response is going to be diplayed on Visualforce Page


    public void kloutTwitterRating() { 




    try {


      //Http


      Http http = new Http();


     


      //Request


      HttpRequest req = new HttpRequest();


      req.setEndpoint('http://api.klout.com/v2/identity.json/twitter?screenName='+ twitterScore +'&key=4j6pe8zamj4dmh2by9tzv5sc');


      req.setMethod('GET');


     


      //Send request


      HTTPResponse firstResponse = http.send(req);


      System.debug('res::::::' + firstResponse.getBody());


     


      //Body


      String body = firstResponse.getBody();


     


      //Deserializing response


      KloutWithSalesforceTwitterRatingUpdate.firstResponseParsingWrapper parsedResponse = (KloutWithSalesforceTwitterRatingUpdate.firstResponseParsingWrapper)JSON.deserialize(body, firstResponseParsingWrapper.class);


      System.debug('parsedResponse:::::::' + parsedResponse);


     


      //String for id in response


      String responseId = parsedResponse.id;


      System.debug('responseId:::::::' + responseId);


   


      //Second request for score


      HttpRequest finalReq = new HttpRequest();


      finalReq.setEndpoint('http://api.klout.com/v2/user.json/'+ responseId +'/score?key=4j6pe8zamj4dmh2by9tzv5sc'); 


      finalReq.setMethod('GET');


     


      //Send request


      HTTPResponse lastResponse = http.send(finalReq);


      System.debug('lastResponse::::::' + lastResponse.getBody());


     


      //Body


      String finalBody = lastResponse.getBody(); 


     


      //Deserializing response


      KloutWithSalesforceTwitterRatingUpdate.KloutFinalResponseWrapper parseFinalResponse = (KloutWithSalesforceTwitterRatingUpdate.KloutFinalResponseWrapper)JSON.deserialize(finalBody, KloutFinalResponseWrapper.class);


      System.debug('parseFinalResponse::::::' + parseFinalResponse);


     


      //Assigning value


      account.Twitter_Rating__c = parseFinalResponse.score;


      account.Validate_Score_Successfully__c = true;


      account.Validate_Score_Last_Attempt__c = date.today();   


   




    }catch (exception e) {


     


      //Error messages


      ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'UserName Not Found, Sorry Try Again');


            ApexPages.addMessage(errormsg);


      System.debug('e:::::::' + e); 


    }   


   


  }


}

Monday, April 13, 2015

OOP'S in Salesforce

The core of the pure object-oriented programming is to create an object, in code, that has certain properties and methods. While designing Salesforce modules, we try to see whole world in the form of objects. For example a car is an object which has certain properties such as color, number of doors, and the like. It also has certain methods such as accelerate, brake, and so on.

There are a few principle concepts that form the foundation of object-oriented programming:


Object:

This is the basic unit of object oriented programming. That is both data and function that operate on data are bundled as a unit called as object. under the next section(Class) i clearly explained about object along with example...

Class:

When you define a class, you define a blueprint for an object. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object.


public class caluclator

{

// declaring data members

integer a;

integer b;

integer c;

//delaring and implementing member methods..

public void add()

{

c=a+b;

}

public void mul()

{

c=a*b;

}

public void div()

{

c=a/b;

}


in the above program we have both data members and member methods which work on data members..its just like blue print of the program.. when ever we create object for above class will help you to get expected out put..

Not clear ?

when ever  we go to tailoring shop we will be giving our measurements as taillor will note down the measurements acording to our body length. Taking notes is nothing but class or blue print however when he stiches the real cloth acording to the measurement will give you exptected dress which is nothing but object.   

Now taking measure measurements is nothing but class and implementing the taken notes can be called as object..

How to create object..?

we need to create instance of the class by using new operator..

syntax    

classname instancename =new classname();

caluclator cal1=new caluclator();

How to accesss methods of the class?

instancename.methodname();

cal1. add();

 cal1.mul();

cal1.div();


Abstraction:

Data abstraction refers to, providing only essential information to the outside world and hiding their background details, i.e., to represent the needed information in program without presenting the details.


In the below example code  getvalues() method is not implemented in the same class to hide the background details, complextiy of  that particuler method will be implemented in the child class.


public abstract class parent 

{

public abstract void getvalues()

}

Abstract methods will not have body,  these methods will contain only defination.  In the below code getvalues() method is not implemented in the parent class, implementation is done at child level. unlike Interface its not manditory to implement the abstract method .

public abstract class parent

{

public abstract void getvalues()

}


public class child extends parent

{

private integer pvt-ch-mem;

public override void getvalues()

{

syatem.debug'pvt ch mem'+pvt-ch-mem);

}

}

public class test

{

public static testmethod void main()

{

child c1=new child();

c1.getvalues();

}


}

To declare method as abstract we need to use abstract keyword infront of parent class and the intended method in the same class

Not clear ?

No problems...

suppose you need to plan a marriage function. first step what you will do is you will note down what the things you suppose to plan..  Ex : FoodServing();

                                        Decoration();

                                        Drinks().....etc..

public abstract  class marriage

{

abstract  FoodServing();

abstract  Decoration();

 abstract  Drinks().....etc..

}

in the above program you dont need to expose how foodserving will be,what drinks need to serve ....its just like plan to implement...


Encapsulation:

Encapsulation is placing the data and the Mehods that work on that data in the same place. While working with procedural languages, it is not always clear which methods work on which variables but object-oriented programming provides you framework to place the data and the relevant methods  together in the same object.

------------------------------------------------------------------------------------------------------------------------------------------------------------------

simple bank program to explain encaplsulation..

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

public class account

{

string name;

Integer ac-no;

interger bal;

pablic account()

{

name='no name';

ac-no=0;

bal=0;

}

pablic account(string name, integer ac-no, integer bal)

{

this.name=name;

this.ac-no=ac-no;

this.bal=bal;

}

pubilc void setvalues(string name, integer ac-no, integer bal)

{this.name= name;

this.ac-no=ac-no;

this.bal=bal;

}

public void deposit(integer amount)

{

bal+=amount;

}

public void withdraw(integer amount)

{

bal-=amount;

}

public void showbalance()

{

system.debug('balance rs='+bal');

}

public void getvalues()

{

system.debug('name='+name');

system.debug('ac-no='+ac-no');

system.debug('balance rs='+bal');

}

}

global class test

{

public static testmethod void main()

{

account acc1=new account('ashok', 100, 4000);

acc1.diposit(10000);

acc1.showbalance();

acc1.withdraw(15000);

acc1.getvalues();

account acc1=new account();

acc2.setvaluce('basu',101, 50000);

acc2.getvalues();

}

}


In the above program datamembers (string name;Integer ac-no;interger bal;) and Member methods  1)pubilc void setvalues(string name, integer ac-no, integer bal)   2)public void deposit(integer amount)  3)public void deposit(integer amount)   4)public void withdrow(integer amount)  5)public void showbalance()  6)public void getvalues()..  are binding together to perform some actions... In a simple way whenever datamembers are used in the member methods in the single class along with access modifiers(public, private,protected and global)   can be called as Encapsulation.


Inheritance:

One of the most useful aspects of object-oriented programming is code reusability. As the name suggests Inheritance is the process of forming a new class from an existing class that is from the existing class called as base class, new class is formed called as derived class.

This is a very important concept of object-oriented programming since this feature helps to reduce the code size.


-------------------------------------------------------------------------------------------------------------------------------------------------------------

code for inheritance:

note: in order to inherit the parent class properties to child class we need to use EXTEND key word

------------------------------------------------------------------------------------------------------------------------------------------------------------


public virtual class parent

{

private integer pvt-mem;

protected integer ptd-mem;

public integer pub-mem;

public virtual void getvalues()

{

system.debug('pvt mem'+pvt-mem);

system.debug('ptd mem'+ptd-mem);

system.debug('pub mem'+pub-mem);

}

}

public class child extends parent

{

private integer pvt-ch-mem;

public override void getvalues()

{

system.debug('pvt mem'+pvt-mem);

system.debug('ptd mem'+ptd-mem);

system.debug('pub mem'+pub-mem);

system.debug('pvt ch mem'+ pvt-ch-mem);

}

}

global class test

{

public static testmethod void main()

{

parent p1=new parent();

p1.getvalues();

child c1=new child();

c1.getvalues();

}


}

Polymorphism:

The ability to use an operator or method in different ways in other words giving different meaning or Methods to the operators or methods is called polymorphism. Poly refers to many. That is a single method or an operator functioning in many ways different upon the usage is called polymorphism.

Following concepts demonstrate different types of polymorphism in Salesforce.
1) Method Overloading
2) Method Overriding


1)Method Overloading:
 it is possible to define two or more methods of same name in a class, provided that there argument list or parameters are different. This concept is known as Method Overloading.


 class Overload
 {

    void demo (integer a)
    {
       system.debug('from method demo with single parameter'+a);
    }
    void demo (integer a, integer b)
    {
       system.debug('from method demo with double parameters parameter'+a+' '+b));
    }
    double demo(double a) {
         system.debug('from method demo with single parameter differentiated by datatype of the method and parmeter'+a);
       return a*a;
    }
}

2) Method Overriding

Child class has the same method as of parent class. In such cases child class overrides the parent class method without even touching the source code of the parent class. This feature is known as method overriding.
Overriding means striking of old one and replacing new one

Example:

public virtual class parentClass
{
    public virtual void methodToOverride() //Parent class method
    {
         System.debug("I'm the method of ParentClass");
    }
}
public class ChildClass extends parentClass
{
    public override void methodToOverride() //Child Class method
    {
         System.debug ("I'm the method of ChildClass");
    }
}



Note : we need to use virtual  keyword before the parent class and method which you suppose to Override , on the other hand we need use override keyword before the child class mehod which you want to override

Thursday, April 9, 2015

Learn salesforce javascript page 4

<apex:page id="thePage">
    <!-- A simple function for changing the font. -->
    <script>
        function changeFont(input, textid) {
            if(input.checked) {
                document.getElementById(textid).style.fontWeight = "bold";
            }
            else {
                document.getElementById(textid).style.fontWeight = "normal";
            }
        }
    </script>

    <!-- This outputPanel calls the function, passing in the
         checkbox itself, and the DOM ID of the target component. -->
    <apex:outputPanel layout="block">
        <label for="checkbox">Click this box to change text font:</label>
        <input id="checkbox" type="checkbox"
            onclick="changeFont(this,'{!$Component.thePanel}');"/>
    </apex:outputPanel>

    <!-- This outputPanel is the target, and contains 
         text that will be changed. -->
    <apex:outputPanel id="thePanel" layout="block">
        Change my font weight!
    </apex:outputPanel>
</apex:page>

Learn Salesforce Java script page 3


copying billing address to shipping address java script  with out controller....


<apex:page standardController="Account" showHeader="true" sidebar="true">
    <apex:form id="myForm">
 
        <script>


            function copyAddress() {
                var shippingStreet = document.getElementById('j_id0:myForm:pgBlock:pgBlockSectionAddressInfo:j_id58:actShippingStreet');
                var shippingCity = document.getElementById('j_id0:myForm:pgBlock:pgBlockSectionAddressInfo:j_id64:actShippingCity');
                var shippingState = document.getElementById('j_id0:myForm:pgBlock:pgBlockSectionAddressInfo:j_id70:actShippingState');
                var shippingCountry = document.getElementById('j_id0:myForm:pgBlock:pgBlockSectionAddressInfo:j_id82:actShippingCountry');
                var shippingPostalCode = document.getElementById('j_id0:myForm:pgBlock:pgBlockSectionAddressInfo:j_id76:actShippingPostalCode');

                var BillingStreet = document.getElementById('j_id0:myForm:pgBlock:pgBlockSectionAddressInfo:j_id55:actBillingStreet');
                var BillingCity = document.getElementById('j_id0:myForm:pgBlock:pgBlockSectionAddressInfo:j_id61:actBillingCity');
                var BillingState = document.getElementById('j_id0:myForm:pgBlock:pgBlockSectionAddressInfo:j_id67:actBillingState');
                var BillingCountry = document.getElementById('j_id0:myForm:pgBlock:pgBlockSectionAddressInfo:j_id79:actBillingCountry');
                var BillingPostalCode = document.getElementById('j_id0:myForm:pgBlock:pgBlockSectionAddressInfo:j_id73:actBillingPostalCode');

                shippingStreet.value = BillingStreet.value;
                shippingCity.value = BillingCity.value;
                shippingState.value = BillingState.value;
                shippingCountry.value = BillingCountry.value;
                shippingPostalCode.value = BillingPostalCode.value;

            }
        </script>
     
     
        <apex:sectionHeader title="Account Edit" subtitle="{!Account.Name}" />  


        <apex:pageBlock id="pgBlock" mode="edit" title="Account Edit">
            <apex:pageBlockButtons location="both">
                <apex:commandButton value="Save" action="{!Save}"/>
                <apex:commandButton value="Cancel" action="{!Cancel}"/>
            </apex:pageBlockButtons>
        <apex:pageBlockSection id="pgBlockSectionAcctInfo" title="Account Information" collapsible="false" columns="2" >
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Account Owner</apex:outputLabel>
                <apex:outputField id="actOwner" value="{!account.ownerid}" />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Rating</apex:outputLabel>
                <apex:inputField id="actRating" value="{!account.rating}" />
            </apex:pageBlockSectionItem>
         
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Account Name</apex:outputLabel>
                <apex:inputField id="actName" value="{!account.name}" required="true" />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Phone</apex:outputLabel>
                <apex:inputField id="actPhone" value="{!account.Phone}" />
            </apex:pageBlockSectionItem>  
         
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Parent Account</apex:outputLabel>
                <apex:inputField id="actParentAccount" value="{!account.ParentId}" />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Fax</apex:outputLabel>
                <apex:inputField id="actFax" value="{!account.Fax}" />
            </apex:pageBlockSectionItem>  
         
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Account Number</apex:outputLabel>
                <apex:inputField id="actNumber" value="{!account.Accountnumber}" />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Website</apex:outputLabel>
                <apex:inputField id="actWebsite" value="{!account.Website}" />
            </apex:pageBlockSectionItem>
         
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Account Site</apex:outputLabel>
                <apex:inputField id="actSite" value="{!account.Site}" />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Ticker Symbol</apex:outputLabel>
                <apex:inputField id="actTicker" value="{!account.TickerSymbol}" />
            </apex:pageBlockSectionItem>
         
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Type</apex:outputLabel>
                <apex:inputField id="actType" value="{!account.Type}" />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Ownership</apex:outputLabel>
                <apex:inputField id="actOwnership" value="{!account.Ownership}" />
            </apex:pageBlockSectionItem>
         
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Industry</apex:outputLabel>
                <apex:inputField id="actIndustry" value="{!account.Industry}" />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Employees</apex:outputLabel>
                <apex:inputField id="actEmployees" value="{!account.NumberOfEmployees}" />
            </apex:pageBlockSectionItem>
         
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Annual Revenue</apex:outputLabel>
                <apex:inputField id="actAnnualRevenue" value="{!account.AnnualRevenue}" />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >SIC Code</apex:outputLabel>
                <apex:inputField id="actSIC" value="{!account.Sic}" />
            </apex:pageBlockSectionItem>          
        </apex:pageBlockSection>
         
        <apex:pageBlockSection id="pgBlockSectionAddressInfo" title="Address Information" collapsible="false" columns="2">
            <apex:facet name="header">
                    <span class="pbSubExtra">
                        <span class="bodySmall">
                            <a href="javascript:copyAddress();">Copy Billing Address to Shipping Address</a>
                        </span>
                    </span>
                    <h3>Address Information<span class="titleSeparatingColon">:</span></h3>
            </apex:facet>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Billing Street</apex:outputLabel>
                <apex:inputField id="actBillingStreet" value="{!account.BillingStreet}" />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Shipping Street</apex:outputLabel>
                <apex:inputField id="actShippingStreet" value="{!account.ShippingStreet}" />
            </apex:pageBlockSectionItem>
         
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Billing City</apex:outputLabel>
                <apex:inputField id="actBillingCity" value="{!account.BillingCity}" />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Shipping City</apex:outputLabel>
                <apex:inputField id="actShippingCity" value="{!account.ShippingCity}" />
            </apex:pageBlockSectionItem>
         
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Billing State/Province</apex:outputLabel>
                <apex:inputField id="actBillingState" value="{!account.BillingState}" />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Shipping State/Province</apex:outputLabel>
                <apex:inputField id="actShippingState" value="{!account.ShippingState}" />
            </apex:pageBlockSectionItem>        
         
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Billing Zip/Postal Code</apex:outputLabel>
                <apex:inputField id="actBillingPostalCode" value="{!account.BillingPostalCode}" />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Shipping Zip/Postal Code</apex:outputLabel>
                <apex:inputField id="actShippingPostalCode" value="{!account.ShippingPostalCode}" />
            </apex:pageBlockSectionItem>  
         
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Billing Country</apex:outputLabel>
                <apex:inputField id="actBillingCountry" value="{!account.BillingCountry}" />
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Shipping Country</apex:outputLabel>
                <apex:inputField id="actShippingCountry" value="{!account.ShippingCountry}" />
            </apex:pageBlockSectionItem>
         
        </apex:pageBlockSection>
        <apex:pageBlockSection id="pgBlockSectionAdditionalInformation" title="Additional Information" collapsible="false" columns="2">
            <!--ANY CUSTOM FIELDS / ADDITIONAL INFORMATION CAN GO HERE-->
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>



to know what is J_id0 click below linkhttps://developer.salesforce.com/forums?id=906F0000000950IIAQ

Learn Salesforce Java script page 2

Custom code for Copying of billing address to shipping address using controller .


<apex:page controller="Billingtoshipping" >


   <apex:form id="myform">


    <script type="text/javascript">

<!---Java script receiveing parameters from href:javascript component -->


        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">



<!--- From below href we are passing parameters to the javascript  --->

    <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>





--------------------------------------------------------------------------------------------------------------------------
Controller
-------------------------------------------------------------------------------------------------------------------------
public class Billingtoshipping{
    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; }

}