You need to sign in to do that
Don't have an account?
vickySFDC
How to Inactive account status no activity assigned?
Hi All,
I have requirement for Inactive account if there is no activity like(task,event) assigned for last 30 days for that account.Anyone help on this scenario.Give some sample code.How to implement.
Thanks,
vicky
I have requirement for Inactive account if there is no activity like(task,event) assigned for last 30 days for that account.Anyone help on this scenario.Give some sample code.How to implement.
Thanks,
vicky
I think Batch class and a scheduler will work for it.
Scheduler will run everyday and will check those records who are eligble for this condition i.e no activity for more than 30 days.
Thanks,
Arun
You can see by looking at the Dev Console that when I pass in 30, it grabs things with a date less than 2015-12-21 22:03:30
You can then setup a batch job to call this on the fly or nightly, weekly.
Example of a one-time run:
Some great resources:
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_batch_1.htm
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_batch_3.htm
https://developer.salesforce.com/docs/atlas.en-us.198.0.apex_workbook.meta/apex_workbook/apex_scheduling_3.htm#apex_scheduling_3
I will check and let me know
Thanks,
vicky
This code not working.I have tested this code using lastactivitydate.
Scenario:
I have added new account and checking for if no activity assigned for last 3 days then my custom field has Active check box made as false.
CODE:
global class Inactiveaccountstatus implements Database.Batchable<SObject>, Database.Stateful {
global final integer activitydays;
global Inactiveaccountstatus (integer activitydays)
{
this.activitydays = activitydays;
}
global Database.Querylocator start(Database.BatchableContext bc) {
Date oldactvitydate = system.today().addDays(-1 * activitydays);
string query = 'select Id from Account WHERE LastActivityDate <: oldactvitydate AND LastModifiedDate <: oldactvitydate Order by LastActivityDate ASC ';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope){
List<Account> lstacc = new List<Account>();
for(sObject s : scope){Account a = (Account)s;
a.Active__c = false;
lstacc.add(a);
}
try
{
system.Debug(' lstacc +++++++++'+lstacc);
update lstacc;
}
catch(DMLException ex)
{
}
}
global void finish(Database.BatchableContext bc) {
}
}
Please help me on this.
Thanks,
vicky
- Can you show us how you are calling this code?
- What are you passing in for the days param?
- If you look at the stack trace is it returning results from the query? i.e. did it find accounts that matched the criteria
Just as a simple test I took the query lines and ran them in the Dev console on my account to make sure that the query returns results:After running the following in my order I get 5 records, which is correct because the 6th account has an activity that I just added to it.
You should be open to open the Setup > Dev Console > Debug > Open Execute Anonumous and run the class like I gave in the example above but in your case you want 3 so you pass in 3 instead of 30
I guess in your case it would be
When you run this you'll see the debug logs and you should be able to see why it is not working. I am just trying to see where it is failing.