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
Sai Teja 7557Sai Teja 7557 

how to pass selected radio button id to apex class

Hey guys,
I have been struck here from the last two days please help me in this,
>the first screen shot is mydetailpage in that page, slected file field which is url type. 
User-added image
>"open VF page" button is my custo button, on click of that button I'm opening my VF Page.
VF Page Logic:
<apex:page standardController="MyCustom_2__c" extensions="openmyvfpage" >
   <apex:form >
       <apex:pageBlock >
           <apex:pageBlockSection columns="1">
            
            <apex:pageBlockTable value="{!lst}" var="a" id="accTable">
                    <apex:column headerValue="Select" >
                        <input type="radio" name="<strong>selectRadio</strong>" id= "radio">
                        <apex:param assignTo="{!selectedAttachementId}" name="accname" value=" {!a.id}"/>
                        </input>
                    </apex:column>
                    <apex:column value="{!a.ContentDocument.LatestPublishedVersion.Title}"/>
               </apex:pageBlockTable>
      
           <apex:commandButton value="Save" action="{!test}" rendered="{!IF(warning==null,true,false)}"  />
            </apex:pageBlockSection>
           <apex:pageBlockSection rendered="{!IF(warning==null,false,true)}">
             {!warning}
           </apex:pageBlockSection>
       </apex:pageBlock>
   </apex:form>
</apex:page>
> the second screen shot is my vf page preview
User-added image
> from vf page i need to select one radion button, on click of save it should redirect to my detail page with updated value of "selected file" field
>My Controller logic:
public class openmyvfpage {
    
    public List<ContentDocumentLink> lst {set;get;}
    public id  currentURL {set;get;}
    public string warning {set;get;}
    public String selectedAttachementId {get;set;}
    
    public openmyvfpage(ApexPages.StandardController controller) {
        currentURL = apexpages.currentpage().getparameters().get('id');
        System.debug('>>>'+currentURL);
        List<MyCustom_2__c> parentid=[SELECT MyCustom_1__c FROM MyCustom_2__c WHERE Id=:currentURL LIMIT 1];
        System.debug('>>>>'+parentid);
        if(parentid[0].MyCustom_1__c!=null){
        lst=[SELECT Id, ContentDocument.LatestPublishedVersion.Title
                        FROM ContentDocumentLink 
                        WHERE LinkedEntityId =:parentid.get(0).MyCustom_1__c];
            if(lst.size()<0){
              warning='For this Record there are no attachemnts found';  
            }
        }else{
        warning='For this Record there are no attachemnts found';
        }
    }
        public PageReference test(){
            system.debug('>>'+selectedAttachementId);
            system.debug('>>>'+currentURL);
                 MyCustom_2__c my =new MyCustom_2__c();
                my.id=currentURL;
                my.Selected_File__c=selectedAttachementId;
                update my;
                PageReference p= new PageReference('/'+currentURL);
                p.setRedirect(true);
                return p;
            }
}
The issue I'm facing here is I'm unable to capture the selected radio button record id.

 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Sai Teja,

Can you try checking the below link as it seems to have a similar implementation that you could use for reference to developed custom implementation for your scenario.

Link: http://forceforte.com/display-selected-records-of-one-visualforce-page-on-another-visualforce-page/

I hope this helps and in case if this comes handy can you please choose this as the best answer so that it can be used by others in the future.

Regards,
Anutej