Salesforce API create opportunity using Java

package com.thysmichels;

import java.util.Date;
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 opportunity = new SObject();
	        opportunity.setType("Opportunity");
	        opportunity.setField("Name", "Persistent Salesforce Services");
	        Date clsdate = new Date();
	        opportunity.setField("CloseDate", clsdate);
	        opportunity.setField("StageName", "Qualification");
	        SaveResult[] sfoppresult = partnercon.create(new SObject[] { opportunity });
	        System.out.println("Created Opportunity: " + sfoppresult[0].getId());
            } catch (ConnectionException e) {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
	    }
	}
}
Advertisements

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

%d bloggers like this: