this error is occurring ?? Here is my code.Where i mistook ?

public PageReference find() 
    for(Account c : [SELECT BillingCountry, Industry, (SELECT Id, Name,Amount , StageName FROM Opportunities) FROM Account WHERE BillingCountry = 'USA'])
            ResultWrapper result = new ResultWrapper(c,c.Opportunities);


    return null;

public class ResultWrapper{

    public Account account {get;set;}
    public Opportunity opportunity {get;set;}

    public ResultWrapper(Account acc,Opportunity opt)
        this.account = acc;
        this.opportunity = opt;

Thanks in Advance

  • Which line is throwing the NullPointerException? – jonnybro Mar 11 '16 at 19:26
  • @jonnybro lstResultWrapper.add(result); this line – moin khan Mar 11 '16 at 19:27
  • Where is lstResultWrapper instantiated? – jonnybro Mar 11 '16 at 19:29

Seems you have a type mismatch

c.Opportunities is of type List<Opportunity>, but your constructor uses just one opportunity: public ResultWrapper(Account acc,Opportunity opt)

Also, add lstResultWrapper = new List() before your loop.

  • its works.But now the problem is i cant able show that on the datatable – moin khan Mar 11 '16 at 19:35
  • Moin, do me a favor, then. Mark this question as accepted and open a new one with your datatable problem (include VF code, please). I'll go in there and help you as well. – Sebastian Kessel Mar 11 '16 at 19:36
  • salesforce.stackexchange.com/questions/113942/… pls visite this question – moin khan Mar 11 '16 at 19:44

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.