You need to sign in to do that
Don't have an account?
Mahitha Vaka 9
Getting "Content cannot be displayed: List has no rows for assignment to SObject" on the custome object VF page?
Hi, I have created the below VF page and controller, but i am getting "Content cannot be displayed: List has no rows for assignment to SObject".
please advice on how to fix this.
<apex:page Controller="MyController" Tabstyle="Account">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!Save}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!account.contacts}" var="contact">>
<apex:column headerValue="First Name"><apex:inputField value="{!contact.firstname}"/></apex:column>
<apex:column headerValue="Last Name"><apex:inputField value="{!contact.lastname}"/></apex:column>
<apex:column headerValue="Phone Number"><apex:inputField value="{!contact.phone}"/></apex:column>
<apex:column headerValue="E-mail"><apex:inputField value="{!contact.email}"/></apex:column>
<apex:column headerValue="Title"><apex:inputField value="{!contact.title}"/></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class MyController {
private final Account account;
public MyController() {
account = [SELECT Id, Name, Site FROM Account
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
public Account getAccount() {
return account;
}
public PageReference save() {
update account;
return null;
}
}
please advice on how to fix this.
<apex:page Controller="MyController" Tabstyle="Account">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!Save}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!account.contacts}" var="contact">>
<apex:column headerValue="First Name"><apex:inputField value="{!contact.firstname}"/></apex:column>
<apex:column headerValue="Last Name"><apex:inputField value="{!contact.lastname}"/></apex:column>
<apex:column headerValue="Phone Number"><apex:inputField value="{!contact.phone}"/></apex:column>
<apex:column headerValue="E-mail"><apex:inputField value="{!contact.email}"/></apex:column>
<apex:column headerValue="Title"><apex:inputField value="{!contact.title}"/></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class MyController {
private final Account account;
public MyController() {
account = [SELECT Id, Name, Site FROM Account
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
public Account getAccount() {
return account;
}
public PageReference save() {
update account;
return null;
}
}
NOTE:- The standard controller requires record context that can be provided by including a URL parameter named ‘id’ and assigned with a valid 15- or 18-digit record ID. The record specified by the ID must match the sObject type associated with the StandardController on the page, or an error will be thrown when the page attempts to render:
This is slightly different than the URL pattern to access a standard detail page for any record, which simply requires that the record id follow the Salesforce server instance name:
Let us know if this will help you