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
1986anuj1986anuj 

Edit the records

Hello,

 

I am trying to add a edit button at the end of each record i have displayed in a pageblockSection.

This edit button, when clicked, should display the fields to be edited into an another page block just below it.

Please let me know which query i need to use in edit method of apex class.

Below is the VF and Controller code -

 

VF Code -

 

 

<apex:page Controller="JobPortal" sidebar="false">

<apex:relatedList list="OpenActivities" subject="{!$CurrentPage.parameters.relatedId}" />

<apex:form id="form">

<apex:pageBlock title="My Details" id="data" mode="edit">

<apex:pageBlockSection title="All Details" id="detail">

<apex:pageBlockTable value="{!details}" var="p">

<apex:column value="{!p.Name}"/>

<apex:column value="{!p.First_Name__c}"/>

<apex:column value="{!p.Last_Name__c}"/>

<apex:column>

<apex:commandButton action="{!edit}" value="Edit" reRender="edit"/>

</apex:column>

</apex:pageBlockTable>

</apex:pageBlockSection>

<apex:pageBlockSection title="Edit Details" id="edit">

<apex:inputField value="{!test.First_Name__c}"/>

<apex:inputField value="{!test.Last_Name__c}"/>

<apex:commandButton action="{!save}" value="save" reRender="detail"/>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:form></apex:page>

 

 

 Controller Code - 

 

 

public class JobPortal

{

public Job_Portal__c test=null;

List<Job_Portal__c> details;

public Job_Portal__c getTest()

{

if(test==null)

{

test = [select First_Name__c, Last_Name__c from Job_Portal__c limit 1];

} return test;

}

public List<Job_Portal__c> getDetails()

{

return [select Name, First_Name__c, Last_Name__c from Job_Portal__c];

}

 

public PageReference edit()

{

test=[select First_Name__c, Last_Name__c from Job_Portal__c where First_Name__c='Gaurav' limit 1];

return null;

}

public PageReference save()

{

try {

//upsert(portal);

update(test);

}

catch(System.DMLException e)

{

ApexPages.addMessages(e);

return null;

}

// After Save, navigate to the default view page:

//return (new ApexPages.StandardController(portal)).view();

return null;

}

}

 

 

 

 

 

Message Edited by 1986anuj on 03-20-2009 02:43 AM
Message Edited by 1986anuj on 03-20-2009 02:47 AM