You need to sign in to do that
Don't have an account?
Dynamic Casting To Field Data Type
Hey All
I have a system where I am loading a csv and retrieveing a list of strings from it. The first half of the list is the names of the fields I wish to populate, the second half is ther values to push in.
I am trying to find a way of setting the value string to be a generic type which will then populate the field in question - basically performing automatic conversion.
For example:
for(integer i=0; i<(split.size()/2); i++) { Object o = split[i+(split.size()/2)]; m_task.put(split[i].trim() + '__c',o); }
Whwre split is my list and m_task is my sObject. I could write a long list of if statements to cast dependent upon the type from a describe results, but just feel that this has to be possible. I currently get an error from a xxxx type field of "Illegal assignment from String to xxxx".
Thanks for any help guys, I think it would be far more elegant a solution if it were possible this way!
Paul
Perhaps these posts from Wes Nolte can help.
http://th3silverlining.com/2011/01/25/salesforce-instantiating-an-sobject-at-run-time/
http://th3silverlining.com/2011/01/28/salesforce-programmatically-populating-sample-data-post-deployment/
~ Clint