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>

  • How do you know that the page block isn't refreshed? Try to change rerender to reRender. – Sergej Utko Oct 8 '13 at 7:36
  • Because the page block table showing the old values while database is updated with the new value. – LoveSalesforce Oct 8 '13 at 8:46
  • @LoveSalesforce did you get an answer for it? – snehakem Jan 7 '16 at 9:10
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>
| improve this answer | |
  • 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.. – LoveSalesforce Oct 8 '13 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>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.