raym0nd
raym0nd

Reputation: 3262

Salesforce Page auto update upon update of database

I have the following page that shows documents from database, what I'm trying to accomplish is to make this page refresh or update automatically if a new document is added in the database. Is there a way I can use AJAX or pulling or something in my controller or page to accomplish that ?

Page:

    <apex:pageBlockTable value="{!docs}" var="d" rendered="{!NOT(ISNULL(docs))}" Title="Documents">  
        <apex:column headerValue="Name">
               <apex:outputText value="{!d.Name}"/>           
       </apex:column>   
   </apex:pageBlockTable>

Contoller

 public List<FTPAttachment__c> getDocs()
    {
        docs= [Select Name from FTPAttachment__c where Case__c  = :cse.id];
        return docs;

    }

Upvotes: 2

Views: 1838

Answers (2)

Phil R
Phil R

Reputation: 423

Alternatively you could use the streaming api.

http://www.salesforce.com/us/developer/docs/api_streaming/index.htm

Upvotes: 1

JCD
JCD

Reputation: 2231

Sounds like you're looking for the <apex:actionPoller> tag:

<apex:actionPoller action="{!refreshDocs}" rerender="docsTable" interval="5" />
<apex:pageBlockTable id="docsTable" value="{!docs}" var="d" rendered="{!NOT(ISNULL(docs))}" Title="Documents">  
    <apex:column headerValue="Name">
        <apex:outputText value="{!d.Name}"/>           
    </apex:column>   
</apex:pageBlockTable>

You could have the refreshDocs() method explicitly repopulate the docs list, but since you're already doing that in your getter (which will be called when the table is re-rendered), this method can just return without doing anything special:

public List<FTPAttachment__c> getDocs() {
    return [Select Name from FTPAttachment__c where Case__c  = :cse.id];
}
public PageReference refreshDocs() {
    return null;
}

Upvotes: 2

Related Questions