You need to sign in to do that
Don't have an account?
Lakshmi S
Visualforce Error -- System.QueryException: List has no rows for assignment to SObject
HI Team,
Visualforce Error :
System.QueryException: List has no rows for assignment to SObject.
How can we handle these type of errors for vf pages.
Thanks
Lakshmi
Visualforce Error :
System.QueryException: List has no rows for assignment to SObject.
<apex:page standardController="High_Risk_Success_Factors__c" sidebar="true" tabStyle="Account" extensions="HighRiskSuccessFactorsDetailCls" > <apex:form > <apex:pageBlock title="Success Factors Details"> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!Save}" id="saveButton" style="display:none;" /> <apex:commandButton value="Edit" action="{!Edit}" id="editButton" /> <apex:commandButton value="Delete" action="{!Delete}" onclick="if(!confirm('Are you sure?')){return false};" id="deleteButton" /> <apex:commandButton value="Clone" action="{!doClone}" id="cloneButton" /> <apex:commandButton value="Cancel" action="{!doCancel}" id="cancelButton" immediate="true" style="display:none;" /> </apex:pageBlockButtons> <apex:pageMessages ></apex:pageMessages> <apex:pageBlock> <apex:form> <apex:page>
public with sharing class HighRiskSuccessFactorsDetailCls { public boolean bool {get;set;} Private ApexPages.StandardController controller {get;set;} public HighRiskSuccessFactorsDetailCls(ApexPages.StandardController controller){ bool = false; this.controller=controller; } public PageReference save(){ try{ controller.save(); PageReference pr = Page.HighRiskSuccessFactorsDetailPage; pr.setRedirect(true); pr.getParameters().put('id',controller.getId()); return pr; }catch(Exception e){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage())); return null; } } public PageReference doClone(){ PageReference pr; try{ if(controller.getId() != null) pr = Page.HighRiskSuccessFactorsClonePage; pr.getParameters().put('id',controller.getId()); return pr; } catch(Exception e){ ApexPages.addMessages(e); return null; } } Public PageReference doCancel(){ PageReference pr = new PageReference('/'+Schema.SObjectType.High_Risk_Success_Factors__c.getKeyPrefix()+'/o'); return pr; } }If we click on clone button, if record is not available it shwos above error.
How can we handle these type of errors for vf pages.
Thanks
Lakshmi
Please check above code.