Salesforce中通过SOAP API和Metadata API开发java的web server服务

Salesforce中通过SOAP API和Metadata API开发java的web server服务

参考

package wsc;


import com.sforce.soap.enterprise.Connector;
import com.sforce.soap.enterprise.DeleteResult;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.enterprise.Error;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.SaveResult;
import com.sforce.soap.enterprise.sobject.SObject;
import com.sforce.soap.enterprise.sobject.MYSOBJECt__c;
import com.sforce.soap.metadata.MetadataConnection;
import com.sforce.soap.enterprise.LoginResult;


import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;


import java.io.FileWriter;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class wsctest {
	static final String USERNAME = "userName";  
	static final String PASSWORD = "password";
	static EnterpriseConnection connection;
	
	
	public static void main(String[] args) {
	    ConnectorConfig config = new ConnectorConfig();
	
	    config.setUsername(USERNAME);
	    config.setPassword(PASSWORD);
	  
	    config.setAuthEndpoint("https://test.salesforce.com/services/Soap/c/40.0/") ;
		//config.setTraceMessage(true);
		config.setProxy("XXX", 0000);

		try {
		  connection = Connector.newConnection(config);
		
		  queryContacts();
		  System.out.println("Auth EndPoint: "+config.getAuthEndpoint());
		  System.out.println("Service EndPoint: "+config.getServiceEndpoint());
		  System.out.println("Username: "+config.getUsername());
		  System.out.println("SessionId: "+config.getSessionId());
		     
	    } catch (ConnectionException e1) {
	        e1.printStackTrace();
	    }
	    
	}
	  
	private static void queryContacts() {
		    
		System.out.println("Querying for the 5 newest Contacts...");
		Map> idMap = new HashMap>();
	
		try {
		   
		  // query for the 5 newest contacts      
		  QueryResult queryResults = connection.query("SELECT "
		  		+ "ID," 
		  		+ "NAME"  
		    + " FROM MYSOBJECt__c"  
		  	System.out.println("=====queryResults.getSize()======"+queryResults.getSize());
		  	List plaList = new ArrayList();
		  if (queryResults.getSize() > 0) {
		    for (int i=0;i ids = new ArrayList();
		    	  ids.add(pla.getId());
		    	  idMap.put(control,ids);
		      }else{
		    	  idMap.get(control).add(pla.getId());
		      }
		    }
		    
		    for(String key :idMap.keySet()){
		    	System.out.println("======key======"+key);
	        }
	      }
		      
		} catch (Exception e) {
	      e.printStackTrace();
	    }    
	    
	  }
}

 

 

 

 

 

你可能感兴趣的:(Salesforce)