I want update list of opportunities using visualforce page.In visualforce page I want to update Amount,close date and Stage.The visulaforce page should only show all open opportunities(STAGE NOT EQUALS TO CLOSED WON AND CLOSED LOST).
Anyone help me to fix this error and update only all open opportunities.
Here is my code:
Apex
public class UpdateListofOppty {
public Opportunity opportunities {get;set;}
public Id recId{get;set;}
public UpdateListofOpporunity(ApexPages.StandardSetController sc){
recId = ApexPages.CurrentPage().getParameters().get('id');
opportunities = [SELECT Name,Amount,StageName FROM opportunity WHERE Id = :recId AND StageName NOT IN ('Closed Lost', 'Closed Won')];
}
public Opportunity getOpptyDetail(){
return opportunities;
}
public PageReference Save() {
try{
update(opportunities);
}
catch(System.DmlException e){
ApexPages.addMessages(e);
return null;
}
PageReference view = new ApexPages.StandardController(opportunities).view();
return (view);
}
}
VF Page
<apex:page standardController="Opportunity" extensions="UpdateListofOppty" recordSetVar="opportunities" tabStyle="Opportunity" sidebar="false">
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!opportunities}" var="opp">
<apex:column value="{!opp.name}"/>
<apex:column headerValue="Amount">
<apex:inputField value="{!opp.Amount}"/>
</apex:column>
<apex:column headerValue="Close Date">
<apex:inputField value="{!opp.CloseDate}"/>
</apex:column>
<apex:column headerValue="Stage">
<apex:inputField value="{!opp.stageName}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
ERROR:
System.QueryException: List has no rows for assignment to SObject
Error shown in this line:
opportunities = [SELECT Name,Amount,StageName FROM opportunity WHERE Id = :recId AND StageName NOT IN ('Closed Lost', 'Closed Won')];