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
pbattissonpbattisson 

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

 

pbattissonpbattisson
Hey Clint A couple of others have pointed those posts out but I don't think they help, although I am intrigued to know how Wes' Vdv handler deals with loading numeric values in from that string, it possibly has something to do with a nuance of the generation of a generic sobject through the typing he is using. I tried changing some of that code but I already have the sobject I need to populate and do not require a new one, and so the code still errors. I am going to create a ratty if based solution for the client poc but I will spend some time continuing this thought process. Thanks for the suggestions Paul
Dennis H PalmerDennis H Palmer
Did you ever get this resolved?