2

I need to retrieve an Id value through 2 other values (of type string) :
each Id of an object can be identified by a code (Code__c) and another value (Value__c).

How can I retrieve this Id passing by the 2 other field ?

I thought use a Map<String, Id> so the key (String) would be the 2 others values and then I can retrieve the Id, but is it possible to concatenate the key ?

I have 2 value and I have to use only one... If you have any idea, thank you !

2 Answers 2

5

Yes, We can have two values concatenated in String as Key inside Map and Id as Value. We can retrieve the id by passing the Key (two other fields) as mentioned in below solution.

SOLUTION:

Map<String, ID> mapDemo = new Map<String, ID>();

Obj__c  t = [Select Id, Code__c, Value__c From Obj__c Limit 1];

//Putting Key and Value
String key = t.Code__c + t.Value__c ;
mapDemo.put(key , t.Id );

//Getting Id based on the two other field
Id objId = mapDemo.get(key);
3

Yes you can do something like

string temp = Code__c + '#'+Value__c
tempMap.Put(temp, recordid);

Now when you want to retrieve id then split the string or conact another string and then compare. it will help you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .