Saturday, 14 December 2013

Code for alternate background color for rows in a pageBlockTable

Visualforce code:

<apex:page controller="sample">
    <apex:pageBlock >
    <apex:variable var="i" value="{!0}"/>
        <apex:pageBlockTable value="{!acnt}" var="acc">
            <apex:column >
                <apex:variable var="i" value="{!i+1}"/>
            </apex:column>
            <apex:column value="{!acc.Name}" rendered="{! IF((mod(i,2)) == 0, true, false)}" style="background:pink;"/>
            <apex:column rendered="{! IF((mod(i,2)) == 0, true, false)}" style="background:pink;" value="{!acc.Rating}"/>                     
           
            <apex:column value="{!acc.Name}" rendered="{! IF((mod(i,2)) == 1, true, false)}" style="background:yellow;"/>
            <apex:column rendered="{! IF((mod(i,2)) == 1, true, false)}" style="background:yellow;" value="{!acc.Rating}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>


Output:

Thursday, 12 December 2013

Disabiling developer mode using code

Code to Disable Developer mode in visualforce pages:

visualforce code :

<apex:page controller="newclass">
<apex:form >
 <apex:commandButton value="next" action="{!save}"/>
</apex:form>
</apex:page>

Apex Code :

public with sharing class newclass {
    public PageReference save() {
        PageReference pr = new PageReference('https://c.ap1.visual.force.com/apex/test1'+'?isdtp=vw');
        return pr;
    }
}

                                                            ---  OR ---

Append the following code to the URL

For example :

https://c.ap1.visual.force.com/apex/test?isdtp=vw

Monday, 18 November 2013

Dependent Picklist

<apex:page controller="dpickcontroller">
   <apex:form >
      <apex:pageBlock title="Dependent Picklist">
        <apex:pageBlockSection columns="6">
         <apex:selectList size="1" value="{!country}">
         <b>Country</b> <apex:selectOptions value="{!con}" id="co"/>
         <apex:actionSupport event="onchange" reRender="st,ct"/>
         </apex:selectList>
         <apex:selectList value="{!state}" size="1" id="st">
          <b>State</b><apex:selectOptions value="{!sta}"/>
          <apex:actionSupport event="onchange" reRender="ct"/>
         </apex:selectList>
         <apex:selectList value="{!city}" size="1" id="ct">
          <b>City</b><apex:selectOptions value="{!cit}"/>
          <apex:actionSupport event="onchange" />
         </apex:selectList>
        </apex:pageBlockSection>
        <apex:pageBlockSection columns="6">
          <apex:selectList size="1" value="{!country2}">
         <b>Country2</b> <apex:selectOptions value="{!con2}" />
         <apex:actionSupport event="onchange" reRender="st2,ct2"/>
         </apex:selectList>
         <apex:selectList value="{!states}" size="1" id="st2">
          <b>State2</b><apex:selectOptions value="{!sta2}"/>
          <apex:actionSupport event="onchange" reRender="ct2"/>
         </apex:selectList>
         <apex:selectList value="{!cities}" size="1" id="ct2">
          <b>City2</b><apex:selectOptions value="{!cit2}"/>
         </apex:selectList>
        </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:form>
</apex:page>

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

public with sharing class dpickcontroller {

    public List<SelectOption> getCon2() {
     List<SelectOption> options4 = new List<SelectOption>();
        options4.add(new SelectOption('none','none'));
        options4.add(new SelectOption('Indona','Indona'));
        return options4;
    }
 
    public List<SelectOption> getSta2() {
     List<SelectOption> options5 = new List<SelectOption>();
       options5.add(new SelectOption('none','none'));
       if(country2 == 'none'){
        states = 'none';
        cities = 'none';
       }
        else if(country2 == 'Indona'){
          options5.add(new SelectOption('AP1','AP1'));
          options5.add(new SelectOption('Jaipur1','Jaipur1'));
          options5.add(new SelectOption('Delhi1','Delhi1'));
        }
        return options5;
    }

    public List<SelectOption> getCit2() {
     List<SelectOption> options6 = new List<SelectOption>();
       options6.add(new SelectOption('none','none'));
        if(states == 'AP1'){
          options6.add(new SelectOption('Hyd1','Hyd1'));
          options6.add(new SelectOption('Mbnr1','Mbnr1'));
          options6.add(new SelectOption('kmm1','kmm1'));
        }
        return options6;
    }
       
    public String cities { get; set; }
    public String states { get; set; }
    public String country2 { get; set; }
    public String city { get; set; }
    public String state { get; set; }
    public String country { get; set; }

    public List<SelectOption> getCon() {
    List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('none','none'));
        options.add(new SelectOption('INDIA','INDIA'));
        options.add(new SelectOption('US','US'));
        options.add(new SelectOption('CANADA','Canada'));
       // options.add(new SelectOption('MEXICO','Mexico'));
       return options;
    }
 
    public List<SelectOption> getSta() {
     List<SelectOption> options2 = new List<SelectOption>();
       options2.add(new SelectOption('none','none'));
        if(country == 'none'){
         state = 'none';
         city = 'none';
        }
        else if(country == 'india'){
          options2.add(new SelectOption('AP','AP'));
          options2.add(new SelectOption('Jaipur','Jaipur'));
          options2.add(new SelectOption('Delhi','Delhi'));
        } else if(country == 'US'){
          options2.add(new SelectOption('New York','New York'));
          options2.add(new SelectOption('Boston','Boston'));
          options2.add(new SelectOption('Mexico','Mexico'));
        } else if(country == 'Canada'){
          options2.add(new SelectOption('Toronto zoo','Toronto zoo'));
          options2.add(new SelectOption('Niagara falls','Niagara falls'));
          options2.add(new SelectOption('CN Towers','CN Towers'));
        }
        return options2;
    }

    public List<SelectOption> getCit() {
      List<SelectOption> options3 = new List<SelectOption>();
       options3.add(new SelectOption('none','none'));
        if(state == 'AP'){
          options3.add(new SelectOption('Hyd','Hyd'));
          options3.add(new SelectOption('Mbnr','Mbnr'));
          options3.add(new SelectOption('kmm','kmm'));
          options3.add(new SelectOption('sec','sec'));
        } else if(state == 'New York'){
          options3.add(new SelectOption('‎Central Park','Central Park'));
          options3.add(new SelectOption('West Village Stroll','West Village Stroll'));
          options3.add(new SelectOption('Grimaldi Pizzeria','Grimaldi Pizzeria'));
        } else if(state == 'Boston'){
          options3.add(new SelectOption('Fenway Park','Fenway Park'));
          options3.add(new SelectOption('Faneuil hall','Faneuil hall'));
          options3.add(new SelectOption('Castle Island','Castle Island'));
          }
        return options3;
    }
}

Friday, 15 November 2013

Number to word converter

Visualforce code :



<apex:page controller="Numbertowordclass">
  <apex:form >
  <apex:pageBlock id="pb" >
  <apex:panelGrid columns="2">
   Enter Number:<apex:inputText value="{!num}" size="60"/>
   Enter word:<apex:inputText value="{!wrd}" size="60"/> 
  </apex:panelGrid>
  <apex:pageBlockButtons >
  <apex:commandButton value="Convert" action="{!convert}" reRender="pb"/>
  <apex:commandButton value="Cancel" action="{!Cancel}" reRender="pb"/>
  </apex:pageBlockButtons>
  </apex:pageBlock>
  </apex:form>
</apex:page>


Apex  code :


//This Class will support upto 12 digits :-

public with sharing class Numbertowordclass {

    public void Refresh(){
    num= null;
    wrd= null;
    }

    public PageReference Cancel() {
        Refresh();
        return null;
    }


    public string wrd{set;get;}
    public long num { get; set; }
  
    public string convert() {
      wrd=convert(num);
      return null;
    }
    public String[] units = new String[]{'Zero ','One ','Two ','Three ','Four ','Five ','Six ','Seven ','Eight ','Nine
        ','Ten ', 'Eleven ','Twelve ','Thirteen ','Fourteen ','Fifteen ', 'Sixteen ','Seventeen ','Eighteen ',
        'Nineteen '};
    public String[] tens = new String[]{'','','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety'};
 
    //This method is used to convert the integer to words
    public  String convert(long i) {
      //
      if( i < 20)  return units[integer.valueOf(i)];
      if( i < 100) return tens[integer.valueOf(i)/10] + ((math.mod(i , 10) > 0)? '' + convert(math.mod(i , 
         10)):'');
      if( i < 1000) return units[integer.valueOf(i)/100] + ' Hundred ' + ((math.mod(i , 100) > 0)?' ' + 
        convert(math.mod(i , 100)):'');
      if( i < 10000) return units[integer.valueOf(i)/1000] + ' Thousand ' + ((math.mod(i , 1000) > 0)?' ' + 
        convert(math.mod(i , 1000)):'');
      if( i < 1000000) return convert(i / 1000) + ' Thousand ' + ((math.mod(i , 1000) > 0)? '' +  
         convert(math.mod(i ,1000)):'') ;
      if(i < 100000000) return convert(i / 1000000) + ' Milion ' + ((math.mod(i , 1000000) > 0)? '' + 
        convert(math.mod(i , 1000000)):'') ;
      if(i < 1000000000) return convert(i / 1000000) + 'Milion ' + ((math.mod(i , 1000000) > 0)? '' + 
        convert(math.mod(i , 1000000)):'') ;    
      return convert(i / 1000000000) + ' Bilian ' + ((math.mod(i , 1000000000) > 0)? '' + 
        convert(math.mod(i , 1000000000)):'') ;
}
}
 


Wednesday, 13 November 2013

How to get Record Owner ID from record ID?

If u want to get the owner id/ user id of current record.

for this what I know, we have to do 2 things. 
1) First we have to fetch record ID from URL by using
   ApexPages.CurrentPage().getparameters().get('id');
2) We can fetch owner ID by using this record ID.
If I am correct then how to fetch record owner ID by using record ID? then leave a comment.

Tuesday, 5 November 2013

Difference between rendered, renderAs and reRender in Visualforce page



render - Boolean value (if it is true, it displays the block else it will be hidden)

reRender - ID. Particular block will be refreshed.

renderAs - Display the page as pdf, excel, etc...

Monday, 28 October 2013

Show and Hide example using Apex in Salesforce

Visualforce page:

<apex:page controller="HideAndShow" sidebar="false" showHeader="false" >
<apex:form >
 <p style="font-weight:800; color:#4C0000;">&nbsp;&nbsp;&nbsp;Click the buttons below to experiment
     Hide and Show.</p>
<apex:pageBlock title="Block A" rendered="{!abool}">
        This is Block A.<br/><br/>      
</apex:pageBlock>
<apex:pageBlock title="Block B" rendered="{!bbool}">
        This is Block B.<br/><br/>
</apex:pageBlock>  
<apex:pageBlock >
<apex:commandButton value="Show A" action="{!showA}" rendered="{!sabool}" />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<apex:commandButton value="Show B" action="{!showB}" rendered="{!sbbool}" />      
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<apex:commandButton value="Hide A" action="{!hideA}" rendered="{!habool}" />
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<apex:commandButton value="Hide B" action="{!hideB}" rendered="{!hbbool}" />
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<apex:commandButton value="Show A and B" action="{!showAB}" rendered="{!sabbool}"/>
     &nbsp;&nbsp;&nbsp;&nbsp;
<apex:commandButton value="Hide A and B" action="{!hideAB}" rendered="{!habbool}"/>
</apex:pageBlock>
</apex:form>  

</apex:page>

Apex Controller:

public with sharing class HideAndShow {
    public Boolean abool {get;set;}
    public Boolean bbool {get;set;}
    public Boolean sabool {get;set;}
    public Boolean sbbool {get;set;}
    public Boolean habool {get;set;}
    public Boolean hbbool {get;set;}
    public Boolean sabbool {get;set;}
    public Boolean habbool {get;set;}
 
    public HideAndShow()
    {
        sabool = true;
        sbbool = true;
        sabbool = true;
        abool = false;
        bbool = false;
    }
 
    public void showA()
    {
        abool = true;
        check();
    }
 
    public void showB()
    {
        bbool = true;
        check();
    }
   
    public void hideA()
    {
        abool = false;
        check();
    }
 
    public void hideB()
    {
        bbool = false;
        check();
    }
 
    public void showAB()
    {
        abool = true;
        bbool = true;
        check();
    }
 
    public void hideAB()
    {
        abool = false;
        bbool = false;
        check();
    }  
 
    public void check()
    {
        if(abool == true && bbool == false)
        {
            sabool = false;
            sbbool = true;
            habool = true;
            hbbool = false;
            sabbool = true;
            habbool = false;
        }
        else if(abool == false && bbool == true)
        {
            sabool = true;
            sbbool = false;
            habool = false;
            hbbool = true;
            sabbool = true;
            habbool = false;
        }
        else if(abool == true && bbool == true)
        {
            sabool = false;
            sbbool = false;
            habool = true;
            hbbool = true;
            habbool = true;
            sabbool = false;

        }
        else
        {
            sabool = true;
            sbbool = true;
            habool = false;
            hbbool = false;
            sabbool = true;
            habbool = false;
        }
    }  
}



Sunday, 27 October 2013

Radio Button in Salesforce

To create Radio button using apex, use <apex:selectRadio>

Example:

Visual force page:

<apex:selectRadio value="{!searchCategory}" >
    <apex:selectOption itemValue="Member" itemlabel="Member"/>
    <apex:selectOption itemValue="Blog" itemlabel="Blog"/>
    <apex:selectOption itemValue="Photo" itemlabel="Photo"/>
</apex:selectRadio>


Apex:

  public String searchCategory;

  public String getsearchCategory()
 {
  return searchCategory;
 }

 public void setsearchCategory(String searchCategory)
 {
  this.searchCategory = searchCategory;
 }

How to convert sObject to String in Apex

public sObject searchCategory;
String objType = String.valueOf(searchCategory);

Wednesday, 23 October 2013

Reset Password code in VF and Apex

Visual Force Code:

<apex:page controller="Reset">
  <center>
   <apex:form >
   <apex:messages />
    <apex:pageBlock title="Reset Password">
     <b>Reset Your Password</b><br/>&nbsp;
      <apex:panelGrid columns="2">
       Enter Email <apex:inputText value="{!email}"/>
       Enter Password <apex:inputsecret value="{!pass}"/>
       Conform Password <apex:inputsecret value="{!conf_pass}"/>
      </apex:panelGrid>
     <apex:commandButton value="Check In" action="{!Save}"/>
    </apex:pageBlock>
   </apex:form>
  </center>
</apex:page>

Apex Code:

public with sharing class Reset {
    public String conf_pass { get; set; }
    public String pass { get; set; }
    public String email { get; set; }
    list<Registration__c> reg_obj;
    //string email;
    string name;
    string password;
    
    public reset(){
        reg_obj = [select id,Email__c,First_Name__c,Password__c from Registration__c];
    }
    
    public PageReference Save() {
    
        if(pass == conf_pass){
            for(Registration__c reg : reg_obj){
                if(reg.Email__c == email){
                    reg.Password__c = pass;
                    update reg;
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Your Password is update now.'));                
                }
            }
        }else{
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Sorry your password and confirm password are not match'));                
        }
          return null;
    }

}

Login Page Using Salesforce Code

Program for Login Page Using Salesforce with VisualForce and APEX Code :

Visual force  Code:

<apex:page controller="LoginPage" showHeader="false" sidebar="false"  standardStylesheets="true">
<body background="{!$Resource.pic}" width="150" height="150"/>
<apex:form >
<center>
<b>Login Page</b>
<apex:panelGrid columns="2" style="margin-top:2em;">
<b>UserName</b>
<apex:inputText required="true" id="username" value="{!username}"/>
<b>Password</b>
<apex:inputSecret id="password" value="{!password}"/>
<b><apex:messages /></b>
</apex:panelGrid>
<apex:commandButton action="{!loginUser}" value="Login" id="save"/>
<apex:commandButton action="{!Cancel}" value="Cancel" id="cancel"/><br/><br/>
<apex:commandLink action="{!registerUser}" value="Register" id="register"
      immediate="true"/><br/> &nbsp; <br/>
<apex:commandLink action="{!ForgotPassword}" value="Forgot Password"
      id="ForgotPassword"  immediate="true"/>
</center>
</apex:form>
</apex:page>


Apex Code :

public class LoginPage {
    public PageReference ForgotPassword() {
        return page.ForgotPassword;
 }
 public PageReference Cancel() {
    PageReference newPage2 = new PageReference('/apex/login');
        newPage2.setRedirect(true);
        return newPage2;
 }
 public PageReference loginUser() { 
     try{
     List<Registration__c> log=[select Email__c,password__C from Registration__c];
       for(Registration__c obj:log){
       if(obj.Email__c==username && obj.password__c==password){
       //PageReference newPage1 = new PageReference('/apex/new');
       // newPage1.setRedirect(true);
        return page.new;
       }
       }
     }
     catch(Exception E){  
     return null;
     }
 apexPages.addMessage(new ApexPages.message(ApexPages.severity.Error,'.Invalid
         Username or Password'));
     return null;
}      
public String password { get; set; }
public String username { get; set; }
public PageReference registerUser() {
PageReference newPage = new PageReference('/apex/reg');
newPage.setRedirect(true);
return newPage;
}
}

Tuesday, 22 October 2013

Forgot Password Code

Code for Forgot Password That sending link of reset password  your Email-id :

<apex:page controller="ForgotPasswordClass" sidebar="false" showHeader="true">
 <apex:form >
 <apex:messages />
  <center>
    <h1>Reset Password</h1>
    <b><p>Did you forget your password? Please enter your username below.</p></b>
     <apex:outputLabel value=" Enter Email ID"/>&nbsp;
     <apex:inputText value="{!user}"/><br/>&nbsp;<br/>
     <apex:commandButton value="submit" action="{!save}"/>
  </center>
 </apex:form>
</apex:page>


Apex program :

public with sharing class ForgotPasswordClass {
 public Registration__c ln{get;set;}
 public String user{get;set;}
     public ForgotPasswordClass(){
      ln=new Registration__c();
     }
    public PageReference Save() {
       //ln.name=user;
        String address = user;
        String[] toAddresses = user.split(':', 0);
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setSubject( 'link' );
        email.setToAddresses( toAddresses );
        email.setPlainTextBody( 'http://ststech-developer-edition.ap1.force.com/ResetPassword' );
        Messaging.SendEmailResult[] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
        User=null;
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Plz check youe mail id for password...'));
         return null;
    }

}

Saturday, 19 October 2013

Sample JAVA program for Web Service API

package wsc;

import java.io.BufferedReader;
 
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.IOException;

//import com.sforce.soap.enterprise.DeleteResult;
 
import com.sforce.soap.enterprise.DescribeGlobalResult;
import com.sforce.soap.enterprise.DescribeGlobalSObjectResult;
import com.sforce.soap.enterprise.DescribeSObjectResult;
import com.sforce.soap.enterprise.EnterpriseConnection;
//import com.sforce.soap.enterprise.Error;
import com.sforce.soap.enterprise.Field;
//import com.sforce.soap.enterprise.FieldType;
import com.sforce.soap.enterprise.GetUserInfoResult;
//import com.sforce.soap.enterprise.LoginResult;
import com.sforce.soap.enterprise.PicklistEntry;
import com.sforce.soap.enterprise.QueryResult;
//import com.sforce.soap.enterprise.SaveResult;
//import com.sforce.soap.enterprise.sobject.Account;
import com.sforce.soap.enterprise.sobject.Contact;
import com.sforce.soap.enterprise.sobject.SObject;
import com.sforce.ws.ConnectorConfig;
import com.sforce.ws.ConnectionException;

public class QuickstartApiSample 

{
private static BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
EnterpriseConnection con;
String authEndPoint = "";
String passwd = "";
public static void main(String[] args) 
{    
QuickstartApiSample sample = new QuickstartApiSample("https://login.salesforce.com/services/Soap/c/24.0/0DF90000000PX8r");
if ( sample.login() ) 
{
sample.describeGlobalSample();
sample.describeSample();
sample.querySample();
}
}
public QuickstartApiSample(String authEndPoint) 
{
this.authEndPoint = authEndPoint;
}
public String getUserInput(String prompt) 
{
String result = "";
try 
{
System.out.print(prompt);
result = reader.readLine();

catch (IOException ioe) 
{
ioe.printStackTrace();
}
return result;
}
public boolean login() 
{
boolean success = false;
String userId = getUserInput("UserID: ");
String passwd = getUserInput("Password: ");
try 
{
ConnectorConfig config = new ConnectorConfig();
config.setAuthEndpoint(authEndPoint);
config.setUsername(userId);
config.setPassword(passwd);
config.setCompression(true);
//config.setProxy("Your Proxy", 80);
System.out.println("AuthEndPoint: " + authEndPoint);
config.setTraceFile("traceLogs.txt");
config.setTraceMessage(true);
config.setPrettyPrintXml(true);

con = new EnterpriseConnection(config);
 
GetUserInfoResult userInfo = con.getUserInfo();
System.out.println("\nLogging in ...\n");
System.out.println("UserID: " + userInfo.getUserId());
System.out.println("User Full Name: " +
userInfo.getUserFullName());
System.out.println("User Email: " +
userInfo.getUserEmail());
System.out.println();
System.out.println("SessionID: " +
config.getSessionId());
System.out.println("Auth End Point: " +
config.getAuthEndpoint());
System.out.println("Service End Point: " +
config.getServiceEndpoint());
System.out.println();
success = true;

catch (ConnectionException ce)
{
ce.printStackTrace();

catch (FileNotFoundException fnfe) 
{
fnfe.printStackTrace();
}
return success;
}
public void logout() 
{
try 
{
con.logout();
System.out.println("Logged out");

catch (ConnectionException ce)
{
ce.printStackTrace();
}
}
/**
* To determine the objects that are available to the logged-in
* user, the sample client application executes a describeGlobal
* call, which returns all of the objects that are visible to
* the logged-in user. This call should not be made more than
* once per session, as the data returned from the call likely
* does not change frequently. The DescribeGlobalResult is
* simply echoed to the console.
*/
public void describeGlobalSample() 
{
try 
{
DescribeGlobalResult describeGlobalResult =
con.describeGlobal();
DescribeGlobalSObjectResult[] sobjectResults =
describeGlobalResult.getSobjects();
for (int i = 0; i < sobjectResults.length; i++) 
{
System.out.println(sobjectResults[i].getName());
}

catch (ConnectionException ce) 
{
ce.printStackTrace();
}
}
/**
* The following code segment illustrates the type of metadata
* information that can be obtained for each object available
* to the user. The sample client application executes a
* describeSObject call on a given object and then echoes
* the returned metadata information to the console. Object
* metadata information includes permissions, field types
* and length and available values for picklist fields
* and types for referenceTo fields.
*/
private void describeSample() 
{
String objectToDescribe = getUserInput("\nType the name of the object to " +
"describe (Example: Account): ");
try 
{
DescribeSObjectResult describeSObjectResult =
con.describeSObject(objectToDescribe);
if (describeSObjectResult != null) 
{
Field[] fields = describeSObjectResult.getFields();
System.out.println("Metadata for the " +
describeSObjectResult.getName() + " SObject"
);
System.out.println("\tActivateable: " +
describeSObjectResult.isActivateable()
);
System.out.println("\tNumber of fields: " +
fields.length
);
if (fields != null) 
{
for (Field field : fields) 
{
//String name = field.getName();
System.out.println("\tField name: " +
field.getName()
);
PicklistEntry[] picklistValues =
field.getPicklistValues();
if (picklistValues != null && picklistValues.length > 0) 
{
System.out.println("\t\tPicklist values: ");
for (int j = 0; j < picklistValues.length; j++) 
{
if (picklistValues[j].getLabel() != null) 
{
System.out.println("\t\tValue: " +
picklistValues[j].getLabel()
);
}
}
}
String[] referenceTos = field.getReferenceTo();
if (referenceTos != null && referenceTos.length > 0) 
{
System.out.println("\t\tThis field references the " +
"following objects:"
);
for (int j = 0; j < referenceTos.length; j++) 
{
System.out.println("\t\t" + referenceTos[j]);
}
}
}
}
}

catch (ConnectionException ce) 
{
ce.printStackTrace();
}
}
public void querySample() 
{
try 
{
String soqlQuery = "SELECT FirstName, LastName FROM Contact";
QueryResult result = con.query(soqlQuery);
boolean done = false;
if (result.getSize() > 0) 
{
System.out.println("\nLogged-in user can see " +
result.getRecords().length +
" contact records."
);
while (! done) 
{
SObject[] records = result.getRecords();
for ( int i = 0; i < records.length; ++i ) 
{
Contact con = (Contact) records[i];
String fName = con.getFirstName();
String lName = con.getLastName();
if (fName == null) 
{
System.out.println("Contact " + (i + 1) +
": " + lName
);

else 
{
System.out.println("Contact " + (i + 1) + ": " +
fName + " " + lName
);
}
}
if (result.isDone()) 
{
done = true;

else 
{
result =
con.queryMore(result.getQueryLocator());
}
}

else 
{
System.out.println("No records found.");
}
System.out.println("\nQuery succesfully executed.");

catch (ConnectionException ce) 
{
ce.printStackTrace();
}
}
}