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
Sucharita NandanSucharita Nandan 

How I can Edit/Save for individual row?

I want to show edit page of opportunity when edit button on list of opportunity will be clicked, after that when save is clicked again we can view the list on same block

VF page
<apex:page showHeader="true" sidebar="true" controller="SalesOrderEntryController" >
    <apex:form>
    <apex:pageBlock title="Account Detail">
            <apex:pageBlockButtons>
                <apex:commandButton value="Save" action="{!saveAcc}" reRender="editButton" />
                <apex:commandButton value="Edit" action="{!editAcc}" reRender="savebutton"/>
            </apex:pageBlockButtons >
        <apex:pageBlockSection  id ="savebutton" rendered="{!rend}" >
                <apex:inputField value="{! acc.Name }" label="Account Name" />
                <apex:inputField value="{! acc.CurrencyIsoCode }" label="Account Currency Code"/>
                <apex:inputField value="{!acc.OwnerId}" label="Owner"/>
                <apex:inputField value="{!acc.Locked_Employees__c}" label="Employess"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection  id ="editButton" >    
                <apex:outputField value="{! acc.Name }" label="Account Name"/>
                <apex:outputField value="{! acc.CurrencyIsoCode }" label="Account Currency Code"/>
                <apex:outputField value="{!acc.OwnerId}" label="Owner"/>
                <apex:outputField value="{!acc.Locked_Employees__c}" label="Employess"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock title="Related Opportunities" id="opps">
            <apex:pageblocktable value="{!listOfOpps}" var="o">
                <apex:column>
                    <apex:commandbutton value="Edit" rerender="opps" rendered="{!!( opptoBeEdited == o.Id )}">
                        <apex:param assignTo="{!opptoBeEdited}" value="{!o.Id}" name="optobeedited"/>
                    </apex:commandbutton>
                    <apex:commandButton value="Save" action="{!oppEditSaveClicked}" reRender="opps" rendered="{!opptoBeEdited == o.Id}"/>
                </apex:column>                
                <apex:column  headerValue="Opportunity Name" >
                    <apex:commandLink action="{!OppClicked}" reRender="opliDetail, orderDetail,tabp" >
                        <apex:outputField value="{!o.Name}" rendered="{!!opptoBeEdited == o.Id}"/>
                        <apex:param name="oppId" value="{!o.Id}" assignTo="{!selectedOPId}"/>
                    </apex:commandLink>
                    <apex:inputField  value="{!o.Name}"  rendered="{!(opptoBeEdited == o.Id)}"/>
                </apex:column>
            </apex:pageblocktable>
                <apex:panelGrid columns="10" style="margin-left:40%">
                    <apex:commandButton status="fetchStatus" reRender="opps" value="First" action="{!con.first}" disabled="{!!con.hasPrevious}" title="First Page"/>
                    <apex:commandButton status="fetchStatus" reRender="opps" value="Previous" action="{!con.previous}" disabled="{!!con.hasPrevious}" title="Previous Page"/>
                    <apex:commandButton status="fetchStatus" reRender="opps" value="Next" action="{!con.next}" disabled="{!!con.hasNext}" title="Next Page"/>
                    <apex:commandButton status="fetchStatus" reRender="opps" value="Last" action="{!con.last}" disabled="{!!con.hasNext}" title="Last Page"/>
                    <apex:outputText >{!(con.pageNumber * size)+1-size}-{!IF((con.pageNumber * size)>noOfRecords, noOfRecords,(con.pageNumber * size))} of {!noOfRecords}</apex:outputText>
                </apex:panelGrid>
        </apex:pageBlock>
        <apex:pageBlock>
        <apex:pageBlockSection>
            <apex:tabPanel switchType="client" selectedTab="tabopli" id="tabp" >
                <apex:tab id="tabopli" label="Opportunity Line Item" name="OPLI" >
                    <apex:pageBlockTable id="opliDetail" value="{!productFromOPLI}" var="opli" style="float:right;" title="OpportunityLineItem Details">
                        <apex:column headerValue="Product Name" value="{!opli.Product2.Name}"/>
                        <apex:column headerValue="Porduct Code" value="{!opli.Product2.ProductCode}"/>
                        <apex:column headerValue="TotalPrice" value="{!opli.TotalPrice}"/>
                        <apex:column headerValue="Quantity" value="{!opli.Quantity}"/>
                    </apex:pageBlockTable>
                </apex:tab>
                <apex:tab id="tabOrder" label="OrderItems"  name="OrderI">
                    <apex:pageBlockTable value="{!listOfOrderLI}" var="ord" id="orderDetail" title="OrderItem Details">
                        <apex:column headerValue="Order Item Number" value="{!ord.OrderItemNumber}"/>
                        <apex:column headerValue="Product Name" value="{!ord.PricebookEntry.Product2.Name}"/>
                        <apex:column headerValue="UnitPrice"  value="{!ord.UnitPrice}"/>
                        <apex:column headerValue="Quantity" value="{!ord.Quantity}"/>
                    </apex:pageBlockTable>
                </apex:tab>
            </apex:tabPanel>
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>

Controller
public with sharing class SalesOrderEntryController {
    
    public Account acc{ get; set; }
    public List<Opportunity> listOfOpps;

    public Id opptoBeEdited{ get; set; }

    Public Integer noOfRecords{get; set;}
    Public Integer size{get;set;}

    //we take a variable of ID of selected Opportunity  property
    public Id selectedOPId{ get; set; }


    //we take a variable of List of OrdrItem property
    public List<OrderItem> listOfOrderLI{ get; set; }

    //we take a variable of Product property
    public List<OpportunityLineItem> productFromOPLI{ get; set;}

    // property for selected Order id (on which the Save is clicked - inline save)
    public String selectedOrderLIId { get; set; }

    // property for selected OppLI id (on which the Save is clicked - inline save)
    public String selectedOPLIId { get; set; }

    
    public SalesOrderEntryController() {
        this.acc = [select Id, Name,CurrencyIsoCode, OwnerId, Locked_Employees__c from Account
                            where Id = :ApexPages.currentPage().getParameters().get('id')];
        this.listOfOpps = new List<Opportunity>();
        this.listOfOrderLI = new List<OrderItem>();
        this.productFromOPLI = new List<OpportunityLineItem>();
    }

    public Pagereference saveAcc(){
        try{
            update acc;
            this.acc = [select Id, Name,CurrencyIsoCode, OwnerId, Locked_Employees__c from Account
                            where Id = : acc.Id ];
            return null;
        }catch(Exception ex){
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, ' you cannot edit this acc'+ex.getMessage());
            ApexPages.addMessage(msg);
            return null;
        }
        
    }
    public Pagereference editAcc(){
        try{
            this.acc = [select Id, Name,CurrencyIsoCode, OwnerId, Locked_Employees__c from Account
                            where Id = : acc.Id ];
            return null;
        }catch(Exception ex){
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, ' you cannot view this acc'+ex.getMessage());
            ApexPages.addMessage(msg);
            return null;
        }
        
    }




    // ApexPages.StandardSetController must be instantiated   
    //
    /*
    * pagination methods
    */
    // standard set controller      
    public ApexPages.StandardSetController con {
        get {
            size = 4;
            if(con == null) {
                con = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [ Select Id, Name, Account.Name, CloseDate, Amount, Type from Opportunity where AccountId =: acc.Id ]));
                con.setPageSize(size);
                noOfRecords = con.getResultSize();
            }
            return con;
        }
        set;
    }

     
    // Initialize setCon and return a list of records
   
    public List<Opportunity> getlistOfOpps() {
         List<Opportunity> opplist = new List<Opportunity>();
         for( Opportunity o :(List<Opportunity>)con.getRecords() )
            opplist.add(o);
         return opplist;
    }

    public void oppEditSaveClicked(){
        try{
            Opportunity tobeUpdatedOp;
            for( Opportunity tempOpp :listOfOpps ){
                if( tempOpp.Id == opptoBeEdited ){
                    tobeUpdatedOp = tempOpp;
                    break;
                }
            }
            update tobeUpdatedOp;
            tobeUpdatedOp = null;
            }catch(Exception e){
            ApexPages.Message errMess = new ApexPages.Message(ApexPages.Severity.ERROR, ' you cannot view Orderitem for this Opp'+e.getMessage());
            ApexPages.addMessage( errMess );
        }
    }
 

    public Void OppClicked(){
        try{
            this.listOfOrderLI = [ Select Id, OrderId , PricebookEntryId, CurrencyIsoCode,
                                                            UnitPrice, Quantity, OrderItemNumber,  PricebookEntry.Product2.Name
                                                            from OrderItem
                                                            where Order.OpportunityId =:selectedOPId
                                                            and  Order.AccountId =:this.acc.Id ];
            System.debug('=====opp id====' + selectedOPId);
            if( listOfOrderLI.isEmpty() ){
                ApexPages.Message noOrderItem = new ApexPages.Message(ApexPages.Severity.INFO, ' There are no OrderItem');
                ApexPages.addMessage( noOrderItem );
            }

        }catch(Exception e){
            ApexPages.Message errMess = new ApexPages.Message(ApexPages.Severity.ERROR, ' you cannot view Orderitem for this Opp'+e.getMessage());
            ApexPages.addMessage( errMess );
        }
        try{
            this.productFromOPLI = [ Select Id, Product2.Id, TotalPrice, Quantity, Product2.ProductCode, UnitPrice,
                                                                Product2.Family, Product2.Name , OpportunityId from Opportunitylineitem
                                                                where OpportunityId =:selectedOPId and Opportunity.AccountId =: this.acc.Id ];
        }catch(Exception e1){
            ApexPages.Message errMess = new ApexPages.Message(ApexPages.Severity.ERROR, ' you cannot view OpportunityLineItem for this Opp'+e1.getMessage());
            ApexPages.addMessage( errMess );
        }
    }
}

below page how can i show the edit page of that clicked opportunity with few field and save button, and when save is clicked then again list opp opportunity will be apeared.
User-added image
Dilip_VDilip_V
Hi Sucharita,

Try to use inline edit functionality.Display data in a table and enable inline editing.

for more Info:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_inlineEditSupport.htm
Thanks.
 
Chandra Sekhar CH N VChandra Sekhar CH N V
Try 
<apex:relatedList list="Opportunities" />

as the record is related to a parent record with a lookup or master-detail relationship