
I am getting the error "There is no record to save" when I press the Save Button. The data seems to be saving correctly, but I don't know why the error is appearing:
Controller:
public with sharing class testValidationController {
private final sObject mysObject;
public ApexPages.StandardController myController ;
public PRC_Client__c clientRec {get; set;}
public ID logID;
public testValidationController(ApexPages.StandardController stdController) {
this.mysObject = (sObject)stdController.getRecord();
myController = stdController;
logID = myController.getID();
}
public id getID(){
return logID;
}
public String getRecordName() {
return 'Hello ' + (String)mysObject.get('name') + ' (' + (Id)mysObject.get('Id') + ')';
}
public PageReference mySave(){
try{
this.myController.save();
upsert clientRec;
} catch (DmlException ex) {
ApexPages.addMessages(ex);
}
return null;
}
public PageReference mainActionHandler()
{
PRC_Client_Contact_Log__c getcid = [SELECT prc_client__c, id FROM PRC_Client_Contact_Log__c WHERE id = :logID];
id clientID = getcid.PRC_Client__c;
PRC_Clients_helper prc_h = new PRC_Clients_helper();
clientRec = prc_h.get_PRC_Client_byID(clientID);
return null;
}
}
Adding visualForce code here as well in case someone wants to copy and paste:
<apex:page showHeader="true" sidebar="true" standardController="PRC_Client_Contact_Log__c" extensions="testValidationController" action="{!mainActionHandler}">
<apex:form >
<apex:pageblock mode="edit" id="theWholepage">
<apex:pageblockbuttons id="thePageButtons">
<apex:actionStatus id="saveStatus" startText="Saving please wait...">
<apex:facet name="stop">
<apex:commandbutton value="Save" action="{!mysave}" status="saveStatus" />
</apex:facet>
</apex:actionStatus>
</apex:pageblockbuttons>
<apex:pagemessages />
<!-- test rules in PRC_CLIENT_LOG__C-->
<apex:pageblockSection columns="1" >
<apex:inputField value="{!PRC_Client_Contact_Log__c.id}"/>
<apex:inputField value="{!PRC_Client_Contact_Log__c.name}"/>
<br/>
<apex:inputField value="{!PRC_Client_Contact_Log__c.Call_Outcome__c}"/>
<apex:inputField value="{!PRC_Client_Contact_Log__c.Caller_Engaged_But_No_Appt_Set__c}"/>
</apex:pageblockSection>
<br/>
<br/>
<!-- test rules in PRC_CLIENT__C -->
<apex:pageblockSection columns="1" >
<apex:inputField value="{!clientRec.First_Name__c}"/>
<apex:inputField value="{!clientRec.Last_Name__c}"/>
<apex:inputField value="{!clientRec.Id}"/>
<br/>
<apex:inputField value="{!clientRec.Appt_Made__c}"/>
<apex:inputField value="{!clientRec.Appt_Date__c}"/>
</apex:pageblockSection>
</apex:pageblock>
</apex:form>
</apex:page>
Any help greatly appreciated!!!
Thanks in advance.
6 answers