I have a custom VF page and apex controller that mimics the standard Clone for Contracts. Currently, it is copying the date fields as they're from the previous record. However, I want to make the date fields null and let the users enter new dates which will be inserted in the newly cloned contract record.
<apex:page standardController="Contract" tabStyle="Contract" lightningstylesheets="true"
extensions="ContractClone">
<apex:sectionHeader title="Clone Contract" subtitle=" {!ContractRecordQueried.ContractNumber}"/>
<apex:form >
<apex:pageBlock mode="inlineEdit" title="">
<apex:pageblockButtons >
<apex:commandButton action="{!cloneContract}" value="Clone"/>
<apex:commandButton action="{!Cancel}" value="Cancel"/>
</apex:pageblockButtons>
<apex:pageBlockSection columns="2" title="General Information" collapsible="false">
<apex:inputField value="{!ContractRecordQueried.Division__c}" required="true"/>
<apex:inputField value="{!Contract.Status}" label="Status" required="TRUE" id="contractStatus" />
<script>
document.querySelector('[id$=contractStatus]').value = 'Initial Contract Discussion';
//document.querySelector('[id$=contractStartDate]').value = "";
//$("#contractStartDate").val("");
</script>
<apex:pageBlockSectionItem />
<apex:outputField value="{!ContractRecordQueried.CustomerSignedDate}"/>
<apex:pageBlockSectionItem />
<apex:outputField value="{!ContractRecordQueried.ESignature_Status__c}"/>
<apex:inputField value="{!ContractRecordQueried.Name}" required="true"/>
<apex:inputField value="{!ContractCloned.StartDate}" required="true" id="contractStartDate"/>
<apex:inputField value="{!ContractRecordQueried.Description}" required="true"/>
<apex:inputField value="{!Contract.EndDate}" label="Contract End Date"/>
</apex:pageBlockSection>
</apex:form>
<apex:pageMessages />
</apex:page>
Apex Controller:
public class ContractClone {
private ApexPages.StandardController controller {get; set;}
public Contract ContractRecordQueried{get;set;}
public Contract ContractCloned {get;set;}
public ContractClone(ApexPages.StandardController controller) {
this.controller = controller;
ContractRecordQueried = [select Id,
ContractNumber,
CustomerSignedDate,
StartDate,
EndDate,
Name
from Contract
where id =: controller.getId()];
}
public PageReference cloneContract() {
//String contactid = ContractRecordQueried.ContactId;
Date start_date = ContractRecordQueried.StartDate;
Date end_date = ContractRecordQueried.EndDate;
Savepoint sp = Database.setSavepoint();
Contract ContractCloned;
try {
ContractCloned = ContractRecordQueried.clone(false);
insert ContractCloned;
} catch (Exception e){
Database.rollback(sp);
ApexPages.addMessages(e);
return null;
}
return new PageReference('/'+ContractCloned.id);
}
}
clone()
operation incloneContract()
- that looks like the place where you could change values on the record, right? I'm not sure what your question is.null
.