0

I want to display opportunities on inline VF page on Lead page layout. But it is giving error

List has more than 1 row for assignment to SObject

Here is my code :

Class :

public class sampleDetailPageCon {
    public List<Opportunity> oppz;
    //public Opportunity op;
    public Lead lead; 
    public sampleDetailPageCon(ApexPages.StandardController controller) {
        this.lead= (Lead)controller.getRecord();
    }
    public List<Opportunity> getOppz()
    {
        Lead l = [Select id,Name,OwnerId FROM Lead];
        oppz = [Select id, Name, Account.Name, CloseDate, Amount, Type from Opportunity where OwnerId IN: l.OwnerId limit 10];
        return oppz;
    }
}

1 Answer 1

1

Your lead SOQL returning all the leads instead of single lead so add your lead.id in that SOQL so that it can get single record.

update your following code as shown below

    public List<Opportunity> getOppz()
    {
        /**************updated code**************************/
        Lead l = [Select id,Name,OwnerId FROM Lead where id =: this.lead.id];
        /****************************************/
        if (l.OwnerId== null)
         return null;
        oppz = [Select id, Name, Account.Name, CloseDate, Amount, Type from Opportunity where OwnerId IN: l.OwnerId limit 10];
        return oppz;
    }

You must log in to answer this question.

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