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
Pankaj Kumar 456Pankaj Kumar 456 

why my class id is not populating in controller

My Vf Page is 
<apex:page standardController="Class__c" extensions="ManageClassController" >
    <apex:pageBlock > 
        <apex:pageBlockSection >
            <apex:form >
                <apex:pageBlockTable value="{!classList}" var="c" >
                    <apex:column headerValue="class name">
                        <apex:outputText value="{!c.name}"></apex:outputText>
                    </apex:column>
                    <apex:column headerValue="Edit" >
                        <apex:commandLink value="Edit" action="{!editDetails}">
                            <apex:param assignTo="{!classId}" value="{!c.id}" />
                        </apex:commandLink>
                    </apex:column>    
                    <apex:column headerValue="Delete">
                        <apex:commandLink value="Delete">
                            <apex:param assignTo="{!classId}" value="{!c.id}" />
                        </apex:commandLink>
                    </apex:column>   
                </apex:pageBlockTable>
            </apex:form>
        </apex:pageBlockSection>
        <apex:pageBlockSection >
            
            <apex:form rendered="{!flag}">
                <apex:inputField value="{!dummyClass.name}"/>
                <apex:inputField value="{!dummyClass.Fee__c}"/>
                <apex:inputField value="{!dummyClass.Detailed_Description__c}"/>
                <apex:inputField value="{!dummyClass.Max_Size__c}"/>
                <apex:inputField value="{!dummyClass.My_Count__c}"/>
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandLink value=""/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:form>
            
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

My Controller is 
public class ManageClassController {
    public List<Class__c> classList{get;set;}
    public String classId{get;set;}
    public class__c dummyClass{get;set;}
    public boolean flag {get;set;}
    private ApexPages.StandardController controller {get; set;}
    public ManageClassController(ApexPages.StandardController stdController){
        this.controller = stdController;
        this.classList = new List<Class__c>([SELECT id , name from class__c]);
        this.flag=false;
        this.classId = null;
    }
    public void editDetails(){
        System.debug('I came here');
        System.debug('classId = ' + this.classID);
        if(this.classId != null){
            this.dummyClass = [SELECT id , name , fee__c , detailed_description__c , max_size__c , my_count__c FROM class__c where id = :classId];
            this.classId = null;
            this.flag = true;
        }
    }
}

My vf page is running as 
User-added imageand as soon as i press edit link value must get populate in controller but is not going
Debug only logs -
User-added imageThanks in advance
Best Answer chosen by Pankaj Kumar 456
Soyab HussainSoyab Hussain
Hi Pankaj Kumar,

I go through your issue, when we are using apex:param tag for get value in apex controller, its necessary to use name attribute in the same.

Use this code this will help you.
 
<apex:page standardController="Class__c" extensions="ManageClassController" >
    <apex:pageBlock > 
        <apex:pageBlockSection >
            <apex:form >
                <apex:pageBlockTable value="{!classList}" var="c" >
                    <apex:column headerValue="class name">
                        <apex:outputText value="{!c.name}"></apex:outputText>
                    </apex:column>
                    <apex:column headerValue="Edit" >
                        <apex:commandLink value="Edit" action="{!editDetails}">
                            <apex:param assignTo="{!classId}" value="{!c.id}" name="classId" />
                        </apex:commandLink>
                    </apex:column>    
                    <apex:column headerValue="Delete">
                        <apex:commandLink value="Delete">
                            <apex:param assignTo="{!classId}" value="{!c.id}" name="classId" />
                        </apex:commandLink>
                    </apex:column>   
                </apex:pageBlockTable>
            </apex:form>
        </apex:pageBlockSection>
        <apex:pageBlockSection >
            
            <apex:form rendered="{!flag}">
                <apex:inputField value="{!dummyClass.name}"/>
                <apex:inputField value="{!dummyClass.Fee__c}"/>
                <apex:inputField value="{!dummyClass.Detailed_Description__c}"/>
                <apex:inputField value="{!dummyClass.Max_Size__c}"/>
                <apex:inputField value="{!dummyClass.My_Count__c}"/>
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandLink value=""/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:form>
            
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

If you found it useful please appreciate my efforts and mark it as the best answer.

Regards,
Soyab

All Answers

Soyab HussainSoyab Hussain
Hi Pankaj Kumar,

I go through your issue, when we are using apex:param tag for get value in apex controller, its necessary to use name attribute in the same.

Use this code this will help you.
 
<apex:page standardController="Class__c" extensions="ManageClassController" >
    <apex:pageBlock > 
        <apex:pageBlockSection >
            <apex:form >
                <apex:pageBlockTable value="{!classList}" var="c" >
                    <apex:column headerValue="class name">
                        <apex:outputText value="{!c.name}"></apex:outputText>
                    </apex:column>
                    <apex:column headerValue="Edit" >
                        <apex:commandLink value="Edit" action="{!editDetails}">
                            <apex:param assignTo="{!classId}" value="{!c.id}" name="classId" />
                        </apex:commandLink>
                    </apex:column>    
                    <apex:column headerValue="Delete">
                        <apex:commandLink value="Delete">
                            <apex:param assignTo="{!classId}" value="{!c.id}" name="classId" />
                        </apex:commandLink>
                    </apex:column>   
                </apex:pageBlockTable>
            </apex:form>
        </apex:pageBlockSection>
        <apex:pageBlockSection >
            
            <apex:form rendered="{!flag}">
                <apex:inputField value="{!dummyClass.name}"/>
                <apex:inputField value="{!dummyClass.Fee__c}"/>
                <apex:inputField value="{!dummyClass.Detailed_Description__c}"/>
                <apex:inputField value="{!dummyClass.Max_Size__c}"/>
                <apex:inputField value="{!dummyClass.My_Count__c}"/>
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandLink value=""/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:form>
            
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

If you found it useful please appreciate my efforts and mark it as the best answer.

Regards,
Soyab
This was selected as the best answer
Pankaj Kumar 456Pankaj Kumar 456
Thank you Soyab Hussain it worked.
Soyab HussainSoyab Hussain