Salesforce API create Contact using Java

package com.thysmichels;

import com.sforce.soap.partner.*;
import com.sforce.soap.partner.sobject.*;
import com.sforce.ws.*;

public class ForcedotcomAWS {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
	    //Create a new connectionconfig to your Salesforce Org
	    ConnectorConfig sfconfig = new ConnectorConfig();
		//Use your salesforce username = email
	    sfconfig.setUsername("username");
	    //Use your saleforce password with your security token look like: passwordjeIzBAQKkR6FBW8bw5HbVkkkk
	    sfconfig.setPassword("passwordsecuritytoken");
	 
	    PartnerConnection partnercon = null;
	    
	    try {
	    	 
	        // create a salesforce connection object with the credentials supplied in your connectionconfig
	        partnercon = Connector.newConnection(sfconfig);
                SObject contact = new SObject();
	        contact.setType("Contact");
	        contact.setField("Salutation", "Mr.");
	        contact.setField("FirstName", "Thys");
	        contact.setField("LastName", "Michels");
	        contact.setField("Title", "Software Engineer");
	        contact.setField("Department", "IT");
	        contact.setField("Phone", "4084213377");
	        contact.setField("Email", "thys_michels@persistentsys.com");
	        contact.setField("LeadSource", "Web");
// safe contact object
	        SaveResult[] sfcontactresults = partnercon.create(new SObject[] { contact });
	        System.out.println("Created Contact: " + sfcontactresults[0].getId());
	    } catch (ConnectionException e) {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
	    }
	}
}
About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 260 other followers

%d bloggers like this: