You need to sign in to do that
Don't have an account?
Venkateshwarrao Admin
While savethepage I am getting error for "System.QueryException: List has no rows for assignment to SObject"
Code:
<apex:page controller="Mycontroller" tabStyle="Account">
<apex:form >
<apex:pageBlock title="AccountDetails">
<apex:pageBlockSection title="Accountinformation">
<apex:inputField value="{!Account.Name}"/>
<apex:inputField value="{!Account.Phone}"/>
<apex:inputField value="{!Account.Fax}"/>
<apex:inputField value="{!Account.ShippingCity}"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Account Detail">
<apex:inputField value="{!Account.Annualrevenue}"/>
<apex:inputField value="{!Account.Website}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!Save}" value="SavethePage"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Class:
public with sharing class Mycontroller
{
Public Account acc;
Public Mycontroller()
{
try{
acc=[SELECT Id,Name,Phone,Fax,ShippingCity,Website,AnnualRevenue from account Where Id=:ApexPages.CurrentPage().getparameters().get('Id')];
}
catch (Exception e) {
acc= new Account();
}
}
public Account getaccount()
{
return acc;
}
Public Pagereference Save()
{
Update acc;
Pagereference page=New ApexPages.standardController(acc).View();
return page;
}
}
Please any one provide me the solution. and tell me steps i have to follow
Custom page
While savethepage I am getting error for "System.QueryException: List has no rows for assignment to SObject"
Code:
<apex:page controller="Mycontroller" tabStyle="Account">
<apex:form >
<apex:pageBlock title="AccountDetails">
<apex:pageBlockSection title="Accountinformation">
<apex:inputField value="{!Account.Name}"/>
<apex:inputField value="{!Account.Phone}"/>
<apex:inputField value="{!Account.Fax}"/>
<apex:inputField value="{!Account.ShippingCity}"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Account Detail">
<apex:inputField value="{!Account.Annualrevenue}"/>
<apex:inputField value="{!Account.Website}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!Save}" value="SavethePage"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Class:
public with sharing class Mycontroller
{
Public Account acc;
Public Mycontroller()
{
try{
acc=[SELECT Id,Name,Phone,Fax,ShippingCity,Website,AnnualRevenue from account Where Id=:ApexPages.CurrentPage().getparameters().get('Id')];
}
catch (Exception e) {
acc= new Account();
}
}
public Account getaccount()
{
return acc;
}
Public Pagereference Save()
{
Update acc;
Pagereference page=New ApexPages.standardController(acc).View();
return page;
}
}
Please any one provide me the solution. and tell me steps i have to follow
Please change your Vf page and class code as follows :
VF : Class : Let me know if you have any issue.
Regards,
Abhishek
I was able to execute the code successfully.
Please find the below steps that I have followed,
- Saved the code you posted as apex class and VF page
- click preview button of VF page and add the parameter Id like this ex: ?id=RecordIdOfAccount
- Replace RecordIdOfAccount with your Accout record Id
Thanks,Vinoth