You need to sign in to do that
Don't have an account?
Ghanesan
List has no rows for assignment to SObject - Apex/VfPage
Hi ,
Getting this error "List has no rows for assignment to SObject"
Trying to create button through vf page. When button is clicked, the date field should update. below is my code.
Controller:
public class ResignationButtonClass {
public Employee_Information__c emp;
public ResignationButtonClass() {
emp = [SELECT DN_Employee_ID__c FROM Employee_Information__c
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
public Employee_Information__c getemp() {
return emp;
}
public PageReference Resign() {
pagereference redirect = new PageReference('/apex/newPage');
emp.DN_Resignation_Date__c= System.today();
update emp;
return null;
}
}
VF Page:
<apex:page controller="ResignationButtonClass" >
<apex:form >
<apex:commandbutton value="Resign" action="{!Resign}"/>
</apex:form>
</apex:page>
Getting this error "List has no rows for assignment to SObject"
Trying to create button through vf page. When button is clicked, the date field should update. below is my code.
Controller:
public class ResignationButtonClass {
public Employee_Information__c emp;
public ResignationButtonClass() {
emp = [SELECT DN_Employee_ID__c FROM Employee_Information__c
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
public Employee_Information__c getemp() {
return emp;
}
public PageReference Resign() {
pagereference redirect = new PageReference('/apex/newPage');
emp.DN_Resignation_Date__c= System.today();
update emp;
return null;
}
}
VF Page:
<apex:page controller="ResignationButtonClass" >
<apex:form >
<apex:commandbutton value="Resign" action="{!Resign}"/>
</apex:form>
</apex:page>
In the Vf you are just calling only one method which is Resign(). Do you mean the other methods were not needed in Aepx class?
Thanks,
I can't tell which line of code you're getting this error in. But according to your code, this line might be the problem:
emp = [SELECT DN_Employee_ID__c FROM Employee_Information__c
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
To avoid this error, you can
1 - Check that this statement returns the correct value: ApexPages.currentPage().getParameters().get('id')
2 - Check that the id returned by ApexPages.currentPage().getParameters().get('id') is an Employee_Information__c id.