You need to sign in to do that
Don't have an account?
Clone Button
Hey there,
I have created a VF page with extension that will re-direct the user to a visualforce page with the correct tab open after creating a new record. I tried putting that same page onto the clone button and although it autofilled the correct fields, upon attempting to save I was left with this:
System.DmlException: Insert failed. First exception on row 0 with id a0LN0000000OsBEMA0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
Class.extSaveButton.saveFactFinder: line 11, column 1
Am I able to do it like this or do I have to create an entirely different VF page and extension?
Thank you,
Mikie
change this
if(System.currentPageReference().getParameters().get("clone") == "1"){
if(System.currentPageReference().getParameters().get('clone') == '1'){
All Answers
Hi,
This is happening because the page is opening the record you are viewing. In the saveFactFinder() method add a simple check to know if the record is being cloned. If it is, remove the record id before inserting the record.
Ex.
public PageReference saveFactFinder(){
if(System.currentPageReference().getParameters().get("clone") == "1"){
//Set record id to null
myFactFinder.Id = null
}
...
insert myFactFinder;
}
Hope this helps!
I tried changing the code as you said. It ended up looking like this:
public class extSaveButton {
public Fact_Finder__c fac {get;set;}
public extSaveButton(ApexPages.StandardController controller) {
this.fac = (Fact_Finder__C)controller.getRecord();
}
Public PageReference saveFactFinder(){
if(System.currentPageReference().getParameters().get("clone") == "1"){
//Set record id to null
fac.Id = null
}
insert fac;
// Send the user to the detail page for the new account.
PageReference pageRef= new PageReference('/apex/DestinyAccountTest?id='+fac.account__c+'&Sfdc.override=1');
pageRef.getParameters().put('tab','FactFinder');
return pageRef;
}
}
Put upon saving i was left with the error:
Error: Compile Error: line 13:57 no viable alternative at character '"' at line 13 column 57
Thank you so much for your time.
Mikie
change this
if(System.currentPageReference().getParameters().get("clone") == "1"){
if(System.currentPageReference().getParameters().get('clone') == '1'){
Works now, thank you for your help guys.