+ Start a Discussion

Not Sure if Trigger is right solution...

Hi Everyone,


I'm working on a solution to export records that meet do not have a date in a customer field called Extract_Date__c.  I have a controller and a VF page that displays the records and a button on the VF page that exports the data in a .csv format.  Once the records have been exported, I need to update the Extract_Date__c field with the date the records were extracted. 


I have a method written that updates the field, but not sure how to update the records once they are extracted.  I was thinking a trigger, but am not sure.  Any thoughts?


Thanks for your assistance!




r u deleting data from database or just export them? If only export use future method in your apex class after you are done with export.


I assume you have a button "Export" on your VF age that calles an action method which does the export. In that action method, include a loop that iterates through the list of records and sets the date field to System.today(). Then include an update call.

A trigger will not help here.



public PageReference yourActionMethod()
   --- your Code to do the csv export here ---

   for(yourObject theRecord:recordList)  //just making up variable names here, replace with your variables
      theRecord.Extract_Date__c = System.today();
    update recordList;

    return PageReference (--- your PageReference here, you probably have this already ---)





If you can implement Ahab1372's approach , i think its the most straightforward solution.

After being done with the export , update the records you just exported.


If you have any doubts on how to implement , reply and ill be glad to help you out.