0 votes
1 view
in Salesforce by (13.1k points)

I was trying to display a selectList in a visualforce page using my custom controller. But get this error saying "list has no rows for assignment to SObject".

Herewith I have attached my page and my controller.

My Page :

<apex:page Controller="BpmIcountPayment">

<apex:form >

    <apex:selectList value="{!productsTitle}" multiselect="false">

        <apex:selectOptions value="{!ProductsLov}"></apex:selectOptions>

    </apex:selectList>

</apex:form>

</apex:page>

My controller :

public class BpmIcountPayment{

    private final Account account;

    public String productsTitle {

      get { return 'products for sale'; }

      set;

    }

    public BpmIcountPayment() {

        account = [SELECT Id, Name, Site FROM Account

                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];

    }

    public Account getAccount() {

        return account;

    }

    public List<SelectOption> getProductsLov() {

        List<SelectOption> products = new List<SelectOption>();

        List<Product2> productsList = [SELECT Id, Name, Family 

                                       FROM Product2 

                                       WHERE (Family = 'ShopProduct') 

                                       OR (Family = 'CourseParent') 

                                       OR (Family = 'SFCourseProgram')];

        for (Product2 currProduct : productsList) {

            products.add(new SelectOption(currProduct.Id, currProduct.Name));

        }

        return products;

    }

}

Can anyone help me with this?

1 Answer

0 votes
by (26.7k points)

If you are getting an error, which means that you are assigning to a single object.

Below code will help you, to minimize your code.

public BpmIcountPayment(ApexPages.StandardController sc){

    if(String.isBlank(sc.getId()){

        System.debug('you screwed up passing the valid acc id');

    } else {

        acc = (Account) sc.getRecord();

    }

}

I hope this work.

Want to become an Salesforce Expert? join salesforce lightning training now!!

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...