0

When im running the below soql its work fine

SELECT BillingCountry,BillingCity, Industry, (SELECT Id, Name,Amount , StageName FROM Opportunities) FROM Account  WHERE BillingCountry = 'USA'

its work fine but when i customized this query into

SELECT BillingCountry,BillingCity, Industry, (SELECT Id, Name,Amount , StageName FROM Opportunities) FROM Account

salesforce returing this error.

Here is the method where i run this query

public PageReference find() 
    {         
        String id = UserInfo.getUserId();
        User activeUser = [Select Email From User where id = :id limit 1];
        String email = activeUser.Email;

        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

        req.setEndpoint('http://52.37.182.4/public/checkUser/'+email);
        req.setMethod('GET');
        req.setCompressed(false);
        req.setBody('key1=value1&key2=value2');
        req.setHeader('Content-Type', 'application/json'); 

        try {
            res = http.send(req);
        } catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
        }

        Boolean userExsist = (Boolean)JSON.deserialize(res.getBody(), Boolean.class);

        if(!userExsist)
        {
            showPopup();
            return null;
        }                            

        lstResultWrapper = new List<ResultWrapper>();
        for(Account c : [SELECT BillingCountry,BillingCity, Industry, (SELECT Id, Name,Amount , StageName FROM Opportunities) FROM Account WHERE BillingCountry='USA'])
        {
                req.setEndpoint('http://52.37.182.4/public/checkDeal/'+c.Opportunities[0].Name);
                req.setMethod('GET');
                req.setCompressed(false);
                req.setBody('key1=value1&key2=value2');
                req.setHeader('Content-Type', 'application/json'); 

                try {
                    res = http.send(req);
                } catch(System.CalloutException e) {
                    System.debug('Callout error: '+ e);
                    return null;
                }

                Boolean dealExsist = (Boolean)JSON.deserialize(res.getBody(), Boolean.class);

// error indicating on the below line       
                ResultWrapper result = new ResultWrapper(c,c.Opportunities, !dealExsist);
                lstResultWrapper.add(result);                                    

        }

        return null;
    }     

Edited : enter image description here enter image description here

Visual Force page

<apex:pageBlock id="tableId2">
                 <apex:outputText value="{!result}"></apex:outputText> 
                <apex:pageBlockTable value="{!lstResultWrapper}" var="items" id="table">

                    <apex:column headerValue="Deal Title"> 
                    <apex:outputText value="{!items['opportunity'].Name}"/> 
                    </apex:column> 

                    <apex:column headerValue="Deal Value"> 
                    <apex:outputText value="{!items['opportunity'].Amount}"/> 
                    </apex:column> 

                    <apex:column headerValue="Stage"> 
                    <apex:outputText value="{!items['opportunity'].StageName}"/> 
                    </apex:column> 

                    <apex:column headerValue="Industry"> 
                    <apex:outputText value="{!items['account'].Industry}"/> 
                    </apex:column> 

                    <apex:column headerValue="Country"> 
                    <apex:outputText value="{!items['account'].BillingCountry}"/> 
                    </apex:column> 

                    <apex:column headerValue="City"> 
                    <apex:outputText value="{!items['account'].BillingCity}"/> 
                    </apex:column> 


                    <apex:column headerValue="Action"> 
                        <apex:commandButton value="Find Clozer" onclick="displayResult" action="{!createDeal}" rendered="{!IF(items['isCreated'], false, true)}" rerender="tableId2,table" >
                            <apex:param name="title" value="{!items['opportunity'].Name}" assignTo="{!title}" />
                             <apex:param name="dealValue" value="{!items['opportunity'].Amount}" assignTo="{!dealValue}" />
                             <apex:param name="stageName" value="{!items['opportunity'].StageName}" assignTo="{!stageName}" />
                             <apex:param name="ind" value="{!items['account'].Industry}" assignTo="{!ind}" />
                             <apex:param name="count" value="{!items['account'].BillingCountry}" assignTo="{!count}" />
                             <apex:param name="cty" value="{!items['account'].BillingCity}" assignTo="{!cty}" /> 
                        </apex:commandButton>
                    </apex:column>
                </apex:pageBlockTable>        
6
  • Add LIMIT 1 in your soql – Ratan Paul Apr 12 '16 at 17:13
  • at what line you are seeing this error ? – Himanshu Apr 12 '16 at 17:19
  • You can do for(List<Account> ... > but I don't know what your trying to do – EricSSH Apr 12 '16 at 17:27
  • Are you sure that line lstResultWrapper.add(result); throws an exception of type System.QueryException ? It seems rather impossible. – Bart Juriewicz Apr 12 '16 at 17:35
  • @Himanshu i put a comment above the line where the error occur – moin khan Apr 12 '16 at 17:46
0

You need to update your ResultWrapper which currently accepting single opportunity but you are passing c.Opportunities which is list of opportunity so modify your ResultWrapper to accept list.

ResultWrapper result = new ResultWrapper(c,c.Opportunities, !dealExsist);

Wrapper class

public class ResultWrapper{
  public Account account {get;set;} 
  public List<Opportunity> opportunity {get;set;} 
  public Boolean isCreated {get;set;}

  public ResultWrapper(Account acc,List<Opportunity> opt,Boolean alreadyCreated) { 
         this.account = acc; 
         this.opportunity = opt; 
         this.isCreated = alreadyCreated; 
 } 
}

I don't know what is your logic behind this wrapper class but if you want to user single opportunity there is no need to modify wrapper class only pass single opportunity as shown below

ResultWrapper result = new ResultWrapper(c,c.Opportunities[0], !dealExsist);
8
  • here is my wrapper class public class ResultWrapper{ public Account account {get;set;} public Opportunity opportunity {get;set;} public Boolean isCreated {get;set;} public ResultWrapper(Account acc,Opportunity opt,Boolean alreadyCreated) { this.account = acc; this.opportunity = opt; this.isCreated = alreadyCreated; } } – moin khan Apr 12 '16 at 17:52
  • what changs should i make there – moin khan Apr 12 '16 at 17:52
  • check the updated code – Himanshu Apr 12 '16 at 17:59
  • i am using the wrapper class to display the data into the datatable.For making you more clear here is the code.I update my post pls have a look – moin khan Apr 12 '16 at 18:07
  • i assume that you have one single opportunity for every account if yes gor for last line of my answer don't modify wrapper class – Himanshu Apr 12 '16 at 18:10

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.