1

I am trying to understand or come up with a solution for the issue we currently having in our Org. We have a situation that our Marketing users are adding the existing contacts to the Campaign which like 35K records are getting added to a campaign which locks the records for few mins that other users cannot add those contacts to the Cases that they are creating, which basically creates deadlocks on the records.

The users are using the reports and adding the Contacts from the report to Add to Campaign button on the report which is causing the issue

Is there a way to restrict the users to run these only after hours or have a way so that they can schedule this contacts to be added to Camapign after hours like in the night.

Implement the schedulable interface (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm) but I am not sure if this is the way to go.Any suggestion or help is greatly appreciated.

5
  • Please edit your post to include more details on how the users are adding the contacts -- are they using report > add campaign members, or data loader, or a 3rd party tool, etc? Jun 14, 2021 at 16:13
  • @DavidCheng I updated the question The users are using the reports and adding the Contacts from the report to Add to Campaign button on the report
    – user81642
    Jun 14, 2021 at 16:16
  • Do you only want to prevent the adding of campaign members just from reports or from all possible ways during the Job hours?
    – manjit5190
    Jun 14, 2021 at 19:08
  • @manjit5190 We want the job to run after hours even if they try to add contacts to Campaign using Add Campaign button
    – user81642
    Jun 14, 2021 at 19:56
  • This is standard functionality and you won't be able to delay the addition of members. You can take away the access to Add campaign member via reports somehow (either a permission or via the answer below) and only give this access after job hours. I am not sure how much this will impact your users day to day jobs. Please do consider that as well.
    – manjit5190
    Jun 15, 2021 at 13:46

1 Answer 1

0

This is a kind of transaction security policy where user is restricted to do certain things based on the action they perform on the org

This type of situation is very well handled by TransactionSecurity policies Have read this salesforce developer guide, it has detailed information and explanation to implement.

For your use case, you will have to implement a policy for a campaign member object

pseudo code picked from the guide link posted above

global class BlockAccountQueriesEventCondition implements TxnSecurity.EventCondition {

   public boolean evaluate(SObject event) {
      switch on event {
         when ApiEvent apiEvent {
            return handleApiEvent(apiEvent);
         }
         when null {
         // Trigger action if event is null
            return true;
         }
         when else {
         // Trigger action for unhandled events
            return true;
         }
      }
   }

   private boolean handleApiEvent(ApiEvent apiEvent){
      if(apiEvent.QueriedEntities.contains('Account')){ 
         return true;
      } 
      return false;
   }
}

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.