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
Richa KRicha K 

Get the current instance value from VF page

I am using a custom controller(Not extension controller) for a VF page. That VF page has a lookup to Accounts. I want the selected lookup field value in my controller. I am using actionSupport for this(On change of lookup).

 

Any help?

Abhay AroraAbhay Arora

Try adding a custom js function on the onchange event of the field if it dosent works  please put your code here so that i can look into it

Richa KRicha K

Thanks!

 

Sure!

 

Class:

public with sharing class Invoice_Helper
{
   
     public List<CashFlow__Invoice__c> getLstRecs() {
            return lstRecs;
        }
        Public Id statusSelected {get;set;}
        public pagereference newTets() 
        {
            //updateInvs();
            system.debug('=========here===');
            statusSelected = objInv.Account__c; 
            system.debug('============'+statusSelected );
            return null;
        }
        public void updateInvs() 
        {
        //Id id = ApexPages.currentPage().getParameters().get('id');
        //statusSelected = objInv.Account__c; 
        //system.debug('============'+id );
            lstRecs = [SELECT Id, Name, Account__c
                    FROM CashFlow__Invoice__c ];
                    //return null;
        }

      public Pagereference NewSave()
        {
            if((!lstCat.isEmpty() && lstCat.KeySet().size() > 1) && (!lstPay.isEmpty() && lstPay.KeySet().size() > 1))
            {
            objInv.CashFlow__Payment__c = lstCat.get(strPay);
            objInv.CashFlow__Category__c = lstCat.get(strCategory);
            insert objInv ;
            }
            else
            {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'The category you have selected is duplicate'));
            }
            PageReference acctPage = new ApexPages.StandardController(objInv).view();
            acctPage.setRedirect(true);
            return acctPage;
              //return null;
            //write a code returning to the record using objCon.Id
        }
           public Pagereference saveNnew()
            {
                
                if(!lstCat.isEmpty() && lstCat.KeySet().size() > 1)
                {
                objInv.CashFlow__Category__c = lstCat.get(strCategory);
                insert objInv ;
                }
                else
                {
                    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'The category you have selected is duplicate'));
                }
                PageReference pageRef = new PageReference('/apex/Invoice_Override');
                pageRef.setRedirect(true);
                return pageRef;
    
            }
            public Pagereference cancelOn()
            {
                PageReference pageRef = new PageReference('/a01/o');
                pageRef.setRedirect(true);
                return pageRef;
            }
            



}

 Page:

<apex:page Controller="Invoice_Helper" >

<script>

function search()

{

  //  alert('hi');

    sendvaltocontroller();

}
</script>
 <apex:sectionHeader title="Invoice Edit" subtitle="New Invoice" />
     <apex:form >
      <apex:pageBlock title="Invoice Edit" id="block">
        <apex:pageBlockButtons >
        <apex:commandButton action="{!NewSave}" value="Save"/>
        <apex:commandButton action="{!saveNnew}" value="Save and New"/>
        <apex:commandButton action="{!cancelOn}" value="Cancel" immediate="true"/>
        </apex:pageBlockButtons>
        <apex:pageblockSection title="Information" collapsible="false">       
        
        <apex:inputField value="{!objInv.Account__c}" >
        <apex:actionSupport event="onchange" action="{!newTets}" immediate="true"/>
        </apex:inputField>
        <br/>&nbsp;&nbsp;&nbsp;&nbsp;<apex:inputField required="true" value="{!objInv.Invoice_Date__c}"/>
        <br/><apex:inputField required="true" value="{!objInv.Invoice_Name__c}"/>
        <br/><apex:inputField required="true" value="{!objInv.Gross_Amount__c}"/>
        <br/><apex:inputField required="true" value="{!objInv.Currency__c}"/>
        <br/><apex:inputField required="true" value="{!objInv.BTW__c}"/>
        <br/><apex:inputField required="true" value="{!objInv.Description__c}"/>

        </apex:pageblockSection>
        <apex:pageblockSection title="Catagory" collapsible="false">
        <apex:outputLabel >Category &nbsp;&nbsp;&nbsp;<apex:selectlist value="{!strCategory}" size="1">
          <apex:selectOptions value="{!Categories}"/>
        </apex:selectList></apex:outputLabel>
        </apex:pageblockSection>
        
        <apex:pageblockSection title="Dropbox Document" collapsible="false">
        <apex:inputField required="true" value="{!objInv.Document_Scan__c}"/>
        </apex:pageblockSection>
        
        <apex:pageblockSection title="Payment" collapsible="false">
        <apex:inputField required="true" value="{!objInv.Due_Date__c}"/>
        <br/><apex:outputLabel >&nbsp;&nbsp;Payment Method &nbsp;&nbsp;&nbsp;&nbsp;<apex:selectlist value="{!strPay}" size="1">
          <apex:selectOptions value="{!payMethods}"/>
        </apex:selectList></apex:outputLabel>
        <br/><apex:inputField required="true" value="{!objInv.Payment_Date__c}"/>
        </apex:pageblockSection>
        
        </apex:pageBlock>
        
        <apex:pageBlock title="List of Invoices" id="Account">
        <apex:pageBlockSection title="Invoices"  columns="1" collapsible="false">
        <apex:pageBlockTable value="{!lstRecs}" var="item">
          <apex:column value="{!item.Name}" headerValue="Invoices" width="100"/>
        </apex:pageBlockTable>
        </apex:pageBlockSection>
        </apex:pageBlock>
      
      </apex:form>
            
</apex:page>

 

kiranmutturukiranmutturu

<apex:inputField value="{!objInv.Account__c}" >
<apex:actionSupport event="onchange" action="{!newTets}" immediate="true">
<apex:param name="invaccount" assignTo="{!invAccount}"/>
</apex:actionsupport>
</apex:inputField>

 

and put this in your class

 

public string invAccount{get;set;}

Abhay AroraAbhay Arora

Hi Shailesh,

 

I hope the solution of kiran would have solved your problem or just let me know i wil provide you more details

Richa KRicha K

Hi Kiran,

 

I put param like this :

<apex:inputField value="{!objInv.Account__c}" >
        <apex:actionSupport event="onchange" action="{!newTets}" immediate="true">
        <apex:param name="invaccount" assignTo="{!invAccount}" value="{!objInv.Account__c}"/>
        </apex:actionSupport>
        </apex:inputField>

 

Still no luck... the debug in newTest still say :

13:52:41.052 (52940000)|USER_DEBUG|[99]|DEBUG|=========invAccount2===null

 Is there any approach?

kiranmutturukiranmutturu

write a constructor and find this debug value

 

system.debug(apexpages.currentpage().getparameters().get('invaccount'));

kiranmutturukiranmutturu

i think u need a ajax call here ... when ever u are tring to call the method in onchange thats a fresh call to the server it wont take the old call... so use rerender in action support..and render an fake output panel...

 

declare an output panel

<apex:outputpanel id="op"/>

 

and in apex:actionsupport rerender="op"  try this way u can get that value to the controller..

Richa KRicha K

HI Kiran

 

No luck man. Earlier in debug logs, it will show the value as 'null' but when I used renderer, it is simply blank/. No value is being shown.

 

Like :

14:38:42.062 (62336000)|USER_DEBUG|[99]|DEBUG|=========invAccount2===

 

M I missing something?

Abhay AroraAbhay Arora

Shailesh ,

 

There is a problem with apex:param this never worked for me properly. It will not work with command button or command

 

link  actionfunction instead it will work for sure

 

Thanks

Abhay