Skip to main content
My page bloc section :

<apex:pageblockSection title="Organisme audité">

                     <apex:pageblockSection >

                     <apex:pageblockSection >

                          <apex:inputField value="{!customObj1.Name}"/>

                      </apex:pageblockSection>

                  

                      <apex:pageblockSection >

                          <apex:inputField value="{!customObj1.Date_debut__c}"/>

                      </apex:pageblockSection>

                      

                      <apex:pageblockSection >

                          <apex:inputField value="{!customObj1.Date_fin__c}"/>

                      </apex:pageblockSection>

                     

                      <apex:pageblockSection >

                          <apex:commandButton value="save" action="{!save}"/>

                      </apex:pageblockSection>

 my controller :

public with sharing class controller_audit {

    

     public Mission__c customObj1 {get;set;}

public controller_audit()

{

     customObj1= [select Name, Date_debut__c, Date_fin__c from Mission__c LIMIT 1];

}

public void save()

{

    

     insert customObj1;

   

}

}

Error: 

System.DmlException: Insert failed. First exception on row 0 with id a0P24000000GPkhEAG; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

help ?
8 件の回答
  1. 2015年4月16日 11:51
    Hi,

    As an best practise we should always initalize all the variables before using..so in your case please initalize it in constructor..

    customObj1  = new Mission__c();

    Thanks

    Sandeep

     
0/9000