Database.getUpdated() using Visualforce and Apex in Salesforce

Database.getUpdated() using Visualforce and Apex in Salesforce

Sample Code:
Visualforce Page:
<apex:page controller=”DatabaseGetUpdatedController”>
    <apex:pageBlock>
    <apex:pageBlockTable value=”{!listAccounts}” var=”acc”>
            <apex:column headerValue=”Name”>{!acc.Name}</apex:column>
            <apex:column headerValue=”Industry”>{!acc.Industry}</apex:column>
            <apex:column headerValue=”Type”>{!acc.Type}</apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
Apex Class:
public class DatabaseGetUpdatedController {
    
    public List < Account > listAccounts { get; set; }
    
    public DatabaseGetUpdatedController() {
        
        Database.GetUpdatedResult r = Database.getUpdated(
            ‘Account’,
            Datetime.now().addDays( -20 ),
            Datetime.now()
        );
        listAccounts = [ 
            SELECT Id, Name, Industry, Type 
            FROM Account 
            WHERE Id IN: r.getIds() 
        ];
                        
    }
    
}
Output:


Leave a Reply