Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
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
up vote 4 down vote accepted

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");
share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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