6

The rerender is not working. My data is getting updated but the pg block table is not getting refreshed. How to do that. Here is my code -

<script type="text/javascript">
    function DoSomething(rcId,status){
        try
        {   
            var RCObj = new sforce.SObject("Child__c"); 
            RCObj.id = rcId; 
            RCObj.Status__c = status;
            sforce.connection.sessionId = '{!GETSESSIONID()}'; 
            var result = sforce.connection.update([RCObj]); 
            if (result[0].getBoolean("success")) { 
                alert("Record Successfully Updated");
            } 
            else { 
                alert("Failed to update RC " + result[0]); 
            }
        }catch (e) {
            alert(e);
        }
    }
</script>
<apex:form>
    <apex:pageBlock id="pgBlock">
        <apex:pageBlockTable value="{!Parent__c.Child__r}" var="item" id="mid" title="Table 1">
            <apex:column value="{!item.Type__c}"/>
            <apex:column value="{!item.Status__c}"/>
            <apex:column headerValue="Action"> 
                <apex:commandLink value="Approve" id="Approve" onClick="DoSomething('{!item.id}','Approved')" rerender="pgBlock"/>
                </apex:column> 
        </apex:pageBlockTable> 
    </apex:pageBlock>
</apex:form>

3
  • How do you know that the page block isn't refreshed? Try to change rerender to reRender. Commented Oct 8, 2013 at 7:36
  • Because the page block table showing the old values while database is updated with the new value. Commented Oct 8, 2013 at 8:46
  • @LoveSalesforce did you get an answer for it?
    – snehakem
    Commented Jan 7, 2016 at 9:10

2 Answers 2

2

Added a actionFunction which will reRender the page once the doSomething funciton is done executing. Try this out:

 <script type="text/javascript">
    function DoSomething(rcId,status){
        try
        {   
            var RCObj = new sforce.SObject("Child__c"); 
            RCObj.id = rcId; 
            RCObj.Status__c = status;
            sforce.connection.sessionId = '{!GETSESSIONID()}'; 
            var result = sforce.connection.update([RCObj]); 
            if (result[0].getBoolean("success")) { 
                alert("Record Successfully Updated");
            } 
            else { 
                alert("Failed to update RC " + result[0]); 
            }
           //call the action fucntion to refresh the section of the page. 
            refreshPageBlock();
        }catch (e) {
            alert(e);
        }
    }
</script>

<apex:form>
    <apex:actionFunction name="refreshPageBlock" id="actionFunciton" reRender="pgBlock"/>
    <apex:pageBlock id="pgBlock">
        <apex:pageBlockTable value="{!Parent__c.Child__r}" var="item" id="mid" title="Table 1">
            <apex:column value="{!item.Type__c}"/>
            <apex:column value="{!item.Status__c}"/>
            <apex:column headerValue="Action"> 
                <apex:commandLink value="Approve" id="Approve" onClick="DoSomething('{!item.id}','Approved')"/>
                </apex:column> 
        </apex:pageBlockTable> 
    </apex:pageBlock>
</apex:form>
1
  • No its not working. the action function is getting called but old data showing. Only on page reload I am able to see updated data. Is it because I am using standard controller? I have no idea.. Commented Oct 8, 2013 at 9:03
2

Looks like you should be using CommandLink Action & Params to pass your data, You can add onComplete if it is needed but you should be ok without it.

<apex:commandLink value="Approve" id="Approve" action="{!controllerMethod}" rerender="pgBlock">
<apex:param name="linkId" value="{!link.id}"/>
</apex:commandLink>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .