+ Start a Discussion
Hari nadh babu Eluru 7Hari nadh babu Eluru 7 

visualforce page modified recently

fetch and display students whose records modified recently in visualforce page
Best Answer chosen by Hari nadh babu Eluru 7
Suraj Tripathi 47Suraj Tripathi 47
HI Hari,
Please try this code:

Vf Page:
<apex:page controller="SearchStudent">
    <apex:form >
        <apex:pageblock title="Recently Modified student">
          
            <apex:pageBlockTable value="{!stu}" var="c">
                <apex:column value="{!c.Name}"/>
            </apex:pageBlockTable>
        </apex:pageblock>        
    </apex:form>
</apex:page>


Apex class:

public class SearchStudent {
    
    public List<Student> stu {get;set;}
 
    public SearchStudent(){
        DateTime dt = System.Now().addHours(-1);
        stu = [SELECT Id,Name, Phone,LastModifiedDate FROM Student where LastModifiedDate=:dt ORDER BY LastModifiedDate DESC LIMIT 1];
        system.debug('stu'+stu);
        
    }
}
Hope this will help you.
Thanks.

 

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Hari,

Please help the community to understand the requirement. Do we need to display all the records which were modified after some date. Can you elobrate what is meant by recently here.

Thanks,
 
Hari nadh babu Eluru 7Hari nadh babu Eluru 7
modified after some date and time sir. If user modified recently 1 hour ago we can also show that
Suraj Tripathi 47Suraj Tripathi 47
HI Hari,
Please try this code:

Vf Page:
<apex:page controller="SearchStudent">
    <apex:form >
        <apex:pageblock title="Recently Modified student">
          
            <apex:pageBlockTable value="{!stu}" var="c">
                <apex:column value="{!c.Name}"/>
            </apex:pageBlockTable>
        </apex:pageblock>        
    </apex:form>
</apex:page>


Apex class:

public class SearchStudent {
    
    public List<Student> stu {get;set;}
 
    public SearchStudent(){
        DateTime dt = System.Now().addHours(-1);
        stu = [SELECT Id,Name, Phone,LastModifiedDate FROM Student where LastModifiedDate=:dt ORDER BY LastModifiedDate DESC LIMIT 1];
        system.debug('stu'+stu);
        
    }
}
Hope this will help you.
Thanks.

 
This was selected as the best answer