I want to use Java to bind to the SOAP API to insert some objects into salesforce from a CSV file. I don't want to use the dataloader or excel connector, because I will be inserting multiple related objects and will be writing code to automate the whole process with a single button press.

My CSV files have the first line defining the names of the fields that I want to insert. I want to keep my solution as flexible as possible, so I don't want to hardcode the order of the fields like the following:

Account acc = new Account();

Instead, I would like to read the first line and perhaps insert the order/name combination into a map and then use this to somehow call the right setter methods for my object (This obviously presumes that the header names are well formed).

I am stuck on how I can call a setter method, or even set a field using the dot notation, in the above scenario using the name of the field. Is there a way to achieve this?


  • How are you accessing the SOAP API...? With Java, .NET, other? You could use the reflection API in either to call the setter methods – Phil Hawthorn Dec 11 '12 at 11:30
  • I'm using Java. I'll have a look into this. Thanks. – Joe Dec 11 '12 at 11:33

If you use the Partner-wsdl, you'd only have access to SObject fields by name. Obviously a drawback for some use cases, but in your case it might be preferable? Example from the documentation

SObject account = new com.sforce.soap.partner.sobject.wsc.SObject();
account.setField("XID1__c", "1");

As you are using Java, you can use the Reflection API

A quick google found this blog post which gives you a brief example. There are lots out there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.