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
udayarangareddy mekalaudayarangareddy mekala 

how to rectify UPDATE ERROR

Below code i got some error.Please modify and send the code
public class EmployeeRelatedList {
 private Empolyee_Details__c empDetail;
 //private Apexpages.StandardController controller;

    
    public EmployeeRelatedList(ApexPages.StandardController stdController) {
        //controller = stdController;
        this.empDetail = (Empolyee_Details__c)stdController.getRecord().id;
        
    }
    
    public Pagereference save() {
     if(id!= null){
     
        try{
            insert empDetail;
            return new Pagereference('/apex/Custom_pagenations'); 
     }
   }  
    else{
    update empDetail;
    here i got error
    
    
    } 
        catch(Exception e){
            Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.ERROR, e.getMessage()));
            return null;
        }
    }
}
THANKS

RANGA

Best Answer chosen by udayarangareddy mekala
Krishna SambarajuKrishna Sambaraju
Your code is not clear, but I have upated it to correct some mistakes. Try this.
public class EmployeeRelatedList {
 private Empolyee_Details__c empDetail;
 //private Apexpages.StandardController controller;

    
    public EmployeeRelatedList(ApexPages.StandardController stdController) {
        //controller = stdController;
        this.empDetail = (Empolyee_Details__c)stdController.getRecord();
        
    }
    
    public Pagereference save() {
​        try{
            if(empDetail.id == null){
                insert empDetail;
                return new Pagereference('/apex/Custom_pagenations'); 
            }  
            else{
                update empDetail;
            }
        }
        catch(Exception e){
            Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.ERROR, e.getMessage()));
            return null;
        }
    }
}
Hope this helps.
 

All Answers

RAM AnisettiRAM Anisetti
Hi,

Your code is not clear...could u please tell me exact functionality of this class...
Krishna SambarajuKrishna Sambaraju
Your code is not clear, but I have upated it to correct some mistakes. Try this.
public class EmployeeRelatedList {
 private Empolyee_Details__c empDetail;
 //private Apexpages.StandardController controller;

    
    public EmployeeRelatedList(ApexPages.StandardController stdController) {
        //controller = stdController;
        this.empDetail = (Empolyee_Details__c)stdController.getRecord();
        
    }
    
    public Pagereference save() {
​        try{
            if(empDetail.id == null){
                insert empDetail;
                return new Pagereference('/apex/Custom_pagenations'); 
            }  
            else{
                update empDetail;
            }
        }
        catch(Exception e){
            Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.ERROR, e.getMessage()));
            return null;
        }
    }
}
Hope this helps.
 
This was selected as the best answer
Krishna SambarajuKrishna Sambaraju
You have to add a return statement (return null) after the update empDetail (line 19).
udayarangareddy mekalaudayarangareddy mekala
Thanks Krishna.