Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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();
acc.setId(id);
acc.setName(name);
...

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?

Thanks

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 –  user293 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
add comment

2 Answers

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.setType("Account");
account.setField("Name","myAccount");
account.setField("XID1__c", "1");
share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.