• Ronald Flisijn
  • NEWBIE
  • 30 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Trying to query what ApexClass was used by a CronTrigger by determining what Trigger executed an AsyncApexJob.

The AsyncApexJob shows the Apex Class and if I can query the CronTriggerId that executed that job, I can determine what job was using that Apex Class.

The SOAP API Developer Guide shows that the Metadata for AsyncApexJob has a field for CronTriggerId but when I attempted to query that info, I received an error that the column doesn't exist for CronTriggerId.

In our current configuration, a Campaign can have a lookup to a Campaign.
Whenever the looked-up Campaign is deleted, the "child" Campaigns need to be deleted as well.

This is done by means of a trigger (see code below).
This trigger only selects and deletes Campaigns related to the "Campaign to be deleted".

When pressing the standard Delete button in Salesforce Classic, the user is redirected to the Campaign listview.
This is the expected behaviour.

When pressing the standard Delete button in Salesforce Lightning, the user is often redirected to a deleted "child" Campaign.
The screen shows an error: Record has been deleted

Is this a Salesforce Lightning issue or related to the Apex trigger?
Any help or suggestions are appreciated.


Apex trigger code:
    // Delete child Campaigns
    if(Trigger.isBefore && Trigger.isDelete) {
        Campaign[] campaigns = [
            SELECT Id
              FROM Campaign
             WHERE RecurringParentCampaign__c IN :Trigger.oldMap.keyset()
               AND Id NOT IN :Trigger.oldMap.keyset()
        ];
        if(!campaigns.isEmpty())
            delete campaigns;
    }

 

Trying to query what ApexClass was used by a CronTrigger by determining what Trigger executed an AsyncApexJob.

The AsyncApexJob shows the Apex Class and if I can query the CronTriggerId that executed that job, I can determine what job was using that Apex Class.

The SOAP API Developer Guide shows that the Metadata for AsyncApexJob has a field for CronTriggerId but when I attempted to query that info, I received an error that the column doesn't exist for CronTriggerId.