You need to sign in to do that
Don't have an account?

System.QueryException: List has no rows for assignment to SObject
hi I am getting this Error Colud you Please Check... Error:System.QueryException: List has no rows for assignment to SObject
Class.Mysecondcontroller.<init>: line 4, column 1
here is My Apex Class and VF Code
Class.Mysecondcontroller.<init>: line 4, column 1
here is My Apex Class and VF Code
public class Mysecondcontroller { Public Opportunity opp; Public Mysecondcontroller(){ Opp=[select id, name,CloseDate,StageName from Opportunity where id=:ApexPages.currentpage().getParameters().get('Id')]; } Public Opportunity getOpportunity(){ return opp; } Public pageReference SaveMethod(){ Update Opp; return null; } }
<apex:page controller="Mysecondcontroller" tabStyle="Opportunity"> <apex:form > <apex:pageBlock title="Opportunity Detail"> <apex:pageBlockButtons > <apex:commandButton value="Save The Opportunity" action="{!SaveMethod}"/> </apex:pageBlockButtons> <apex:pageblockSection title="Opportunity" Columns="2" collapsible="False"> <apex:inputField value="{!Opportunity.Name}"/> <apex:inputField value="{!Opportunity.CloseDate}"/> <apex:inputField value="{!Opportunity.StageName}"/> </apex:pageblockSection> </apex:pageBlock> </apex:form> </apex:page>
i think you no need to write query
just create instance for opportunity.then you will get expected output.
public class Mysecondcontroller
{
Public Opportunity opp{get;set;}
Public Mysecondcontroller()
{
opp=new Opportunity();
}
Public pageReference SaveMethod(){
Update Opp;
return null;
}
}
Thanks,
Jagan
jagan.srit@gmail.com