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
Hemant ThakkarHemant Thakkar 

Passing id from visualforce to apex

Hi,
I am trying to pass Account id through param to the controller , but controller is not recieving that value from my visualforce page.
Please Help me out and give me the reason .
I tried with all javascript , jsquery and param too, so if you find anything extra please ignore as i am trying to do by any method that might work.
Here is the code

Visualforce Page :-

<apex:page controller="AccountListController" docType="html-5.0" id="pg">
    <style>
        .requiredLoaderBG{
        background-color: rgb(71,71,71);
        opacity:0.7;
        filter:alpha(opacity=70);
        background-image:url('{!$Resource.ajaxLoadGif}');
        background-position: center center;
        background-repeat: no-repeat;
        height: 100%;
        left: 0;
        position: fixed;
        text-align: center;
        top: 0;
        width: 100%;
        z-index: 1;
    }
    </style>
    <script>
    function setaccvalue(accountid){
        alert(accountid);
        alert(document.getElementByid("pg\:frm\:PagBlck\:AccIdcheck").value);
        document.getElementByClassName('AccClass')[0].value = accountid;
        alert(document.getElementByClassName('AccClass')[0].value);
    }
   
    </script>
   
          <apex:form id="frm">
          <apex:pageBlock id="PagBlck">
          <apex:commandButton value="Create Account" action="{!save}" reRender="frm" status="actStatus"/>
          <apex:actionFunction action="{!save}"  status="actStatus" name="actfunct" reRender="frm,fields"/>
          <apex:actionFunction name="accparam" reRender="AccIdcheck">
              <apex:param name="p1" value="" assignTo="{!Acid}" />
          </apex:actionFunction>
          <apex:actionStatus startStyleClass="requiredLoaderBG" id="actStatus"></apex:actionStatus>
          <Div align="right">
              <apex:inputText value="{!Acid}" styleClass="AccClass" id="AccIdcheck"/>
              <apex:inputHidden value="{!Acid}" id="myHiddenField"/>
              <apex:inputText value="{!num}" style="width:45px"/>
              <apex:commandButton value="Add rows" action="{!add_rows}" reRender="tblop" status="actStatus"/>
          </Div>
          <apex:outputPanel rendered="{!val}" id="tblop">
              <apex:pageBlockTable value="{!AccoList}" var="Alst"  id="tbl">
                  <apex:column value="{!Alst.name}" rendered="{!if(Alst.name != null , true ,false)}"/>
                  <apex:column >
                      <apex:inputField value="{!Alst.name}" rendered="{!if(Alst.name != null ,false,true)}"/>
                  </apex:column>
                 
                  <apex:column >
                      <!--<input type="button"  value="Create" onclick="actfun"> <!-- onclick="actfunct();" - ->
                              <apex:param value="{!Alst.id}" name="Acntid" assignTo="{!Acid}"/>
                      </input> -->
                      <apex:commandLink value="Create"   action="{!Save}"> <!-- action="{!Save}" -->
                          <apex:param value="{!Alst.id}" assignTo="{!Accid}"/>
                      </apex:commandLink>
                  </apex:column>
              </apex:pageBlockTable>
          </apex:outputPanel>
         
          <apex:pageBlockSection id="fields" rendered="{!Not(val)}">
              <input type = "button" value = "Save" onclick = "CrtCont();" />
              <apex:actionFunction action="{!SaveContact}" status="actStatus" name="CrtCont" />
                      <apex:inputField value="{!Con.firstname}"/>
                      <apex:inputField value="{!Con.lastname}"/>
          </apex:pageBlockSection>
         <!-- apex:pageBlockSection rendered="{!Not(val)}">
              <apex:inputField value="{!Acc.name}"/>
              <apex:inputField value="{!Acc.Phone}"/>
              <apex:inputField value="{!Acc.type}"/>
              <!--<apex:selectRadio value="{!Acc.Rating}">
                    <apex:selectoptions value="{!types}"></apex:selectoptions>
              </apex:selectRadio> - ->
              <c:PicklistValue />
          </apex:pageBlockSection> -->
         </apex:pageBlock>
      </apex:form>
    
</apex:page>

Apex :-

Public Class AccountListController{
    Public List<Account> AccoList {get; set;}
    Public Contact Con {get; set;}
    Public Account Acc {get; set;}
    Public Boolean val {get; set;}
    Public String Acid {get; set;}
    public integer num {get; set;}
    Public String Accid{get; set;}
   
    Public AccountListController(){
        Con = new Contact();
        Acc = new Account();
        val = true;
        AccoList = [Select id, name from Account limit 1000];
    }
    /**Public List<Account> getAcco(){
        AccoList = [Select id, name from Account limit 1000];
        return AccoList;
    }**/
    Public PageReference Save(){
        val = false;
       // Acid = apexpages.currentpage().getparameters().get('Acntid');
        System.debug('++++++Acid+++++'+Acid);
        //Con.Accountid = Acid ;
        upsert AccoList;
        return null;
    }
    Public PageReference SaveContact(){
        //Accid = Apexpages.currentpage().getparameters().get('p1');
        System.debug('++++++Acid+++++'+ Accid);
        Con.Accountid = Accid ;
        insert Con;
        if(Acc.name != null)
        insert Acc;
        return null;
    }
     Public PageReference add_rows() {
        for(integer i=0;i<num ;i++)
            {
            System.debug('======Entering===='+i);
              AccoList.add(new Account());   
            }
            return null;
     }
    Public PageReference SaveAccount(){
        return null;
    }
    Public List<SelectOption> getTypes(){
        Schema.sObjectType sobject_type = Account.getSObjectType();
        Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe();
        Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap();
        List<Schema.PicklistEntry> pick_list_values = field_map.get('Rating').getDescribe().getPickListValues();
        List<selectOption> options = new List<selectOption>();
        for (Schema.PicklistEntry a : pick_list_values) {
             options.add(new selectOption(a.getLabel(), a.getValue()));
          }
        return options;
    }
}
Ramu_SFDCRamu_SFDC
The following articles would be helpful

http://www.eltoro.it/ArticleViewer?id=a07A000000NPRhfIAH

http://www.mindfiresolutions.com/How-to-pass-ID-in-Visualforce-1578.php
Amit BangadAmit Bangad
This might sound weird but give it a shot :)

<apex:actionFunction name="accparam" reRender="AccIdcheck" Oncomplete="">
<apex:param name="p1" value="" assignTo="{!Acid}" />
</apex:actionFunction>

Cheers,
Amit