+ Start a Discussion
SidharthSidharth 

Time dependent Field Updates

Hello All

 

Child Object : C, with one date field DF1.

When DF1 passes Today (i.e no longer => Today), it should update master object fields.

 

The trigger is not catching this. How should i go about this?

One possible solution is to schedule a batch to run every day, but not sure if thats the best solution.

 

Any help will be appreciated.

 

Thanks

Sid

 

 

 

Vinit_KumarVinit_Kumar

Have you tried:-

 

Date DF1 = system.today() + 1; // it would result the next dat

 

 

SidharthSidharth

Hey Vinit, i dont understand what you trying to say.

 

Vinit_KumarVinit_Kumar

I am trying to say;

 

Lets say your object is Obj__c,then use it like below :-

 

Obj__c ob = new Obj__c();

ob.DF__c = system.today() + 1 ; // This will assign the next day to your field DF__c

 

 

SidharthSidharth

I dont have to change DF1 field.

 

My question, is when this date field is no longer a future date (i.e < Today), it should update the master object fields.

 

Ex: for a record, DF1 is 3/4/2013 and this record is good. But tomorow this date will be a past date, and the record is no longer good.

Vinit_KumarVinit_Kumar

Then,do this

 

Date dt = system.today();

 

Obj__c ob = new Obj__c();

if(obj.DF__c<dt){

 

// do your code here

 

}

SidharthSidharth

Hey Vineet. Please read my post carefully. I am not asking help to write a If-else code.

The condition i am saying, the trigger doesnt catch that, So i need a way which checks if that date date is passed, and do the related updates

 

 

 

 

:) :) :) :) :):) :) :) :) :)

This would also help you to achive your goal.

 

System.today().addDays(-1);

 

Thanks.

jnegijnegi

@Sidharth

 

Scheduling with batch apex should be a feasible solution for your requrirement, which will execute on daily basis and will update master object fields as per your condition.

 

Thanks,

Jagmohan

Vinit_KumarVinit_Kumar

Sidharth,

 

I am not sure what yo mean,

 

Both the code would work :-

 

Obj__c ob = new Obj__c();

Date dt = system.today() + 1 ;

 

Or

 

Date dt = system.today().addDays(+1);

 

and you can use it in Trigger like below :-

 

for(Obj__c ob:Trigger.new){

if(

if(obj.DF__c<dt){

 

// do your code here

 

}

)

}