function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ministe_2003ministe_2003 

Mapping fields outside of the code

Hi all,

I have written a java application which imports csv files containing records from various ERP systems and creates/updates them in salesforce.

to do this I simply create SObjects in code like so:

		    	  Opportunity o = new Opportunity();
		    	  o.setOwnerId(record.get(1));
		    	  o.setAccountId(record.get(5));
		    	  o.setName(record.get(7));
		    	  o.setCloseDate(Main.formatDate(record.get(8)));

 and then upsert the records, which is working very well.  FYI, record is an entry in a 2d array and get() simply retrieves a value from that entry, in the corresponding position to the column it was on the csv file.

 

However I wonder if its possible to do this outside of the code and map the fields in an external properties file.  My reason for this is if we want to start recording additional fields, or stop recording an existing one, it would require a code change.

 

Is it somehow possible for an unskilled user to be able to open up a file in notepad and manage this?  To be honest I'm failing to see how it could be possible really because presumably the value assignment to a field would have to be written in code as above, but is there some way?

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
colemabcolemab

Judging by your methods (i.e. setAccountID) It looks like you are using the enterprise WSDL.  This is very strongly typed but because of that you get those prebuilt get/set methods for each field - at the cost of having to regenerate the WSDL for any new fields.

 

If you were on the partner WSDL you could use the .setField method which looks something like this when called:

MyObject.setField(name, value)

 

In this call, you specify in a string the name of the field you want to update.  So you could pull that from a text file or some other location.

 

I think the Java Preferences API would be a great tool to use on the back end for storage.  However, you would have to build a GUI to manage those settings.

All Answers

colemabcolemab

Judging by your methods (i.e. setAccountID) It looks like you are using the enterprise WSDL.  This is very strongly typed but because of that you get those prebuilt get/set methods for each field - at the cost of having to regenerate the WSDL for any new fields.

 

If you were on the partner WSDL you could use the .setField method which looks something like this when called:

MyObject.setField(name, value)

 

In this call, you specify in a string the name of the field you want to update.  So you could pull that from a text file or some other location.

 

I think the Java Preferences API would be a great tool to use on the back end for storage.  However, you would have to build a GUI to manage those settings.

This was selected as the best answer
ministe_2003ministe_2003

Thanks for that, when I get time I'll have a go at re-writing the application using the Partner WSDL and see how I get on.  I assume you're recommending the JP API as a tool to store the field mapping over just a text file, is that correct?

colemabcolemab

For advanced data structures that, I do think that the JP API can be a good fit as you can indirectly store an object. Of course, when it comes to medium-large data sizes and/or search ability this is never a replacement for a database.

 

See these notes from the IBM page "The first trick is to turn an object into a byte array. The reason for doing this is simple: although the Preferences object does not handle objects, it does handle byte arrays."

 

However, if you are using very simple data structures and don't want to program a GUI for reading / writing to the JP API you may find a text file more convenient.