function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Fetch map values of related objects into if()?

I need help.I'm trying query records from three objects which are releted and use on particular field in if().See below code Im getting error 
Error: Compile Error: Variable does not exist: Product2 at line 39 column 86..Please help.
Map<id,Quote> QuoteProductMap=new Map<Id,Quote>([Select id,recordTypeId,Status,(Selectid,Product2.Name,Product2.Additional_Spe__c FROM QuoteLineItems)from Quote where Id in:newItems.keyset()]);
          for(Quote quoteToProduct:newItems.values()){
if(QuoteProductMap.get( listProductAttribute[0].Additional_spe__c)

v varaprasadv varaprasad
Hi Sunil,

Space is missing between id,product2
Map<id,Quote> QuoteProductMap=new Map<Id,Quote>([Select id,recordTypeId,Status,(Select id,Product2.Name,Product2.Additional_Spe__c FROM QuoteLineItems)from Quote where Id in:newItems.keyset()]);

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

@For Support:

Raghavendra Raj K SRaghavendra Raj K S
Hi Sunil,

Check the below code this might be helpful.
Map<id,List<QuoteLineItem>> QuoteProductMap = new Map<Id,List<QuoteLineItem>> ();

  List<QuoteLineItem> quoteLineItemsList = [Select id, QuoteId, Product2.Name, Product2.Additional_Spe__c FROM QuoteLineItem WHERE QuoteId IN : newItems.keyset()];
        for(QuoteLineItem qItem : quoteLineItemsList) {
            if(QuoteProductMap.containsKey(qItem.QuoteId)) {
            }else {
                QuoteProductMap.put(qItem.QuoteId, new List<QuoteLineItem>{qItem});        
        for(Id quoteId : QuoteProductMap.keyset()){
            for(QuoteLineItem  qItem :  QuoteProductMap.get(quoteId)) {
               if(qItem.Product2.Additional_Spe__c == listProductAttribute[0].Additional_spe__c) {