Reply
Regular Contributor
thunksalot
Posts: 82
0
Accepted Solution

Convert ID to string?

I want to concatenate two object IDs in order to make a hash value for a map, but this doesn't work:

 

conversionMap.put(entry.Pricebook2Id + entry.Product2Id), entry);

If I could convert the IDs to strings first, then I should be able to concatenate them in this way.  But, while there is a function to convert a string to an ID, I can't find any way to convert an ID to a string.  Anybody know how to do that?  Or, a better way to do what I'm trying to do?

 

Regular Contributor
SimonJai
Posts: 28
0

Re: Convert ID to string?

Haven't tested it completely but give this a go.

 

String newID = '' + entry.pricebook2Id + entry.Product2Id;
Super Contributor
sfdcfox
Posts: 3,883
0

Re: Convert ID to string?

You can also use String.valueOf(entry.Pricebook2Id)+String.valueOf(entry.Product2Id).

~ sfdcfox ~


I am a sandwich. That is all.

Regular Contributor
thunksalot
Posts: 82
0

Re: Convert ID to string?

Thank you both for your quick replies.  I tested both methods and they both worked. 

 

I swear I had already tried String.valueOf() and I got an error.  But when I tried it again now, it worked.  User error!