You need to sign in to do that
Don't have an account?
Drew Salazar 5
Apex Class Extension error message issue?
I am new to Apex and I am having trouble with changing the record type of a record on a visualforce page. Here is what is happening.
If I try to use this as an Apex Class,
And reference this extension on the visualforce page like this.
I get this error.
Visualforce Error
System.QueryException: List has no rows for assignment to SObject
Error is in expression '{!setRecordType}' in component <apex:page> in page accountdetailbutton: Class.LoadRecordType.setRecordType: line 10, column 1
Class.LoadRecordType.setRecordType: line 10, column 1
Im kind of a visualforce Newb. Can someone help me figure out why this is happening?
If I try to use this as an Apex Class,
public class LoadRecordType { Account a; public LoadRecordType(ApexPages.StandardController controller) { a=(Account)controller.getRecord(); } public PageReference setRecordType(){ a.RecordTypeId=[Select Id,SobjectType,Name From RecordType where Name ='VCHospital' and SobjectType ='Account' limit 1].id; update a; return null; } }
And reference this extension on the visualforce page like this.
<apex:page standardController="Account" extensions="LoadRecordType" action="{!setRecordType}"> <apex:detail subject="{!account}"/> </apex:page>
I get this error.
Visualforce Error
System.QueryException: List has no rows for assignment to SObject
Error is in expression '{!setRecordType}' in component <apex:page> in page accountdetailbutton: Class.LoadRecordType.setRecordType: line 10, column 1
Class.LoadRecordType.setRecordType: line 10, column 1
Im kind of a visualforce Newb. Can someone help me figure out why this is happening?
All Answers
Please use following code VF:
Thanks,
Amritesh
a.RecordTypeId=[Select Id From RecordType where Name ='VCHospital' and SobjectType='Account' limit 1].id;
System.QueryException: List has no rows for assignment to SObject
Class.LoadRecordType.setRecordType: line 12, column 1
Class.LoadRecordType.<init>: line 8, column 1
Ughhh!
Please check your query and name of the RecordType "VCHospital" and also check if this recordtype is present in account or not.
Thanks!
I'm not sure why it is not finding it.