You need to sign in to do that
Don't have an account?
Frank Jordan
Apex Class with Button error: List has no rows for assignment to SObject
I have a class that is updating the owner of a record when the Submit to Legal button on the "Agreement Request" object is pressed. I am running into the "List has no rows for assignment to SObject" error when pressing the button and i'm not sure why. Below is my code:
public with sharing class classSubmitToLegal {
public Agreement_Request__c a{get;set;}
public classSubmitToLegal() {
a = new Agreement_Request__c ();
a = [select Business_Unit__c from Agreement_Request__c Where Id=: ApexPages.currentPage().getParameters().get('Id')];
}
public void someMethod() {
if(a.Business_Unit__c == 'EIS') {
a.Business_Unit__c = 'EIS Queue';
update a;
Apexpages.Message errorMessage = new Apexpages.Message(ApexPages.Severity.Info,'You have changed the owner');
Apexpages.addMessage(errorMessage);
} else {
Apexpages.Message errorMessage = new Apexpages.Message(ApexPages.Severity.Info,'You cannot update');
Apexpages.addMessage(errorMessage);
}
}
}
public with sharing class classSubmitToLegal {
public Agreement_Request__c a{get;set;}
public classSubmitToLegal() {
a = new Agreement_Request__c ();
a = [select Business_Unit__c from Agreement_Request__c Where Id=: ApexPages.currentPage().getParameters().get('Id')];
}
public void someMethod() {
if(a.Business_Unit__c == 'EIS') {
a.Business_Unit__c = 'EIS Queue';
update a;
Apexpages.Message errorMessage = new Apexpages.Message(ApexPages.Severity.Info,'You have changed the owner');
Apexpages.addMessage(errorMessage);
} else {
Apexpages.Message errorMessage = new Apexpages.Message(ApexPages.Severity.Info,'You cannot update');
Apexpages.addMessage(errorMessage);
}
}
}
Below query is not returning any records.Thats the reason of issue:
NOTE: When adding code please use the "Add a code sample" button (icon <>) to increase readability and make it easier to reference.
NOTE: When adding code please use the "Add a code sample" button (icon <>) to increase readability and make it easier to reference.
I did update the .get to use a lowercase id instead of the uppercase Id. This sometimes makes a difference as well.