function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
1204198312041983 

Need to Update the record with Trgger

Hi,

 

I wrote one trigger like this:

 

trigger UpadteKYCStatus on Account (before insert,before update)
{list<account> aclist=new list<account>();
for(Account ac: trigger.new)
   {
      acList.add(ac);
   }

if(aclist.size() !=0)
{
for(Account acc :acList)
{
if(acc.Expiration_Date__C < system.Today())
 {
  acc.Is_KYC_Approved__c='Expired';
 }
}
}
}

 

But this trigger is not working for automatic record refresh.

ex.When i am creating one customer with Expiration Date > today's date and the KYC Status should be Expired tomorrow automatically.

But this status is not updating automatically.After clicking on Edit and Save this Status is changing to "Expired"

Please let me know, how the record will be automatically get updated.

 

Regards,

Pragnya

 

SamuelDeRyckeSamuelDeRycke

I think you've not undestood the concept of triggers. They run at the moment of insert/update/delete and only at that time. So you can't specify an event/logic execution to happen in the future.

 

Have you considered a workflow rule with a time-dependent workflow action ?

asish1989asish1989

Hi

   Try this ...

        

trigger UpdateAccount on Account (before insert , before update) {
List<Account> actlist = [select id , Name ,Is_KYC_Approved__c ,Expiration_Date__C from Account where Expiration_Date__C = System.Today()-1];
if(actlist !=NULL && actlist.size() !=0){

for(Account account :actlist){
account.Is_KYC_Approved__c = 'Expired';
}

}
}

 

 

If it is answered your problem ..please mark it solved ..

 

Thanks

asish