1

I need to have a Map<Id, List<String>> or a Map<Id, List<Custom_Object__c>> to store this data:

Id = Id of the record that is above, List<String>/List<Custom_Object__c> = Store an id and a type of the records below.

After that, I need to validate if the type is not xxx and store the id of bellow object, but I don't know how to do this in both ways, because:

  • If I used the List<String> I would store in one index like this: Id + ' - ' + Type and I would need to check if contains(), the problem is that the check if is totally equal, and it would not be the case because has the id and type;
  • And if I used the List<Custom_Object__c> I would just store the object and look the type field, but I don't know how to do this either, I tried access the type field after the get() but it said that doesn't exist this field. The only wrong solution that I could reach (I would like to avoid loop inside loop):
for(Id objId : customObjectMap.keySet()){
     if(!(customObjectMap.get(objId).contains('XXXX') && customObjectMap.get(objId).contains('ZZZZ'))){
        //action to store the Id of the record bellow in a list
     }
}
3
  • 2
    What you want is a composite key. Unfortunately, you've simplified your question to the point where I can't write concrete code example(s). Consider making an edit to your question to be as reasonably detailed as possible.
    – sfdcfox
    Commented Dec 20, 2022 at 19:47
  • Thanks! What I need to detail? Basic I wanna know which is the best approach and how to implemented, it could be a generic way only so I can understand the logic. The implement doubt it's for example, if the list of object is the best way and how can I see if the field type inside this list is equal to XXXX
    – Alexia
    Commented Dec 20, 2022 at 20:00
  • I mean, it sounds like you want to create/map a child record given a parent id and a property on the child, correct? That can be serviced with a simple Map<Custom_Object__c, Custom_Object__c>, where the key is a composite key consisting of the parent Id and the type. You can easily find matching records using a composite key this way without Id-Type keys or such, which you said won't work for some reason... we're just trying to understand the logic behind what you're trying to do. See the X-Y problem for more info.
    – sfdcfox
    Commented Dec 20, 2022 at 20:24

0

You must log in to answer this question.

Browse other questions tagged .