function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Samantha Starling 18Samantha Starling 18 

Illegal variable

I'm building a flow that is going to call on a tiny bit of Apex where I need it to delete the Email Campaign record once it's greater than 90 days old. I copied and modified from the original apex replacing quotes with my object. I'm getting error messages for illeglal variables around the salesfusion_web_campaign. Anyone spot what I'm doing wrong?

Here's the article I'm using as a guide: https://automationchampion.com/tag/auto-delete-record-using-process-builder/

ORIGINAL APEX>
public class DeleteUnacceptedQuotes
{
    @InvocableMethod
    public static void QuoteDelete(List<Id> OpportunityIds)
    {
        List<Quote> Quotes =[select id from quote
                          where Opportunity.id in :OpportunityIds
                       and Status != 'Accepted'];
        delete Quotes;
   }
}

MY CUSTOM APEX VERSION 1>
public class DeleteEmailCampaigns
{
   @InvocableMethod
   public static void WebCampaignDelete(List<Id> salesfusion__Web_Campaign__c.Ids)
   {
       List<Web_Campaign__c> Web_Campaign__c =[select id from Web_Campaign__c
                         where salesfusion__Web_Campaign__c.id in :salesfusion__Web_Campaign__c.Ids
                      and Days_Since_Creation__c > 90];
       delete Web_Campaign__c;
  }
}

MY CUSTOM APEX VERSION 2>
public class DeleteEmailCampaigns
{
   @InvocableMethod
   public static void WebCampaignDelete(List<Id> salesfusion__Web_Campaign__cIds)
   {
       List<Web_Campaign__c> Web_Campaign__c =[select id from Web_Campaign__c
                         where salesfusion__Web_Campaign__c.id in :salesfusion__Web_Campaign__cIds
                      and Days_Since_Creation__c > 90];
       delete Web_Campaign__c;
  }
}

bob_buzzardbob_buzzard
Variables with double underscores are illegal syntax in Apex. The solution is to use a human friendly name for your variables, e.g.
 
public class DeleteEmailCampaigns
{
   @InvocableMethod
   public static void WebCampaignDelete(List<Id> webCampaignIds)
   {
       List<Web_Campaign__c> webCampaigns =[select id from Web_Campaign__c
                         where salesfusion__Web_Campaign__c.id in :webCampaignIds
                      and Days_Since_Creation__c > 90];
       delete webCampaigns;
  }
}

 
Samantha StarlingSamantha Starling

Hi Bob...thanks for the update. This is the error message I get when I tried your code above. The Web_Campaign is a custom object included in the Salesfusion app.

Error: Compile Error: sObject type 'Web_Campaign__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. at line 6 column 44User-added image

Samantha StarlingSamantha Starling
I was able to update it to this and it saved successfully! Thanks for putting me on the right track, Bob!

public class DeleteEmailCampaigns
{
   @InvocableMethod
   public static void WebCampaignDelete(List<Id> webCampaignIds)
   {
       List<salesfusion__Web_Campaign__c> webCampaigns =[select id from salesfusion__Web_Campaign__c
                         where salesfusion__Web_Campaign__c.id in :webCampaignIds
                      and Days_Since_Creation__c > 90];
       delete webCampaigns;
  }
}