• Erin Ryan 62
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
I need to tweak the code to any Task that contains the word Pardot will be deleted. I'm not a developer so any assistance will be appreciated. Thanks so much. 

Apex Class
public class TaskDeleteBatch implements Database.Batchable<sObject>{
    public Database.QueryLocator start(Database.BatchableContext bc){
      String query ='select id from task where createdby.Name =\'B2BMA Integration\' AND Subject LIKE \'Pardot List Email%\'';
        return Database.getQueryLocator(query);
    }
    public void execute(Database.BatchableContext bc, list<Task> scope){
        Database.delete(scope);  }
     public void finish(Database.BatchableContext bc)   }}

TaskDeleteBatchTest
@isTest public class TaskDeleteBatchTest {
    @isTest static void testMethod1(){
       Lead l = new lead();
        l.LastName = 'Test';
        l.Company = 'Test Company';
        l.How_did_lead_hear_about_us__c='Email Campaign';
        Insert l;
        
        Profile p = [SELECT Id FROM Profile WHERE Name='B2BMA Integration User']; 

        User u = new User(Alias = 'standt', Email='standarduser@leopardsolutions.com', 
                          EmailEncodingKey='UTF-8', LastName='B2BMA Integration', LanguageLocaleKey='en_US', 
                          LocaleSidKey='en_US', ProfileId = p.Id, 
                          TimeZoneSidKey='America/Los_Angeles', UserName='b2bmaintegration@leopardsolutions.com');
        
        system.runAs(u){
            Task t = new Task();
            t.Subject = 'Pardot List Email';
            t.whoId = l.Id;
            Insert t;   
            
            system.debug([select id,createdBy.Name from task][0].createdBy.Name);
        }
        
        Test.startTest();
          Database.executeBatch(new TaskDeleteBatch());
    Test.stopTest();

    }
}
I need to tweak the code to any Task that contains the word Pardot will be deleted. I'm not a developer so any assistance will be appreciated. Thanks so much. 

Apex Class
public class TaskDeleteBatch implements Database.Batchable<sObject>{
    public Database.QueryLocator start(Database.BatchableContext bc){
      String query ='select id from task where createdby.Name =\'B2BMA Integration\' AND Subject LIKE \'Pardot List Email%\'';
        return Database.getQueryLocator(query);
    }
    public void execute(Database.BatchableContext bc, list<Task> scope){
        Database.delete(scope);  }
     public void finish(Database.BatchableContext bc)   }}

TaskDeleteBatchTest
@isTest public class TaskDeleteBatchTest {
    @isTest static void testMethod1(){
       Lead l = new lead();
        l.LastName = 'Test';
        l.Company = 'Test Company';
        l.How_did_lead_hear_about_us__c='Email Campaign';
        Insert l;
        
        Profile p = [SELECT Id FROM Profile WHERE Name='B2BMA Integration User']; 

        User u = new User(Alias = 'standt', Email='standarduser@leopardsolutions.com', 
                          EmailEncodingKey='UTF-8', LastName='B2BMA Integration', LanguageLocaleKey='en_US', 
                          LocaleSidKey='en_US', ProfileId = p.Id, 
                          TimeZoneSidKey='America/Los_Angeles', UserName='b2bmaintegration@leopardsolutions.com');
        
        system.runAs(u){
            Task t = new Task();
            t.Subject = 'Pardot List Email';
            t.whoId = l.Id;
            Insert t;   
            
            system.debug([select id,createdBy.Name from task][0].createdBy.Name);
        }
        
        Test.startTest();
          Database.executeBatch(new TaskDeleteBatch());
    Test.stopTest();

    }
}