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
Vetriselvan ManoharanVetriselvan Manoharan 

cannot specify id in an insert call

Hi All,
 
public void GetRecruitmentDetails()
    {
        List<Candidate__c> recruitment = new List<Candidate__c>();
        List<Contact> contactIds = new List<Contact>();
        contactIds  = [ SELECT Id from Contact where FirstName = :firstname and LastName = :lastName ];
        if(contactIds.size() > 0)
        {
            System.debug('Job Id' + jobId);
            System.debug('Contact Id' + contactIds[0].Id);
            recruitment = [ SELECT Id, Available_Date__c, Bottom_line_closed_on__c, Ideally_looking_for__c, Interview_Availability__c, Notice_Period__c, Submitted_at__c from Candidate__c where Job__c = :jobId and Contact__c = : contactIds[0].Id  ];
            if(recruitment.size() == 0)
            {
                try
                {
                    if(recruitmentDetails != null)
                    {
                        insert recruitmentDetails;
                    }
                }
                catch(Exception e)
                {
                    System.debug('Exception : ' + e.getMessage() + ' - ' + e.getStackTraceString());
                }   
            }
            else
            {
                recruitmentDetails = recruitment[0];
            }
        }
    }

recruitmentDetails is the variablle which is binded to visual force page.
 
<div class="col-lg-12 zero-padd marg-five-b">
                                        <div class="col-sm-6 col-md-6 two-padd">
                                            <label for="bottomline" class="marg-five-t col-xs-12 zero-padd">Idealy Looking For </label>
                                        </div>
                                        <div class="col-sm-6 col-md-6 two-padd">
                                            <input type="text" class="amount col-xs-12 zero-padd" placeholder="$" value= "{!recruitmentDetails.Ideally_looking_for__c}"/>
                                        </div>
                                    </div>
                                    <div class="col-lg-12 zero-padd marg-five-b">
                                        <div class="col-sm-6 col-md-6 two-padd">
                                            <label for="bottomline" class="marg-five-t col-xs-12 zero-padd">Submitted At</label>
                                        </div>
                                        <div class="col-sm-6 col-md-6 two-padd">
                                            <input type="text" class="amount col-xs-12 zero-padd" placeholder="$" value= "{!recruitmentDetails.Submitted_at__c}"/>
                                        </div>
                                    </div>

This method is also called in page action method. The logic of the method is if the recruitment details available for particular contact it should display the value. And also if we enter values in textbox and click save button it should insert the recruitment details.

I am getting an error "cannot specify id in an insert call"

Any ideas
 
Navee RahulNavee Rahul
Hi Vetri selvan,

change the query From.
 
recruitment = [ SELECT Id, Available_Date__c, Bottom_line_closed_on__c,Ideally_looking_for__c, Interview_Availability__c, Notice_Period__c, Submitted_at__c fromCandidate__c where Job__c = :jobId and Contact__c = : contactIds[0].Id  ];

to
 
recruitment = [ SELECT  Available_Date__c, Bottom_line_closed_on__c,Ideally_looking_for__c, Interview_Availability__c, Notice_Period__c, Submitted_at__c fromCandidate__c where Job__c = :jobId and Contact__c = : contactIds[0].Id  ];

u cant add ID in Insert process.

Thanks
D Naveen Rahul. 
 
Amit Chaudhary 8Amit Chaudhary 8
It look like recruitmentDetails is one record which is already in data base and you want to insert that one again
Please try
update recruitmentDetails;

Please let us know if this will help u