function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
skdevskdev 

Calling controller method for new records

Hi,

I have a visualforce page with an extension and the New button on a custom object is overridden with this visualforce page. I have a method in the extension controller that is invoked onchange of a date field and does some validation and disables certain fields on the page. The issue I have is that when I create a new record and change the date, the controller method does not get invoked. The same piece of code works fine when I edit a record.

 

Is there something am missing, please help.

 

VF Page

 

<apex:inputField value="{!location__c.Start_Date__c}" onchange="processStartDt();"/>
<apex:actionFunction action="{!methodOne}" name="processStartDt" rerender="DeliverySection"/>
Extension:
public with sharing class extLOC {
    private final location__c L;
    
    public extLOC(ApexPages.StandardController stdController) {
        this.L = (location__c)stdController.getRecord();
    }
     public void methodOne(){
        integer month = L.Start_Date__c.Month();
        if(month == 12){
            system.debug(month); // I am not seeing this debug statement
 }
 }
}

 

 

Virendra NarukaVirendra Naruka

HI

 

Try to edit the date using keyboard instead of selecting date from calender .

 

Hope it will work fine 

aballardaballard

Do you have an <apex:messages> in your page to display any generated error messages?  I wondering if there is a required field that has not been filled in, which would cause a validation error and prevent the request going on toe execute the action method call.

Pradeep_NavatarPradeep_Navatar

Use system.debug statement before if() statement. You need to make sure that whether it is being called or not :

 

public void methodOne()

   {

       system.debug('Your Custom date');

       integer month = L.Start_Date__c.Month();

       system.debug('########'  +  month);

       if(month == 12){

       system.debug(month); // I am not seeing this debug statement

        }

   }