You need to sign in to do that
Don't have an account?
Emmanuel B.
Id.valueOf static method not working
Hi,
I have a custom field where is stored a 15 digits Id.
I need to build a String csv with the 18 digits version of this Id.
In my Execute anonymous window, I tried a simple
system.debug(Id.valueOf('101c00000001GWe'));
and got
USER_DEBUG|[2]|DEBUG|101c00000001GWeAAM
Wonderful, that's what I need ! But when I try to write in my class
csv += Id.valueOf(var);
I get an ugly
Save error: variable does not exist: Id
I finally did what I need by creating a variable with
Id myId = String.valueOf(var); csv += myId;
But I don't understand why the documented static method Id.valueOf works in anonymous code and not in a class ?
There is not any method like id.valueOF(). You can apply String.valueof('id here') method.
For example
String s = '101c00000001GWe';
ID =s;
Hi,
Sure there is, in addition of what I wrote about the working anonymous code (but there was a mistake, I wrote string instead of ID), here is a paste of my Force.com Apex Code Developer's guide :
ID Methods
The following are the static methods for ID.
Method : valueOf
Arguments : String s
Return Type : ID
Description : Convertst he specified String into an ID
and returns the ID.
csv += Id.valueOf(var);
Is csv an ID field? Maybe it's getting confused because you're treating it as a string?
I've used this syntax in some of classes and never encountered the issue. Though my code doesn't use it with a string literal.
Also, mainly I ask because i'd do it but is it possible that you type Ld instead of Id?
Well it's a long time ago but I must admit that, even if I hate this idea, I could have written LD instead of Id because I tried again and now it works perfectly, and if I write Ld I have the error message described up there.
However I still doubt it because I probably pasted the error message in my post and it actually is a I in the message.
Maybe the last revisions of salesforce fixed it ? @DouglasCAyers : did you find the same problem ?
Anyway, it works, that's what matters :)
Where obj is a generic SObject and field a String (the name of the object field).
But why this message ?... At least I didn't type a L for a I :)
Everything will work like a charm!.
Mark it as the Best answer if it helps!!!!