3

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);
            lstResultWrapper.add(result);                
            system.debug('=============lstResultWrapper================='+lstResultWrapper);

    }

    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

3
  • Which line is throwing the NullPointerException? Commented Mar 11, 2016 at 19:26
  • @jonnybro lstResultWrapper.add(result); this line Commented Mar 11, 2016 at 19:27
  • Where is lstResultWrapper instantiated? Commented Mar 11, 2016 at 19:29

1 Answer 1

5

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.

3
  • its works.But now the problem is i cant able show that on the datatable Commented Mar 11, 2016 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. Commented Mar 11, 2016 at 19:36
  • salesforce.stackexchange.com/questions/113942/… pls visite this question Commented Mar 11, 2016 at 19:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.