function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
M SreekanthM Sreekanth 

Can any one tell me is this my code is handling excetion.

Can any one tell me is this my code is handling excetion and if transaction happen then how to navigate to page ,if it it is working properly how to know  and if any modifactions require let me know

Class:-
=====
/*
 * Description        : Bulk Account Creation
 * Autor              :Sreekanth Meesal
 * Created Date       :16/03/2023
 * Last Modified Dtae :
*/
public class Account_Class {
/*
 * Description        : Bulk Account Creation
 * Autor              :Sreekanth Meesal */
    
    public string name{set;get;}
    public string phone{set;get;}
    public string accNo{set;get;}
    public string industry{set;get;}
    
    public pageReference insertAcc(){
        account a = new account();
        a.Name = name;
        a.Phone = phone;
        a.AccountNumber = accNo;
        a.Industry = industry;
        list<account> accList = new list<account>();
        accList.add(a);
        try{
        Database.SaveResult[] srList = DataBase.insert(accList,true);
        for(Database.SaveResult sr:srList){
            if(sr.isSuccess()){
                system.debug('Success Id => '+sr.getId());
            }else{
                for(Database.Error err:sr.getErrors()){
                    system.debug('Message : fields => '+err.getMessage()+' : '+err.getFields());
                }
            }
        }
        }Catch(Exception e){
            system.debug('Message : cause '+e.getMessage()+' : '+e.getCause());
        }
        
        pageReference p = new pageReference('/'+a.id);
        return p;
    }
 
}

Vf Page :-
======
<apex:page controller="Account_Class">
 <apex:form >
 <apex:pageblock title="Accounts Page">
 <apex:pageblockButtons location="Bottom">
 <apex:commandButton action="{!insertAcc}" value="Create"/>
 </apex:pageblockButtons>
 <apex:pageBlockSection columns="2">
  <apex:pageBlockSectionItem >
     <apex:outputLabel value="Account Name"/>
     <apex:inputText value="{!name}"/>
   </apex:pageBlockSectionItem>
   
    <apex:pageBlockSectionItem >    
     <apex:outputLabel value="Account Phone"/>
     <apex:inputText value="{!phone}"/>
   </apex:pageBlockSectionItem>
    
    <apex:pageBlockSectionItem >
     <apex:outputLabel value="Account No"/>
     <apex:inputText value="{!accNo}"/>
      </apex:pageBlockSectionItem>
       <apex:pageBlockSectionItem >
     <apex:outputLabel value="Industry"/>
     <apex:inputText value="{!industry}"/>
      </apex:pageBlockSectionItem>
 </apex:pageBlockSection>

 </apex:pageblock>
 </apex:form>
</apex:page>
Best Answer chosen by M Sreekanth
SwethaSwetha (Salesforce Developers) 
HI Sreekanth,
I don't see any issues in the code as you have used all the best practices like try-catch block, DataBase.insert , Database.SaveResult.

The only thing you could consider is checking the value being inserted for the Industry picklist. Currently, you can insert any value in this field. You could make changes such that it only takes values from existing industry picklists.

Related: https://salesforce.stackexchange.com/questions/181459/display-a-pick-list-field-on-a-visual-force-page-using-custom-controller
https://developer.salesforce.com/forums/?id=9060G000000XhJ2QAK


If this information helps, please mark the answer as best. Thank you

All Answers

SwethaSwetha (Salesforce Developers) 
HI Sreekanth,
I don't see any issues in the code as you have used all the best practices like try-catch block, DataBase.insert , Database.SaveResult.

The only thing you could consider is checking the value being inserted for the Industry picklist. Currently, you can insert any value in this field. You could make changes such that it only takes values from existing industry picklists.

Related: https://salesforce.stackexchange.com/questions/181459/display-a-pick-list-field-on-a-visual-force-page-using-custom-controller
https://developer.salesforce.com/forums/?id=9060G000000XhJ2QAK


If this information helps, please mark the answer as best. Thank you
This was selected as the best answer
M SreekanthM Sreekanth
Got it..same page i need to navigate for update standard page of account how can i implement
Thank you for replay Swetha