Unable to pass contact from VF to the controller. I have to check if the contact is inactive on VF page if it inactive, allow user to change the contact and pass the changes to the controller. If contact is active, use the same. Here's what my VF page looks like:
<apex:page standardController="Case" tabStyle="Case" lightningstylesheets="true"
extensions="TestCase_Controller">
<apex:sectionHeader title="{!$Label.ClaimAP_Clone_Title}" subtitle="{!Case.CaseNumber}"/>
<apex:form >
<apex:pageBlock mode="inlineEdit" title="">
<apex:pageblockButtons >
<apex:commandButton action="{!cloneCase}" value="{!$Label.ClaimAP_Clone_ButtonClone}" />
<apex:commandButton action="{!Cancel}" value="{!$Label.ClaimAP_Clone_ButtonCancel}" />
</apex:pageblockButtons>
<apex:pageBlockSection columns="1" title="{!$Label.ClaimAP_Clone_CloneLegend}" collapsible="false">
<apex:inputField value="{!Case.ContactId}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<apex:pageMessages />
My controller is this:
public class TestCase_Controller {
private ApexPages.StandardController controller {get; set;}
private Case CaseRecordQueried{get;set;}
public Case CaseRecord {get;set;}
public Case Contactid;
public TestCase_Controller(ApexPages.StandardController controller) {
this.controller = controller;
CaseRecord = (Case)controller.getRecord();
Contactid = (Case)controller.getRecord();
//Contactid = (Case)
CaseRecordQueried = [select Id,
AccountId,
CaseNumber,
External_Reference_Number__c,
FSR__c,
Total_Lines__c,
Opportunity__c,
EU_Sample_Type__c,
Comments_For_Customer__c,
Shipment_Status__c,
Comments_for_Stratos__c,
Customer_PO__c,
Comments_for_Manager__c,
Division__c,
Lead__c,
Shipment__c,
Customer_Language__c,
Shipment_Contact__c,
Shipment_Contact_Phone__c,
Shipment_Address__c,
Work_in_progress__c,
Carrier__c,
UPS_Tracking_Nbr__c,
AWB_Number__c,
Country__c,
Comments_from_Stratos__c,
Cost_of_Sample__c,
Shipment_Cost__c,
Total_Cost__c,
Origin,
Description,
Priority,
Requires_Approval__c,
RecordTypeId
from Case
where id =: CaseRecord.Id];
}
public PageReference cloneCase() {
String contactid = Contactid.ContactId;
Savepoint sp = Database.setSavepoint();
Case CaseCloned;
try {
CaseCloned = CaseRecordQueried.clone(false);
insert CaseCloned;
} catch (Exception e){
Database.rollback(sp);
ApexPages.addMessages(e);
return null;
}
return new PageReference('/'+CaseCloned.id);
}
}
Contactid.ContactId
will always be null, because on VF page you have bind contact withCase.ContactId
.CTRL + K
.