You need to sign in to do that
Don't have an account?
Lakshmi S
Custom cloning using Visualfoce pages?
Hi Team,
Requirement : cloning from custom detail page.
I got an issue, after clicking on clone button the record was saved to database.
I want to save the record after clicking on save button only, other wise the record dont want to save in database like standard functionality.
my code :
Thanks
Lakshmi
Requirement : cloning from custom detail page.
I got an issue, after clicking on clone button the record was saved to database.
I want to save the record after clicking on save button only, other wise the record dont want to save in database like standard functionality.
my code :
<apex:page standardController="High_Risk_Success_Factors__c" sidebar="true" extensions="HighRiskSuccessFactorsDetailCls" tabStyle="Account" > <apex:form > <apex:pageBlock title="High Risk Success Factors Details"> <apex:pageBlockButtons > <apex:commandButton value="Clone" action="{!doClone}" id="cloneButton"/> <apex:commandButton value="Save" action="{!Save}" id="saveButton" style="display:none;" /> <apex:commandButton value="Edit" action="{!Edit}" id="editButton" /> <apex:commandButton value="Delete" action="{!Delete}" onclick="if(!confirm('Are you sure?')){return false};" id="deleteButton" /> <apex:commandButton value="Cancel" action="{!doCancel}" id="cancelButton" immediate="true" style="display:none;" /> </apex:pageBlockButtons> <apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" hideOnEdit="editButton,deleteButton,cloneButton" /> <apex:pageBlockSection title="Account/Opportunity Details" columns="2"> <apex:outputField value="{!High_Risk_Success_Factors__c.Name}" /> <apex:outputField value="{!High_Risk_Success_Factors__c.Account_Name__c}" /> <apex:outputField value="{!High_Risk_Success_Factors__c.Opportunity_Name__c}" /> <apex:outputField value="{!High_Risk_Success_Factors__c.Opportunity_Stage__c}" /> <apex:outputField value="{!High_Risk_Success_Factors__c.Primary_Division__c}" /> <apex:pageBlockSectionItem > <apex:outputText >Global Unique ID</apex:outputText> <apex:outputField value="{!High_Risk_Success_Factors__c.Global_Unique_ID__c}" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>apex class :
public with sharing class HighRiskSuccessFactorsDetailCls { private ApexPages.StandardController con {get;set;} public HighRiskSuccessFactorsDetailCls(ApexPages.StandardController sc){ this.con=sc; } public PageReference save(){ try{ con.save(); PageReference pr = Page.HighRiskSuccessFactorsDetailPage; pr.setRedirect(true); pr.getParameters().put('id',con.getId()); return pr; }catch(Exception e){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage())); return null; } } public PageReference doClone(){ try{ //con.save(); PageReference pr = Page.HighRiskSuccessFactorsVFPage; pr.setRedirect(true); High_Risk_Success_Factors__c hr = [SELECTid,name,Account_Name__c,Opportunity_Name__c,Opportunity_Stage__c FROM High_Risk_Success_Factors__c where id =:con.getId()]; High_Risk_Success_Factors__c clonedhr = hr.clone(false,false,false,false); insert clonedhr; pr.getParameters().put('id',clonedhr.Id); return pr; }catch(Exception e){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage())); return null; } } Public PageReference doCancel(){ PageReference pr = new PageReference('/'+Schema.SObjectType.High_Risk_Success_Factors__c.getKeyPrefix()+'/o'); return pr; } }Please let me know anyone, how can we resolve this issue?
Thanks
Lakshmi
You can skip the insert part in clone method.
Remove insert clonedhr; in clone method.
Also refer below link.
https://salesforce.stackexchange.com/questions/58078/cloning-record-with-visualforce-apex
Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
Best Regards
Sandhya
After removing the insert clone part i didn't get values to vf page.
How can i do that?
please let me know.
Thanks
Lakshmi