Skip to main content
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 

 
2 件の回答
  1. 2015年7月14日 9:01
    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
0/9000