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
Srini NandhiSrini Nandhi 

getting this error "record id cannot be empty key", while inserting a Case using VF.

Hi All, 

getting this error "record id cannot be empty key", while inserting a Case using VF.

I Have a created a VF page with StandardSetController means RecordSetVar="true". Standard Controller ="Case"
I have used in StandardSetController in Extensions Controller.
  cas=(Case)controller.getRecord();
 cas.RecordTypeID=rtID;
        cas.OwnerID=UserInfo.getUserID();    
      
and i have overrieded Save Method and below 

public PageReference Save()
    {
   
        try{
      // Case c=new Case();
       c1=cas;
            insert c1;
            return New PageReference('/'+cas.id);
        }
        catch(Exception e){
            ApexPages.addMessages(e);
        }
        return null;
    }

while inserting a Case i am getting "record id cannot be empty key",  error
In the ViewState, i found Case id is having 00000000000 

Can anyone know about this, help me out.

Thanks 


 
ShaTShaT
Hi Nidihi,

You have used incoorect contoller you should you StandardController in vf . StandardSetController is used to dislay list of records. 

Below are the links to find difference between standard controller and standardsetcontroller.

http://salesforce.stackexchange.com/questions/48199/what-is-the-difference-between-list-controllers-and-set-controllers

 
Vivek DeshmaneVivek Deshmane
Hi Srini,

      controller.getRecord() method will return sObject that represents the changes to the selected records.
      Case cas;
     //get record type id by recordtype label
        Id rtID=Schema.SObjectType.Contact.getRecordTypeInfosByName().get('RecordType label').getRecordTypeId();
        cas=(Case)controller.getRecord();
        cas.RecordTypeID=rtID;
        cas.OwnerID=UserInfo.getUserID();    


public PageReference Save()
    {
   
        try{
      
            if(cas!=null)
            {
            insert cas;
            }
            return New PageReference('/'+cas.id);
        }
        catch(Exception e){
            ApexPages.addMessages(e);
        }
        return null;
    }

    Please let me know if it helps you.
    
    Best Regards,
    -Vivek