Activity Forums Salesforce® Discussions Editing a record from selecting list of record using radio button

  • Aman

    Member
    May 29, 2018 at 1:23 pm

    Hi Jay,

    Please share your code so that i can check why it is not working and make the possible changes.

  • Jay

    Member
    May 29, 2018 at 1:44 pm

    Hi Aman

    VF and Controller code is mentioned below

    <apex:page Controller="ContactCustomController" >
    <apex:pageBlock title="contact List">
    <apex:form >
    <apex:pageBlockTable value="{!contacts}" var="con">
    <apex:column headerValue=" Name" value="{!con.Name}"/>

    <apex:column headerValue="Select">
    <input type="radio" name="selectRadio" id="radio">
    <apex:actionSupport event="onclick" action="{!goToEdit}" ><br/> <apex:param name="id" value="{!con.id}"/>
    </apex:actionSupport>
    </input>

    </apex:column>
    </apex:pageBlockTable>
    </apex:form>

    <apex:pageBlockButtons >
    <apex:form >
    <apex:commandButton value=" Go to edit page" action="{!goToEdit}"/>
    </apex:form>
    </apex:pageBlockButtons>
    </apex:pageBlock>
    </apex:page>

    Controller:

    public class ContactCustomController {
    Id Idvalue;
    Contact con;
    List<Contact> contacts=[SELECT Name, Id FROM contact];
    List<account> accs=[SELECT Name FROM Account ];
    List<Hospital__c> hosps=[SELECT Name FROM Hospital__c ];

    public List<Contact> getContacts(){
    return contacts;
    }
    public List<Account> getaccs(){
    return accs;
    }
    public List<Hospital__c> gethosps(){
    return hosps;
    }
    public PageReference goToEdit(){
    System.debug('Inside go to edit');
    Idvalue = ApexPages.currentPage().getParameters().get('id');
    system.debug('Id value='+Idvalue);
    con=[SELECT Name, MobilePhone, Id FROM contact WHERE Id=:Idvalue];
    return Page.ContactEditPage;
    }

    }

    • This reply was modified 6 years, 6 months ago by  Jay.
  • Aman

    Member
    May 30, 2018 at 9:35 am

    Hi Jay,

    There are two-three things that are missing in your code, first one is you have used apex:param but you haven't  assign the value for parameter to any variable of apex class. next is your are using Idvalue = ApexPages.currentPage().getParameters().get(‘id’); in your code, are you using this page of an sobject layout ?. next your are refrencing the page to another page, you haven't send the code for that page. please share the code for Page.ContactEditPage.

    Thanks

  • Jay

    Member
    May 31, 2018 at 5:23 am

    Hi Aman,

    main concern is below line is calling the action method edit i.e. goToEdit

    after selection of radio button

    <apex:actionSupport event=onclick”  action="{!goToEdit}">

     

    and I am not using any sObject layout, I am taking Id from VF page in controller action method and fetching that particular record for edit operation.

Log In to reply.

Popular Salesforce Blogs