简体   繁体   中英

Salesforce REST API through add leads in salesforce

I am trying to add leads in salesforce through rest API.Code is in java. I have converted WSDL to jar files and added as reference in Eclipse which allow to access salesforce objects in java. PFB my code.

System.out.println("-------LEAD INSERT----------");
String url= baseUri + "/sobjects/Lead";
System.out.println("((((((("+ url);
JSONObject lead= new JSONObject();
lead.put("FirstName", "LeadCreate3");
lead.put("LastName","Test3");
lead.put("Company","ACME");
AssignmentRuleHeader_element arh=new AssignmentRuleHeader_element();
arh.setAssignmentRuleId("01Q28000000e0Ow");

System.out.println("\n JSON for lead record to be inserted:"+ lead.toString(1));

HttpClient clientObj= HttpClientBuilder.create().build();
HttpPost post= new HttpPost(url);

System.out.println("\n"+oauthHeader+ "|||||"+ prettyPrintHeader);
post.addHeader(oauthHeader);
post.addHeader(prettyPrintHeader);

I want to add assignmentruleheader and emailHeader but i'm not getting which object to associate these headers with?

This is a very unclear question. You "parse WSDL" files when you use SOAP API (giant XML documents). Yet you state you want to use REST API?

Maybe try to not hand-craft the messages, find a nice prebuilt Java library?

For SOAP API the documentation has exactly the example you need, Lead creation. Scroll to almost bottom of the page: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_lead.htm

connection.setAssignmentRuleHeader('SF rule Id goes here', false);

For REST API it's a real HTTP header: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/headers_autoassign.htm Name should be Sforce-Auto-Assign and value should be your rule's Id. As for actual code... would depend if you use any REST framework I guess like JAX-RS? My Java days are long gone but this should work? https://www.baeldung.com/java-http-request

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM