You need to sign in to do that
Don't have an account?
fetch lookup value
I have two fields Opportunity(Lookup) and Products (Picklist). On selection of opportunity i had written one soql query such that it retrieves only the products associated with opportunity. But it is not working.
<apex:actionRegion >
<apex:inputField value="{!lineitem.OpportunityId}" >
<apex:actionsupport event="onChange" action="{!getprods}" reRender="thePanel"/>
</apex:actionRegion>
<apex:selectList value="{!lineitem.custom__c}" size="1" id="thePanel">
<apex:selectOptions value="{!prods}">
</apex:selectOptions>
</apex:selectList>
and my controller is
public List<selectOption> getprods()
{
List<selectOption> options = new List<selectOption>();
opp = [select PriceBook2Id from Opportunity where Id=:lineitem.OpportunityId];
System.debug('sample'+opp);
for (PriceBookEntry product : [SELECT Name from PriceBookEntry where PriceBook2Id=:opp.PriceBook2Id])
{
options.add(new selectOption(product.Name, product.Name));
}
return options;
}
For an existing product it is working. But for a newly created record the page is not even opening and throwing an error "List has no rows for assignment to SObject"
In Controller just add if condition before for loop to check weather list is empty or not
if(opp.size()>0){
}
System.debug('Opportunity Id'+lineitem.OpportunityId);
If the value is passing then there is no records under that id or if value is not passed then there is problem with 'lineitem.OpportunityId'