1

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 !

4

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);
| improve this answer | |
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.