0

We have an integration for data synchronization between Salesforce and our system.
But meanwhile, we run into a performance problem because we are querying a lot of "old" campaigns with uninteresting data.
The data of interest are custom objects (only modified or new), these custom objects are in a many to one relationship to the standard campaign object.

My idea would be to mark the campaign as "uninteresting" with the help of a custom field. If all the custom objects for a campaign haven't been modified since a certain amount of time or no new custom objects were added to that campaign, mark the campaign as "uninteresting.
What would be the best way to achieve this? Some sort of timer job?

I guess there are different approaches to achieve our goal every idea is highly appreciated.
Thanks in advance.

2
  • 2
    A bit more information please. Does the parent object have to be marked when one child object hasn't been modified or when all child objects haven't been modified? Nov 23 '16 at 14:58
  • @SanderdeJong Sorry I edited the question a bit. It is about all custom objects. Modified or new.
    – Detached
    Nov 24 '16 at 7:17
1

One approach is to have a Scheduled Batch Job - Schedule a batch class to run on a daily basis. Query all the campaigns and its child record who has the max Last modified date among the child records. Compare the last modified date with the date threshold that you have set

Date dateThreshold = Date.Today().addMonths(-6);

List<Campaign> campaignList = Select Id, Uninteresting__c,...(Select Id, LastModifiedDate from Child_Records__r order by LastModifiedDate Desc limit 1) from Campaign
for(Campaign c : campaignList){
    if(!c.Child_Records__r.isEmpty()){
        for(Child_Records__c childs : c.Child_Records__r){
            if(childs.LastModifiedDate < dateThreshold ){
                c.Uninteresting__c = true;
            }
        }
    }
    else{
        c.Uninteresting__c = true;
    }
}

update campaignList;

Once you have updated the campaigns, you can filter them in your external callout.

Select Id from Campaigns where Uninteresting__c  = false;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.