You need to sign in to do that
Don't have an account?
Dynamic SOQL: extracting value from sObject field
Hi,
I think this should be quite straightforward question as everyone seem to know abt it. I didnt find any question similar to this on discussion board.
What I am trying to do is...this is just simplified version...
List<sObject> L = Database.query('select name, id from Account where id in : recordIds');
for (sObject c : L){
customObject__c customObject = new customObject__c();
customObject.name = c.get('name');
}
type of name is string. while c.get is returning something of type 'object'. how to convert object to string?
simple casting is not working. it fails at compile time only.
it will save me lots of extra lines of code, if I get solution for this.
I am not able to find in any document, of how to convert this object into string.
TIA.
regards,
Sandip
This was quite simple finally but took time to got it..as solution was other way round.
Object is anytype data type. to convert it to string, straight forward casting (string) object doesnt work.
You have to do String.valueOf(object) to get the string value of object. similar method exists for other standard data types like datetime, Integer, double.
regards
Sandip
All Answers
This was quite simple finally but took time to got it..as solution was other way round.
Object is anytype data type. to convert it to string, straight forward casting (string) object doesnt work.
You have to do String.valueOf(object) to get the string value of object. similar method exists for other standard data types like datetime, Integer, double.
regards
Sandip
I'm trying to get the body of an attachment into a String; there is no method Blob.valueOf(object). Only Blob.valueOf(String).
If I cast the object to a string it turns into this literal value "Blob[xxx]" where xxx = the size of the blob.
Anyone have any advice? I've worked around it by burning a SOQL query, but this shouldn't be necessary.
Blob b = (Blob)attach.get("Body");
Glorious!
I don't understand the syntax though, can you point me to somewhere (online) that explains it?
I saw some references to it in the SF Apex documentation but I (obviously) didn't understand how to use it.
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_classes_casting.htm