You need to sign in to do that
Don't have an account?
Олег Савинков
Obtain the value of a field in the controller
I'm going to override the standard controller for my object . Do insertion a new record ( record in base still there is no). Page
<apex:page standardController="CallReportHosp__c" extensions="CtrlCallHospEdit" >
<apex:outputPanel rendered="{!IF($CurrentPage.parameters.theType = 'app', false, true)}" >
<apex:pageBlockSection columns="2">
<apex:pageBlockSectionItem >
<apex:outputLabel value="{!$ObjectType.CallReportHosp__c.fields.AccountID__c.label}" for="organisation"/>
<apex:inputField value="{!CallReportHosp__c.AccountID__c}" id="organisation" >
<apex:actionSupport event="onchange" reRender="pblock" status="status" action="{!SelectService}" />
</apex:inputField>
</apex:pageBlockSectionItem>
Controller
public with sharing class CtrlCallHospEdit {
public Boolean booleanValue {get;set;}
pablic CallReportHosp__c rep;
public CtrlCallHospEdit(ApexPages.StandardController controller)
{
this.booleanValue=false;
rep = (CallReportHosp__c)controller.getRecord();
System.debug(' bool= '+booleanValue);
SelectService();
}
public void SelectService(){
system.debug('selectservice=');
if(rep.AccountID__c !=null)
{ booleanValue = true; System.debug('acc= '+rep.AccountID__c); }
else {booleanValue=false; System.debug('acc= '+rep.AccountID__c); }
}
}
I changed value in field AccountID__c in page, but i don't have its value in controller ( i have rep.AccountID__c = null).
I remind you that I need to get the value of the field BEFORE saving the record in the database (before the call Save).
Tell me what I'm doing wrong
<apex:page standardController="CallReportHosp__c" extensions="CtrlCallHospEdit" >
<apex:outputPanel rendered="{!IF($CurrentPage.parameters.theType = 'app', false, true)}" >
<apex:pageBlockSection columns="2">
<apex:pageBlockSectionItem >
<apex:outputLabel value="{!$ObjectType.CallReportHosp__c.fields.AccountID__c.label}" for="organisation"/>
<apex:inputField value="{!CallReportHosp__c.AccountID__c}" id="organisation" >
<apex:actionSupport event="onchange" reRender="pblock" status="status" action="{!SelectService}" />
</apex:inputField>
</apex:pageBlockSectionItem>
Controller
public with sharing class CtrlCallHospEdit {
public Boolean booleanValue {get;set;}
pablic CallReportHosp__c rep;
public CtrlCallHospEdit(ApexPages.StandardController controller)
{
this.booleanValue=false;
rep = (CallReportHosp__c)controller.getRecord();
System.debug(' bool= '+booleanValue);
SelectService();
}
public void SelectService(){
system.debug('selectservice=');
if(rep.AccountID__c !=null)
{ booleanValue = true; System.debug('acc= '+rep.AccountID__c); }
else {booleanValue=false; System.debug('acc= '+rep.AccountID__c); }
}
}
I changed value in field AccountID__c in page, but i don't have its value in controller ( i have rep.AccountID__c = null).
I remind you that I need to get the value of the field BEFORE saving the record in the database (before the call Save).
Tell me what I'm doing wrong
Please try with this one
This will show contactId field when accountd has some value.
All Answers
and
add this line
rep = new CallReportHosp__c();
Hope this helps!
Page:
<apex:page standardController="CallReportHosp__c" extensions="CtrlCallHospInsert" id="CallsHospEditt">
<script type="text/javascript">
function onChangeOrganisation() {
booleanValue = true;
openPopup("/apex/TM_AccountsList?context=parents", "lookup", 900, 600, "width=900,height=600,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);
}
</script>
<apex:form >
<apex:pageBlock mode="edit" id="pblock" >
<apex:pageMessages id="message" />
<apex:pageBlockButtons location="top">
<apex:actionStatus id="mySaveStatus1">
<apex:facet name="stop">
<apex:commandButton value="Save" action="{!save}" rerender="pblock" status="mySaveStatus1"/>
</apex:facet>
<apex:facet name="start">
<apex:commandButton value="Save" status="mySaveStatus1" disabled="true"/>
</apex:facet>
</apex:actionStatus>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="2">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Organisation" for="organisation"/>
<apex:inputfield value="{!rep.AccountID__c}" id="organisation" required="true">
<apex:actionSupport event="onchange" reRender="pblock" status="status" action="{!SelectService}" />
</apex:inputfield>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputPanel rendered="{!booleanValue}" >
<apex:outputLabel value="Contact" for="contacts"/>
<apex:inputfield value="{!rep.ContactId__c}" />
</apex:outputPanel>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Date" for="datetime"/>
<apex:inputfield value="{!rep.Date__c}" id="theDate"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Time" for="time"/>
<apex:inputfield value="{!rep.CallTime__c}" id="theTime"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Type of visit" for="type"/>
<apex:inputfield value="{!rep.CallType__c}" id="type"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Duration" for="duration"/>
<apex:inputfield value="{!rep.Duration__c}" id="duration"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Plan/fact" for="planned"/>
<apex:inputfield value="{!rep.Planned__c}" id="planned"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Speciality" for="speciality"/>
<apex:inputfield value="{!rep.Speciality_Hosp__c}" id="planned"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="Discussed Products" columns="1" >
<apex:pageBlockSectionItem >
<apex:outputLabel value="Discussed Products" for="products"/>
<apex:inputfield value="{!rep.Field1_del__c}" id="products"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class CtrlCallHospInsert {
public Boolean booleanValue {get;set;}
public CallReportHosp__c rep {get; set;}
private ApexPages.StandardController controller { get; set; }
public CtrlCallHospInsert(ApexPages.StandardController controller) {
this.controller = controller;
// this.rep = new CallReportHosp__c();
this.rep = (CallReportHosp__c)controller.getRecord();
this.booleanValue=false;
System.debug(' bool= '+booleanValue);
SelectService();
}
public void SelectService(){
system.debug('selectservice=');
this.rep = (CallReportHosp__c)controller.getRecord();
String Acc=rep.AccountID__c; System.debug('value= '+Acc);
if (String.isBlank(Acc))
{this.booleanValue=false; System.debug('acc= '+Acc);
}
else {this.booleanValue = true; System.debug('acc= '+Acc); }
}
public PageReference save(){
try {
insert rep;
}catch (Exception e){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '"Something went wrong !"'));
}
PageReference pageRef = Page.CallsHospList;
pageRef.setRedirect(true);
return pageRef;
}
public PageReference cancel() {
PageReference pageRef = Page.CallsHospList;
pageRef.setRedirect(true);
return pageRef;
}
}
I need to get the value of the field AccountID__c after some value is entered in it. I tried different code I found on the Internet, but nothing works.
also rerender the pageblock message in case any error <apex:pagemessages id="message" />
it will show you the error and it will be make easy to debug.
Hope this helps!
I want that when entering any value in the field AccountID__c (but before writing to the database) the variable booleanValue changes so that another input field ContactId__c is displayed.
Please try with this one
This will show contactId field when accountd has some value.