2

I am unable to get a for loop for Maps working, I am new at this if you could, I would greatly appreciate it.

I am just trying to iterate the the Trigger.oldMap keys, and, everything I try gives me a different error:

Error: Compile Error: Initial term of field expression must be a concrete SObject: Map at line 27 column 34

for( Map<Id, Quote__c> oldQuote :  Trigger.oldMap.getkeys() ) {
            if (oldQuote.quoteID__c == null) {
                sentQuoteIds.add(oldQuote.Id);            
            }

those are lines 25-27, I substitued these generic values and fields: to Quote__c and oldQuote.QuoteID__c from original custom objects and fields, but, I think the answer will be the same.

Any help would be greatly appreciated.

this is my first question please forgive me if I my etiquette is off

3

There is no method called getkeys() instead use keyset() to get all Ids

So you are using Trigger.oldMap.keyset() means it is set<Id> i.e. Quote__c ids

for( Id objId :  Trigger.oldMap.keyset() ) {
   if (Trigger.oldMap.get(objId).quoteID__c == null) {
      sentQuoteIds.add(oldQuote.Id);            
   }
}

So based key you can get object and there field values like Trigger.oldMap.get(objId).quoteID__c


Best way is just iterate over Trigger.oldMap.values() this will return list of Quote__c

for( Quote__c oldQuote:  Trigger.oldMap.Values() ) {
    if (oldQuote.quoteID__c == null) {
        sentQuoteIds.add(oldQuote.Id);            
    }
}

Let me know if this solved your issue or not.

More info check doc Map_methods

  • Thank you for the very quick response, unfortunately, I can't get it working, I get : Error: Compile Error: Loop variable must be of type SObject at line 31 column 28. I tried both ways. Thanks. – Mark Kogon Jan 23 '16 at 6:40
  • @MarkKogon Can you just update you code in your ques ? Are you using Trigger.oldMap.Values() or Trigger.oldMap.keyset() ? – Ratan Paul Jan 23 '16 at 7:12
  • I think I solved the issue, I think my problem was that I was going into a loop of Trigger.oldMap(Values), when I just needed to refer to the oldMap values while inside the Trigger.new loop. Thanks again for the quick response. – Mark Kogon Jan 23 '16 at 7:14
  • I somehow solved this before seeing your latest post a couple of minutes ago, but, I greatly appreciate the followup. Thanks again. – Mark Kogon Jan 23 '16 at 7:16
  • Yes, that is no problem, except, this is my first day on this site, can you tell me what to do, I have to jump off the computer for a few minutes, I will look into how to do it when I get back. Thanks. – Mark Kogon Jan 23 '16 at 7:25

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.