1

I a using the code below to compare lists of records from 2 different Objects - Resource__c and RateCardItem__c.

There is no lookup field on the Resource__c to the RateCardItem. However the CombinationKey__c on the RateCardItem__c is the a combination of the Resource__c Location__c and ActivityRole__c fields separated by a :

I have this working to Output the records when the Resource Combination Key (resourceKey) matches a value in the RateCardItemsMap.

When there is a match I would like to return the Rate__c value from the RateCardItem__c on Line 40, but cannot figure out the best method.

String RateCardId='a6w4J000000UEQx';

List<Resource__c> resources = [
    Select 
        Id,
        Location__c,
        ActivityRole__c
    From Resource__c
    where 
        StandardCost__c=0
    ];

System.debug('Resources = ' + resources.size());

List<RateCardItem__c> ratecarditems = [
    Select
        Id,
        CombinationKey__c,
        Rate__c
    From RateCardItem__c
    Where 
        RateCard__c=:RateCardId
    ];

System.debug('Rate Card Items = ' + ratecarditems.size());

map<string,RateCardItem__c> ratecarditemsMap = new map<string,RateCardItem__c>();

for(RateCardItem__c rci : ratecarditems){
    string rciKey = rci.CombinationKey__c;
    ratecarditemsMap.put(rciKey,rci);
}

for(Resource__c r : resources){
   
   string resourceKey = r.Location__c +':'+r.ActivityRole__c;
   
   if(ratecarditemsMap.containsKey(resourceKey)){
     
       System.debug('Match for Reource ' + r.id + ratecarditemsMap);
   }
   else{
        System.debug('No Match for Resource ' + r.id);
   }
}

1 Answer 1

0

I figured it out - I changed line 40 to

System.debug('Match for Reource ' + r.id + ratecarditemsMap.get(resourceKey).Rate__c);

You must log in to answer this question.

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