You need to sign in to do that
Don't have an account?

Record ID: cannot Specify ID in an Insert Call
I have the following function which is being called on page submit for my visual force page. I am getting the following error when the user hits submit
Record ID: cannot Specify ID in an Insert Call
And the code is below
public PageReference confirm() {case ticket = new case();
if (this.request != null) {request.Title__c = this.empTitle;request.Department__c =
this.empDept; request.Reports_to__c = this.repToEmail;
try {
insert request; } catch (system.DMLException e){ApexPages.addMessages(e);
return null;}
this.caseId1 = generateNewTicket(request.employee_name__c, request.Grant_Email_access_to__c,request.Outlook_out_of_office_message__c, request.Blackberry_user__c );
if (this.caseId1 == NULL)
return null;
}
list<Case> a = [Select c.CaseNumber from Case c where c.Id = :this.caseId1 limit 1];
if(a.size() != 0) {ticket = a[0];}
this.confNumber = ticket.CaseNumber;try{ sendEmail(this.confNumber);
sendEmail();
} catch (EmailException e){ApexPages.addMessages(e);
return null;}
PageReference p = Page.offbsubmit;
p.setRedirect(true);
return p;}
It says problem with insert but I see the new request was created! But I did not get any emails, so may be it was
choking at that part but I dont understand why. Any help please?
The next likely reason that comes to my mind is that the users are likely hitting the save button twice.
Because
this.caseId1 = generateNewTicket(request.employee_name__c, request.Grant_Email_access_to__c,
request.Outlook_out_of_office_message__c, request.Blackberry_user__c );
if (this.caseId1 == NULL)
return null;
}
here null is being returned, the user remains on the same page is hitting the save button again.
All Answers
Is this a standardController Extension, in that if the request id is passed via the Url, SF will automatically set the RequestId
Try putting a System.debug for Request.Id before doing the insert.
Thing is I never got this error when I tested it from my production instance. The request Id is being passed from
sites to visualforce pages to controller extension where I have this code. So I deployed the code on production and only clients are seeing this error. I am unable to reproduce the error!
The next likely reason that comes to my mind is that the users are likely hitting the save button twice.
Because
this.caseId1 = generateNewTicket(request.employee_name__c, request.Grant_Email_access_to__c,
request.Outlook_out_of_office_message__c, request.Blackberry_user__c );
if (this.caseId1 == NULL)
return null;
}
here null is being returned, the user remains on the same page is hitting the save button again.