0

Class:

public void PNSearch(){
    //varible declarations
    parentId=Apexpages.currentPage().getParameters().get('id');
    //Query to retrieve all Quote line Items which are childs to current Quote
    list< Quote_line_Item__c> allQliList=[Select id,Name,Client_P_N__c,Comments__c,Quote1__r.Quoteopp_record_type__c,Quote1__r.Quoteopp_type__c,Quote1__c,Quote_Validity__c ,Description__c,Standard_Estimated_Lead_Time__c,createdDate,Other_Lead_Time__c  from Quote_Line_Item__c where Quote1__c=:parentId ORDER BY CreatedDate ] ;

    set<string> qliNameSet =new set<string>();
    List<String> qliNameList=new List<String>();
    list<Quote_line_Item__c> matchQliList=new list<Quote_line_Item__c>();
    List<Quote__c> QuoteList=new List<Quote__c>();
    Set<Id> nonMatchedQutIds=new Set<Id>();
    Set<id> QlId=new Set<Id>();
    Quote__c currentQuote;
    //creating instance to wrpper classes
    QuoteWrapperListTwo=new List<QuoteWrapperTwo>();
    QuoteWrapperListOne=new List<QuoteWrapperOne>();
    QuoteWrapperList=new List<QuoteWrapper>();
    // Declaring and creating instance to map
    map<id,List<Quote_line_Item__c>> allMatchedQlis= new map<id,List<Quote_line_Item__c>>();
    try{
        currentQuote=[select Account_Name__r.Name,id from Quote__c where id=:ParentId LIMIT 1];
    }catch(Exception e){System.debug('<----Quote exception------>'+e); }
    //condition to check quote lIne item  map size is greater than zero
    if(allQliList.size()>0){
        //iterating the loop to store the name quote line items in list and in set
        for(Quote_line_Item__c qli:allQliList){
            qliNameSet.add(qli.Name);
            qliNameList.add(qli.Name);
        }//End of for loop
        // Query to get all quoteline items  which are matched with current Quote line items names
        try{
            matchQliList=[Select id,Name,Quote1__r.Quote_Number_New__c,Quote1__r.Quoteopp_record_type__c,Quote1__r.Opportunity_Name__r.Name,Quote1__r.Opportunity_Name__c,Quote1__r.Quoteopp_type__c,Quote1__r.Account_Name__c,Quote1__r.Account_Name__r.Name,Quote1__r.createdDate,Quote1__r.Name,Quote1__c from Quote_line_Item__c where Quote1__c!=:ParentId And Name in:qliNameSet];
        }catch(Exception e){ system.debug('<----Quote line item exception--------- >'+e);}
        //Iterating the loop to store the Quote ids in to the set
        for(Quote_line_Item__c q:matchQliList){
            QlId.add(q.Quote1__c);
        }
        //Query to get all quoteline items  which are matched with current Quote line items names
        try{
            QuoteList=[Select id,Quote_Number_New__c,Quote__c.Quoteopp_type__c,Quote__c.Quoteopp_record_type__c,Opportunity_Name__r.name,Opportunity_Name__c,Account_Name__c,Account_Name__r.Name,createdDate,(select id,Name,Quote1__r.Quote_Number_New__c,Quote1__r.Account_Name__c,Quote1__r.Account_Name__r.Name,Quote1__r.createdDate,Quote1__r.Name from Quote__c.Quote_line_Items__r) from Quote__c where id in:QlId ORDER BY CreatedDate  desc LIMIT 50000];
        }catch(Exception e){ System.debug('<***** Quote line item exception****>'+e);}
        //Iterating the loop to place the quote line items in a map with key as Quote id and value as quoteline items
        for(Quote__c qut:QuoteList){
            List<Quote_line_Item__c> qliList=new List<Quote_line_Item__c>();
            for(Quote_line_Item__c ql:qut.Quote_line_Items__r){
                qliList.add(ql);
            }//End of for loop
            allMatchedQlis.put(qut.id,qliList);
        }//End of for loop
        //iterating the map to seperate the Quote values which have exact match with the current quote and non exact quotes
        for(Id mapkey:allMatchedQlis.keyset()){
            String accName=allMatchedQlis.get(mapkey)[0].Quote1__r.Account_Name__r.Name;
            List<String> dupQliNameList=new List<String>();
            //Iterating the loop to store all the Quoteline item's names for each quote
            for(Quote_line_Item__c qli:allMatchedQlis.get(mapkey)){
                dupQliNameList.add(qli.Name);
            }//End of for loop
            // sorting the lists which helps us to compare the current QUote line item name with other Quote child Quotelineitem's name
            dupQliNameList.sort();
            qliNameList.sort();
            //condition to check for exact match
            if(qliNameList.equals(dupQliNameList)&& allMatchedQlis.get(mapkey).size()==qliNameList.size()){
                // condition to check with the current account name and Adding values to display exact match with same accont
                if(accName==currentQuote.Account_Name__r.Name && mapkey!=ParentId){
                    QuoteWrapperTwo qwt=new QuoteWrapperTwo();
                    qwt.Quote_Name_Two=allMatchedQlis.get(mapkey)[0].Quote1__r.Name;
                    qwt.Quote_Id_Two=allMatchedQlis.get(mapkey)[0].Quote1__c;
                    qwt.Account_Name_Two=accName;
                    qwt.Account_Id_Two=allMatchedQlis.get(mapkey)[0].Quote1__r.Account_Name__c;
                    qwt.OPPtype_Two=allMatchedQlis.get(mapkey)[0].Quote1__r.Quoteopp_type__c;
                    qwt.OPPrecordtype_Two=allMatchedQlis.get(mapkey)[0].Quote1__r.Quoteopp_record_type__c;
                    qwt.OPPname_Two=allMatchedQlis.get(mapkey)[0].Quote1__r.Opportunity_Name__r.Name;
                    qwt.OPPid_Two=allMatchedQlis.get(mapkey)[0].Quote1__r.Opportunity_Name__c;
                    qwt.Quote_Num_Two=allMatchedQlis.get(mapkey)[0].Quote1__r.Quote_Number_New__c;
                    qwt.Count_Two=qliNameList.size();
                    qwt.CR_Date_Two=Date.valueOf(allMatchedQlis.get(mapkey)[0].Quote1__r.CreatedDate);
                    QuoteWrapperListTwo.add(qwt);
                }//End of if
                //Adding values to display exact match with different accont
                else{
                    QuoteWrapperOne qwt=new QuoteWrapperOne();
                    qwt.Quote_Name_One=allMatchedQlis.get(mapkey)[0].Quote1__r.Name;
                    qwt.Quote_Id_One=allMatchedQlis.get(mapkey)[0].Quote1__c;
                    qwt.Account_Name_One=accName;
                    qwt.Account_Id_One=allMatchedQlis.get(mapkey)[0].Quote1__r.Account_Name__c;
                    qwt.Quote_Num_One=allMatchedQlis.get(mapkey)[0].Quote1__r.Quote_Number_New__c;
                    qwt.OPPtype_one=allMatchedQlis.get(mapkey)[0].Quote1__r.Quoteopp_type__c;
                    qwt.OPPrecordtype_one=allMatchedQlis.get(mapkey)[0].Quote1__r.Quoteopp_record_type__c;
                    qwt.OPPname_one=allMatchedQlis.get(mapkey)[0].Quote1__r.Opportunity_Name__r.Name;
                    qwt.OPPid_one=allMatchedQlis.get(mapkey)[0].Quote1__r.Opportunity_Name__c;
                    qwt.Count_One=qliNameList.size();
                    qwt.CR_Date_One=Date.valueOf(allMatchedQlis.get(mapkey)[0].Quote1__r.CreatedDate);
                    QuoteWrapperListOne.add(qwt);
                }
            }//End of if
            //Storing non exact matched quote ids into a set
            else {
                nonMatchedQutIds.add(mapkey);
            }
        }//End of for loop
        //Query to get the Quote values in descending order depending on the counting of Quotelineitem names  which are in non exact match
        AggregateResult[] groupedResults   = [SELECT   COUNT_DISTINCT(Name) nameCount,count( Id ) idCount  ,MIN(Quote1__r.Quoteopp_record_type__c) OPPrecordtype ,MIN(Quote1__r.Quoteopp_type__c) OPPtype,MIN(Quote1__r.Opportunity_Name__c)  oppid, Min (Quote1__r.Opportunity_Name__r.Name) OPPname , Min( Quote1__r.Name  )   QuoteName  ,Min( Quote1__c  )   QuoteId  ,Min( Quote1__r.Account_Name__r.Name ) AccountName, Min( Quote1__r.Account_Name__c ) AccountId ,Min(Quote1__r.Quote_Number_New__c)QuoteNum, MIN(Quote1__r.CreatedDate) CRDate  FROM Quote_Line_Item__c  where   ( name in :qliNameSet  AND Quote1__c != null AND  Quote1__c in :nonMatchedQutIds)  Group By Quote1__r.Id ORDER BY COUNT_DISTINCT(Name) desc, MIN(Quote1__r.CreatedDate)desc];
        //Iterating the loop to display non exact matched quotes
        for(AggregateResult aggr:groupedResults){
            QuoteWrapper qw=new QuoteWrapper();
            qw.Quote_Name=String.valueOf(aggr.get('QuoteName'));
            qw.Quote_Id=String.valueOf(aggr.get('QuoteId'));
            qw.Account_Name=String.valueOf(aggr.get('AccountName'));
            qw.Account_Id=String.valueOf(aggr.get('AccountId'));
            qw.Quote_Num=String.valueOf(aggr.get('QuoteNum'));
            qw.Count=Integer.valueOf(aggr.get('nameCount'));
            qw.CR_Date=Date.valueOf(aggr.get('CRDate'));
            qw.oppid=String.valueOf(aggr.get('oppid'));
            qw.OPPtype=String.valueOf(aggr.get('OPPtype'));
            qw.OPPrecordtype=String.valueOf(aggr.get('OPPrecordtype'));
            qw.oppname=String.valueOf(aggr.get('oppname'));
            QuoteWrapperList.add(qw);
        }//End of for loop
    }//End of if
}//End of method

Vf page:

<apex:outputPanel id="panel"  >
            <div id="output1"></div>
            <div id="overlay1" class="web_dialog_overlay1"></div>
            <div id="dialog1" class="web_dialog1">
                <table style="width: 100%; border: 0px;" cellpadding="3" cellspacing="0">
                    <tr>            
                        <td class="web_dialog_title align_right1" colspan="8" >
                        <apex:commandbutton value="cancel" action="{!cancel1}" id="cancelId" immediate="True"/>
                        </td>
                    </tr>
                    <tr>      
                        <td width="20%" colspan="8"><b>Similar Nicomatic P/N : </b></td>            
                        </tr>
                        <tr>      
                        <td width="20%" colspan="8"><hr/></td>            
                    </tr> 
                    <tr>
                        <td><b>SF Quote No</b></td>
                        <td><b>NCM Quote No</b></td>
                        <td><b>Account Number</b></td>
                        <td><b>Opportunity Name</b></td>
                        <td><b>Opportunity Record Type</b></td>
                        <td><b>Opportunity Type</b></td>
                        <td><b>Created Date</b></td>
                        <td><b>Maximum Match </b></td>
                    </tr>
                    <tr><td colspan="8"><hr/></td></tr> 
                    <tr><td colspan="8"><b>Exact match with same Account</b></td></tr>
                    <apex:repeat value="{!QuoteWrapperListTwo}" var="a" > 
                        <tr> 
                            <td valign="top" width="20%"><a href="/{!a.Quote_Id_Two}" target="_blank">{!a.Quote_Name_Two}</a></td> 
                            <td valign="top" width="20%"><a href="/{!a.Quote_Id_Two}" target="_blank">{!a.Quote_Num_Two}</a></td> 
                            <td valign="top" width="20%"><a href="/{!a.Account_Id_Two}" target="_blank">{!a.Account_Name_Two}</a></td> 
                                <td valign="top" width="20%"><a href="/{!a.oppid_two}" target="_blank">{!a.oppname_two}</a></td>             
                            <td valign="top" width="20%">{!a.OPPrecordtype_two}</td> 
                            <td valign="top" width="20%">{!a.OPPtype_two}</td>             
                            <td valign="top" width="20%">    
                            <apex:outputText value="{0,date,dd'/'MM'/'yyyy}">
                            <apex:param value="{!a.CR_Date_Two}"/>
                            </apex:outputText>         
                            </td>
                            <td valign="top" width="20%" align="center" color="RED"><b>{!a.Count_Two}</b> 
                            </td> 
                        </tr>
                    </apex:repeat>
                    <tr><td colspan="8"><hr/></td></tr>       
                    <tr><td colspan="8"><b>Exact match with Other Account</b></td></tr>
                    <apex:repeat value="{!QuoteWrapperListOne}" var="a" > 
                        <tr> 
                            <td valign="top" width="20%"><a href="/{!a.Quote_Id_One}" target="_blank">{!a.Quote_Name_One}</a></td> 
                            <td valign="top" width="20%"><a href="/{!a.Quote_Id_One}" target="_blank">{!a.Quote_Num_One}</a></td> 
                            <td valign="top" width="20%"><a href="/{!a.Account_Id_One}" target="_blank">{!a.Account_Name_One}</a></td>
                                <td valign="top" width="20%"><a href="/{!a.oppid_one}" target="_blank">{!a.oppname_one}</a></td>             
                            <td valign="top" width="20%">{!a.OPPrecordtype_one}</td> 
                            <td valign="top" width="20%">{!a.OPPtype_one}</td>              
                            <td valign="top" width="20%">    
                            <apex:outputText value="{0,date,dd'/'MM'/'yyyy}">
                            <apex:param value="{!a.CR_Date_One}"/>
                            </apex:outputText>         
                            </td>
                            <td valign="top" width="20%" align="center" color="RED"><b>{!a.Count_One}</b> 
                            </td>            
                        </tr>
                    </apex:repeat> 
                    <tr><td colspan="8"><hr/></td></tr>     
                    <tr>
                        <td colspan="8"><b>Partnumbers Match</b>
                        </td>
                    </tr>
                    <apex:repeat value="{!QuoteWrapperList}" var="a" > 
                        <tr>
                            <td valign="top" width="20%"><a href="/{!a.Quote_Id}" target="_blank">{!a.Quote_Name}</a></td> 
                            <td valign="top" width="20%"><a href="/{!a.Quote_Id}" target="_blank">{!a.Quote_Num}</a></td> 
                            <td valign="top" width="20%"><a href="/{!a.Account_Id}" target="_blank">{!a.Account_Name}</a></td> 
                                <td valign="top" width="20%"><a href="/{!a.oppid}" target="_blank">{!a.oppname}</a></td>             
                            <td valign="top" width="20%">{!a.OPPrecordtype}</td> 
                            <td valign="top" width="20%">{!a.OPPtype}</td>             
                            <td valign="top" width="20%">    
                            <apex:outputText value="{0,date,dd'/'MM'/'yyyy}">
                            <apex:param value="{!a.CR_Date}"/>
                            </apex:outputText>         
                            </td>
                            <td valign="top" width="20%" align="center" color="Blue"><b>{!a.Count}</b> 
                            </td>                                                 
                        </tr>    
                    </apex:repeat>
                </table>
            </div>
        </apex:outputPanel>

Error: SObject row was retrieved via SOQL without querying the requested field: Quote__c.Quoteopp_type__c Error is in expression '{!PNSearch}' in component in page searchpn: Class.searchpn.PNSearch: line 108, column 1

I am used all the fields in soql query still it is saying the same error

Help me to resolve this issue

1 Answer 1

5

You can Check this link it may help, I have also faced the same problem and it was solved with this question.

Error message: SObject row was retrieved via SOQL without querying the requested field?

I guess the problem here is with

QuoteWrapper qw = new QuoteWrapper();
qw.Quote_Name = String.valueOf(aggr.get('QuoteName'));
qw.Quote_Id = String.valueOf(aggr.get('QuoteId'));
qw.Account_Name = String.valueOf(aggr.get('AccountName'));
qw.Account_Id = String.valueOf(aggr.get('AccountId'));
qw.Quote_Num = String.valueOf(aggr.get('QuoteNum'));
qw.Count = Integer.valueOf(aggr.get('nameCount'));
qw.CR_Date = Date.valueOf(aggr.get('CRDate'));
qw.oppid = String.valueOf(aggr.get('oppid'));
qw.OPPtype = String.valueOf(aggr.get('OPPtype'));
qw.OPPrecordtype = String.valueOf(aggr.get('OPPrecordtype'));
qw.oppname = String.valueOf(aggr.get('oppname'));

Here you are aggr.get where else in above lists you are accessing it directly with object.

You must log in to answer this question.

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