• Pallavi singh
  • NEWBIE
  • 120 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 17
    Questions
  • 37
    Replies
Hi ,
Trying to write the test class for the Opportunity Trigger and OpportunityTriggerHandler

Here is the Opportunity Trigger:

trigger OpportunityTrigger on Opportunity (after update) {
    
    if(Trigger.isAfter && Trigger.isUpdate){
        if(OpportunityTriggerHandler.isFirstTime){
            OpportunityTriggerHandler.isFirstTime=false;
            List<opportunity> opportunityList= new List<opportunity>();
            Map<id,decimal> optyProbabilityMap=new Map<id,decimal>();
            set<id> optyIds=new set<id>();
            for(opportunity opty:Trigger.new){
                if(opty.Probability != trigger.oldMap.get(opty.id).Probability){
                    opportunityList.add(opty);
                    optyIds.add(opty.Id);
                    if(!optyProbabilityMap.containsKey(opty.Id)){
                        optyProbabilityMap.put(opty.Id,opty.Probability);
                    }
                }
            }
            if(!opportunityList.isEmpty()){
                OpportunityTriggerHandler optyTrig=new OpportunityTriggerHandler();
                optyTrig.probabilityUpdate(opportunityList,optyIds,optyProbabilityMap);
            }
        }
    }
}


And here is the OpportunityTriggerHandler class:

public class OpportunityTriggerHandler {
    
    public static Boolean isFirstTime=true;
    
    
    public void probabilityUpdate(List<Opportunity> opportunityList,set<id> optyIds,Map<id,decimal> optyProbabilityMap){
        
        Map<id,OpportunityLineItem> optyProductMap= new Map<id,OpportunityLineItem>([SELECT id,name from OpportunityLineItem where OpportunityId IN :optyIds]);
        
        Map<Id, Opportunity> oppysMap = new Map<Id, Opportunity>([SELECT Id, Probability FROM Opportunity WHERE Id IN :optyIds]);
        
        List<OpportunityLineItemSchedule> optyLnItmSchedList=new List<OpportunityLineItemSchedule>();
        
        for(OpportunityLineItemSchedule eachLnItemSchdle : [SELECT id,Expected_Amount__c,Quantity,OpportunityLineItem.OpportunityId FROM 
                                                            OpportunityLineItemSchedule where OpportunityLineItemId IN: optyProductMap.keyset()]){
            
            Opportunity oppy = oppysMap.get(eachLnItemSchdle.OpportunityLineItem.OpportunityId);
            eachLnItemSchdle.Expected_Amount__c = eachLnItemSchdle.Quantity * (oppy.Probability / 100);                                                                
            optyLnItmSchedList.add(eachLnItemSchdle);                
        }
        
        update optyLnItmSchedList;
    }
}


And this is my Test Class:

@isTest
public class OpportunityTriggerHandlerTest {
    @isTest
    static void testProbabilityUpdate() {
        TestDataFactory factory = new TestDataFactory();

        // Create test Opportunity
        Opportunity opportunity = factory.createOpportunity('Test Opportunity', 'Prospecting', Date.today().addDays(30), 50);
        
        // Create test OpportunityLineItem
        OpportunityLineItem lineItem = factory.createOpportunityLineItem(opportunity, 2);
        
        // Create test OpportunityLineItemSchedule
        OpportunityLineItemSchedule schedule = factory.createOpportunityLineItemSchedule(lineItem, 2);

        // Invoke the method being tested
        OpportunityTriggerHandler handler = new OpportunityTriggerHandler();
        Set<Id> optyIds = new Set<Id>{opportunity.Id};
        Map<Id, Decimal> optyProbabilityMap = new Map<Id, Decimal>{opportunity.Id => opportunity.Probability};
        handler.probabilityUpdate(new List<Opportunity>{opportunity}, optyIds, optyProbabilityMap);
        
        // Retrieve the updated OpportunityLineItemSchedule record
        OpportunityLineItemSchedule updatedSchedule = [SELECT Expected_Amount__c FROM OpportunityLineItemSchedule WHERE Id = :schedule.Id];
        
        // Assert the expected values
        Decimal expectedAmount = schedule.Quantity * (opportunity.Probability / 100);
        System.assertEquals(expectedAmount, updatedSchedule.Expected_Amount__c);
    }
}

i get this dml error "System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: []"
How to solve this 

Thank you in advance
Pallavi
Hi,
Need help to complete the test class 
here is the batch class:

@isTest
private class CreateLeadDLCRecordsBatchTest {
    @isTest
    static void testBatchExecution() {
        // Create test data
        List<Lead> leads = new List<Lead>();
        for (Integer i = 0; i < 10; i++) {
            Lead lead = new Lead();
            lead.FirstName = 'Test';
            lead.LastName = 'Lead ' + i;
            lead.Status = 'Converted';
           // lead.Retention_Date_Reached__c = false;
            leads.add(lead);
        }
        insert leads;

        List<Lead_Status_History__c> leadStatusHistories = new List<Lead_Status_History__c>();
        for (Lead lead : leads) {
            Lead_Status_History__c history = new Lead_Status_History__c();
            history.Lead__c = lead.Id;
            // Set other required fields
            leadStatusHistories.add(history);
        }
        insert leadStatusHistories;

        // Start the batch
        Test.startTest();
        CreateLeadDLCRecordsBatch batch = new CreateLeadDLCRecordsBatch();
        Database.executeBatch(batch);
        Test.stopTest();

        // Verify the results
        Integer expectedDLCRecords = 10;
        Integer actualDLCRecords = [SELECT COUNT() FROM DLC_Control__c];
        System.assertEquals(expectedDLCRecords, actualDLCRecords, 'Incorrect number of DLC_Control__c records created');
       
        Set<Id> expectedLeadStatusHistoryIds = new Set<Id>();
        for (Lead_Status_History__c history : leadStatusHistories) {
            expectedLeadStatusHistoryIds.add(history.Id);
        }
        Set<Id> actualLeadStatusHistoryIds = new Set<Id>();
        for (DLC_Control__c dlc : [SELECT Record_Id__c FROM DLC_Control__c]) {
            actualLeadStatusHistoryIds.add(dlc.Record_Id__c);
        }
       // System.assertEquals(expectedLeadStatusHistoryIds, actualLeadStatusHistoryIds, 'Incorrect Lead_Status_History__c records processed');
    }
 
}
 

and this is my test class which covers 85% but i need 100%.

@isTest
private class CreateLeadDLCRecordsBatchTest {
    @isTest
    static void testBatchExecution() {
        // Create test data
        List<Lead> leads = new List<Lead>();
        for (Integer i = 0; i < 10; i++) {
            Lead lead = new Lead();
            lead.FirstName = 'Test';
            lead.LastName = 'Lead ' + i;
            lead.Status = 'Converted';
           // lead.Retention_Date_Reached__c = false;
            leads.add(lead);
        }
        insert leads;

        List<Lead_Status_History__c> leadStatusHistories = new List<Lead_Status_History__c>();
        for (Lead lead : leads) {
            Lead_Status_History__c history = new Lead_Status_History__c();
            history.Lead__c = lead.Id;
            // Set other required fields
            leadStatusHistories.add(history);
        }
        insert leadStatusHistories;

        // Start the batch
        Test.startTest();
        CreateLeadDLCRecordsBatch batch = new CreateLeadDLCRecordsBatch();
        Database.executeBatch(batch);
        Test.stopTest();

        // Verify the results
        Integer expectedDLCRecords = 10;
        Integer actualDLCRecords = [SELECT COUNT() FROM DLC_Control__c];
        System.assertEquals(expectedDLCRecords, actualDLCRecords, 'Incorrect number of DLC_Control__c records created');
       
        Set<Id> expectedLeadStatusHistoryIds = new Set<Id>();
        for (Lead_Status_History__c history : leadStatusHistories) {
            expectedLeadStatusHistoryIds.add(history.Id);
        }
        Set<Id> actualLeadStatusHistoryIds = new Set<Id>();
        for (DLC_Control__c dlc : [SELECT Record_Id__c FROM DLC_Control__c]) {
            actualLeadStatusHistoryIds.add(dlc.Record_Id__c);
        }
       // System.assertEquals(expectedLeadStatusHistoryIds, actualLeadStatusHistoryIds, 'Incorrect Lead_Status_History__c records processed');
    }
 
}

Thank you in advance
Hi,
 
i have an apex class which converts the currency field into words. But i want to add the Euro and Cent at the end like "One thousand Two hundred Thirty four Euro and Fifty six cent". Here is my Apex class and Trigger.

public with sharing class ConvertCurrencyToWords {
     
        static String[] to_19 = new string[]{ 'zero', 'One',  'Two', 'Three', 'Four',  'Five',  'Six', 'Seven',
                                              'Eight', 'Nine', 'Ten',  'Eleven', 'Twelve', 'Thirteen',  
                                              'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen' };
        static String[] tens = new string[]{ 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety'};
     
        static string[] denom = new string[]{ '',
                                             'Thousand',   'Million',     'Billion',    'trillion',    'quadrillion',  
                                             'quintillion', 's!xtillion',   'septillion',  'octillion',   'nonillion',  
                                             'decillion',  'undecillion',   'duodecillion', 'tredecillion',  'quattuordecillion',  
                                             's!xdecillion', 'septendecillion', 'octodecillion', 'novemdecillion', 'vigintillion' };
    // convert a value < 100 to English.  
   public static string convert_nn(integer val) {
             if (val < 20)
        return to_19[val];
      if (val == 100)
          return 'One Hundred';
      for (integer v = 0; v < tens.size(); v++) {
        String dcap = tens[v];
        integer dval = 20 + 10 * v;
        if (dval + 10 > val) {
          if (Math.Mod(val,10) != 0)
            return dcap + ' ' + to_19[Math.Mod(val,10)];
          return dcap;
        }    
      }
      return 'Should never get here, less than 100 failure';
    }
   
    public static String convert_nnn(integer val) {
      string word = '';
      integer rem = val / 100;
      integer mod = Math.mod(val,100);
      if (rem > 0) {
        word = to_19[rem] + ' Hundred and';
        if (mod > 0) {
          word += ' ';
        }
      }
      if (mod > 0) {
        word += convert_nn(mod);
      }
      return word;
    }
    public static String english_number(long val) {
      if (val < 100) {
        return convert_nn(val.intValue());
      }
      if (val < 1000) {
        return convert_nnn(val.intValue());
      }
      for (integer v = 0; v < denom.size(); v++) {
        integer didx = v - 1;
        integer dval = (integer)Math.pow(1000, v);
        if (dval > val) {
          integer mod = (integer)Math.pow(1000, didx);
          integer l = (integer) val / mod;
          integer r = (integer) val - (l * mod);
          String ret = convert_nnn(l) + ' ' + denom[didx];
          if (r > 0) {
            ret += ', ' + english_number(r);
          }
          return ret;
        }
      }
      return 'Should never get here, bottomed out in english_number';
    }
  }

Trigger:

trigger ConvertCurrencyToWords on Opportunity (before insert, before update) {
    for (Opportunity c : Trigger.new) {
        if (c.PurchasePriceFormula__c != null && c.PurchasePriceFormula__c >= 0) {
         
            Long n = c.PurchasePriceFormula__c.longValue();
            string amo = ConvertCurrencyToWords.english_number(n);
            string amo1 = amo.remove(',');
            c.PurchasePriceWords__c = amo1;
        } else {
            c.PurchasePriceWords__c = null;
        }
    }
    for (Opportunity c : Trigger.new) {
        if (c.TotalPurchasePriceFormula__c != null && c.TotalPurchasePriceFormula__c >= 0) {
         
            Long n = c.TotalPurchasePriceFormula__c.longValue();
            string amo = ConvertCurrencyToWords.english_number(n);
            string amo2 = amo.remove(',');
            c.TotalPurchasePriceWords__c = amo2;
        } else {
            c.TotalPurchasePriceWords__c = null;
        }
    }
}

Thank you in advance
Pallavi
Hi,
I get this errors while quering.

User-added image

public with sharing class DuplicateCasesController {
   
    @AuraEnabled
    public static List<Case> getDuplicateCases(Id recordId) {
        Case currentCase = [SELECT CaseNumber, IncomingEmail__c, Status FROM Case WHERE Id = :recordId];
        String emailSubject = currentCase.IncomingEmail__c;
        String caseNumber = currentCase.CaseNumber;
        String lowerEmailSubject = emailSubject.toLowerCase();
       
        List<Case> duplicateCases = [SELECT CaseNumber, Status, RelatedTo__c
                                     FROM Case
                                     WHERE Id != :recordId
                                     AND ((LOWER(IncomingEmail__c) LIKE :('%'+caseNumber+'%') AND LOWER(IncomingEmail__c) != 'wg')
                                          OR (LOWER(IncomingEmail__c) = 'wg' AND LOWER(CaseNumber) = :caseNumber))];
       
        for (Case duplicateCase : duplicateCases) {
            if (lowerEmailSubject.contains(duplicateCase.CaseNumber.toLowerCase())) {
                duplicateCase.RelatedTo__c = duplicateCase.CaseNumber;
            } else {
                duplicateCase.RelatedTo__c = 'WG';
            }
        }
        return duplicateCases;
    }
   
}

How to solve this errors

Thank you
Pallavi




 
Hi,

This is the trigger

trigger No_Contacts_Not_Related_to_Account on Task (before insert, before update) {
    List<Task> tList = trigger.new;
    List<Id> idList = new List<Id>();
    for(Task t : tList) {
        if(t.whoId != null) idList.add(t.whoId);
    }
    Map<Id, Contact> cMap = new Map<Id, Contact>([select id, accountId from contact where Id in: idList]);

    List<Task> tList_failed = new List<Task>();
    for(Task t : tList) {
        if(t.whoId != null && t.whatId != null && t.whatId != cMap.get(t.whoId).accountId) tList_failed.add(t);
    }

  if(tList_failed.size() > 0) tList[0].addError('Achtung: Ansprechpartner ist nicht beim ausgewählten Debitor hinterlegt ');
}


And here is the Test class but i get this error message "invalid Parameter value" dont know why.

@isTest
Private class No_Contacts_Not_Related_to_Account_Test {

    static testMethod void testTrigger() {
        // Create test Account
        Account acc = new Account(Name = 'Test Account');
        insert acc;

        // Create test Contact related to Account
        Contact con = new Contact(FirstName = 'Test', LastName = 'Contact', AccountId = acc.Id);
        insert con;

        // Create test Contact not related to Account
        Contact con2 = new Contact(FirstName = 'Test2', LastName = 'Contact2');
        insert con2;

        // Create test Tasks with related and not related Contacts
        Task t1 = new Task(Subject = 'Test Task 1', WhoId = con.Id, WhatId = acc.Id);
        Task t2 = new Task(Subject = 'Test Task 2', WhoId = con2.Id, WhatId = acc.Id);

        Test.startTest();
        // Insert Tasks and verify that the trigger throws an error on t2
        try {
            insert new List<Task>{t1, t2};
            System.assert(false, 'Expected error was not thrown');
        } catch (DmlException e) {
            System.assertEquals('Achtung: Ansprechpartner ist nicht beim ausgewählten Debitor hinterlegt ', e.getMessage());
        }
        Test.stopTest();
    }
}

Need help with this test class

Thank you

 
Hi ,

Need help to write the test class 

public with sharing class DuplicateCasesController {
    @AuraEnabled
    public static List<Case> searchForDuplicates(String email, String caseNumber, String origin, String status) {   
        List<Case> duplicateCases = new List<Case>();
        
        // Query for cases with the same email and case number, and same subject if the case number is mentioned
        String caseNumberCondition = String.isBlank(caseNumber) ? '' : ' AND CaseNumber = :caseNumber';
        String origincondition = String.isBlank(origin) ? '' : ' AND Origin = :origin';
        String statuscondition = string.isBlank(status)? '' : ' AND Status = :status';
        string query = 'SELECT CaseNumber, Status,RelatedTo__c,SuppliedEmail FROM Case WHERE SuppliedEmail = ' + email;
        query += caseNumberCondition += origincondition;
       // query += origin;
     //   query += status;
        List<Case> cases = Database.Query(query);
       
        // Add the duplicate cases to the list to be returned
        duplicateCases.addall(cases);
        
        return duplicateCases;
    }
}

Thank you in advance

 
Hi,
I have a customfield 'RelatedTo__C' in Case.
And when Dupliacte case is created need to know where the case number was involved in Email or both in Email and subject and this should update the customfield.

I have tried this but i m unable to complete this code

global class ExampleClass implements Messaging.InboundEmailHandler {
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {

    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
    
  String subject = email.subject;
 
  if(subject.contains(CaseNumber))
  {
      //Custom code to assign to Case which has same Case number
  }

Thank you in advance
Hi,

I have a requirement to update the checkbox "DocumentsApproved__c" 
when both files "Passport' and 'Status Certificate" are uploaded.

And i  was trying to acheive this through Trigger.
Can someone help me i have tried this but its not working.

trigger ContentDocumentLinkTrigger on ContentDocumentLink ( after INSERT, before DELETE ) {
    List<String> linkedEntIds = new List<String>();
    
    for( ContentDocumentLink link : Trigger.new ) {
        linkedEntIds.add( link.LinkedEntityId );
    }
    
    List<ContentDocumentLink> conDocLinks = new   List<ContentDocumentLink>();
    conDocLinks = [
        SELECT  LinkedEntityId
        FROM    ContentDocumentLink
        WHERE   Id IN :Trigger.newMap.keyset()
        AND     LinkedEntity.Type = 'Account' 
        AND     ContentDocument.Title LIKE 'Diplomatic Passport'
        AND     LinkedEntityId IN :linkedEntIds
    ];
    
    if( !conDocLinks.isEmpty() ) {
        List<Account> accToUpdate = new List<Account>();
        
        for( ContentDocumentLink conDocLink : conDocLinks ) {
            Account acc = new Account();
            
            acc.Id  = conDocLink.LinkedEntityId;
            acc.DocumentsApproved__c   = Trigger.isInsert;
            
            accToUpdate.add( acc );
        }
        
        UPDATE accToUpdate;
    }
}
 
Hello,
Need help to write a test class for the apex class.

Thank you in advance

public without sharing class Fileuploadcttrl {
    @AuraEnabled(cacheable=true)
    public static List<ContentVersion> fetchPassportFiles(String recordId){
        List<ContentVersion> documents =new List<ContentVersion>();
        DateTime nowDT=System.now();
        String formatted=nowDT.format('dd_MM_yyyy');
      //  set<id> contentdocIds=new set<id>();
        for(ContentVersion cv : [SELECT Id,ContentDocumentId, Title, CreatedDate, FileType, ContentSize From ContentVersion WHERE FirstPublishLocationId =: recordId]){
                   
            if( cv.Title.contains('Diplomatic Passport') && cv.Title!='')
            {
                cv.Title = cv.title + ' ' + nowDT;
                documents.add(cv);
            }
         //   contentdocIds.add(cv.ContentDocumentId);
        }
     //   updateDocumentTitle(contentdocIds);
        return documents;
    }
//@future
    public static void updateDocumentTitle(set<id> contentdocIds){
        DateTime nowDT=System.now();
        String formatted=nowDT.format('dd_MM_yyyy');
         list<ContentDocument> contDocList=new list<ContentDocument>();
        for (ContentDocument doc:[select id, Title from ContentDocument where id=:contentdocIds]){
                if(doc.Title!=''&& doc.Title!='null'){
                    doc.Title = doc.title + ' ' + nowDT;
                    contDocList.add(doc);    
                }
        }
        update contDocList;
    }

   @AuraEnabled(cacheable=true)
    public static List<ContentVersion> fetchStatusFiles(String recordId){
        List<ContentVersion> documents =new List<ContentVersion>();
        DateTime nowDT=System.now();
        String formatted=nowDT.format('dd_MM_yyyy');
        for(ContentVersion cvs : [SELECT Id, Title, CreatedDate, FileType, ContentSize From ContentVersion WHERE FirstPublishLocationId =: recordId]){
                   
            if( cvs.Title.contains('Status Certificate') && cvs.Title!='')
            {
               cvs.Title = cvs.title + ' ' + nowDT;
                documents.add(cvs);
            }
        }
        return documents;
    }
                     
}
Hi,
I m trying to convert this apex class into a batch and need help.
Thank you in advance
public class CLS_CodetabelleChange {
    
    public void splitupdate(List<Account> AccountListe){
          List<Account>updateListe=new List<Account>();
          List<Account>restListe=new List<Account>();
          if (!AccountListe.isEmpty()){
          for (Integer i = 0; i < AccountListe.size(); i++) {
                if (i < 49999) {
                    updateListe.add(AccountListe.get(i));
                }else{
                    restListe.add(AccountListe.get(i));
                }
              }
              update updateListe;
              splitupdate(restListe);
          }
    }
    
        public void splitupdate(List<Buchungskreis__c> BuchungskreisListe){
          List<Buchungskreis__c>updateListe=new List<Buchungskreis__c>();
          List<Buchungskreis__c>restListe=new List<Buchungskreis__c>();
          if (!BuchungskreisListe.isEmpty()){
          for (Integer i = 0; i < BuchungskreisListe.size(); i++) {
                if (i < 49999) {
                    updateListe.add(BuchungskreisListe.get(i));
                }else{
                    restListe.add(BuchungskreisListe.get(i));
                }
              }
              update updateListe;
              splitupdate(restListe);
          }
    }
    
    public void updatecode1(List<Codetabelle__c> newcode, List<Codetabelle__c> oldcode){
        List<Account>A1=new List<Account>();
        List<Account>A2=new List<Account>();
        List<Account>A3=new List<Account>();
        List<Account>A4=new List<Account>();
        List<Account>A5=new List<Account>();
        List<Account>A6=new List<Account>();
        List<Account>A7=new List<Account>();
        List<Account>A8=new List<Account>();
        List<Account>A9=new List<Account>();
        List<Account>A10=new List<Account>();
        List<Buchungskreis__c>B1=new List<Buchungskreis__c>();
        List<Buchungskreis__c>B2=new List<Buchungskreis__c>();
        
        for (Codetabelle__c c1: newcode){
            for (Codetabelle__c c2: oldcode){
                if (c1.id==c2.id){
                    if(c1.BuchungskreisFormel__c!=c2.BuchungskreisFormel__c)
                    {for (Account acc1:([Select id, BuKr__c from Account where BuKr__c =:c2.BuchungskreisFormel__c]))
                    {Account A11=new Account(id=acc1.id,BuKr__c =c1.BuchungskreisFormel__c);                     
                     A1.add(A11);}}
                    else 
                        if(c1.KontengruppenFormel__c!=c2.KontengruppenFormel__c)
                    {for (Account acc1:([Select id, Kontengr__c from Account where Kontengr__c =:c2.KontengruppenFormel__c]))
                    {Account A21=new Account(id=acc1.id,Kontengr__c =c1.KontengruppenFormel__c);                     
                     A2.add(A21);}}
                    else 
                        if(c1.KundengruppenFormel__c!=c2.KundengruppenFormel__c)
                    {for (Account acc1:([Select id, Kundengrp__c from Account where Kundengrp__c =:c2.KundengruppenFormel__c]))
                    {Account A31=new Account(id=acc1.id,Kundengrp__c =c1.KundengruppenFormel__c);                     
                     A3.add(A31);}}
                    else 
                        if(c1.KundenbezirkeFormel__c!=c2.KundenbezirkeFormel__c)
                    {for (Account acc1:([Select id, Kundenbezirk__c from Account where Kundenbezirk__c =:c2.KundenbezirkeFormel__c]))
                    {Account A41=new Account(id=acc1.id,Kundenbezirk__c =c1.KundenbezirkeFormel__c);                     
                     A4.add(A41);}}
                    else 
                        if(c1.VerkaeufergruppeDebitorFormel__c!=c2.VerkaeufergruppeDebitorFormel__c)
                    {for (Account acc1:([Select id, Verk_uferg__c from Account where Verk_uferg__c =:c2.VerkaeufergruppeDebitorFormel__c]))
                    {Account A51=new Account(id=acc1.id,Verk_uferg__c =c1.VerkaeufergruppeDebitorFormel__c);                     
                     A5.add(A51);}
                     
                     for (Buchungskreis__c Buch1:([Select id, Verk_ufergruppe__c from Buchungskreis__c where Verk_ufergruppe__c =:c2.VerkaeufergruppeDebitorFormel__c]))
                    {Buchungskreis__c B11=new Buchungskreis__c(id=Buch1.id,Verk_ufergruppe__c =c1.VerkaeufergruppeDebitorFormel__c);                     
                     B1.add(B11);}
                    
                    }
                    else 
                        if(c1.VerkaeuferbueroFormel__c!=c2.VerkaeuferbueroFormel__c)
                    {for (Account acc1:([Select id, Verk_Buero__c from Account where Verk_Buero__c =:c2.VerkaeuferbueroFormel__c]))
                    {Account A61=new Account(id=acc1.id,Verk_Buero__c =c1.VerkaeuferbueroFormel__c);                     
                     A6.add(A61);}
                     
                    for (Buchungskreis__c Buch1:([Select id, Verkaufsb_ro__c from Buchungskreis__c where Verkaufsb_ro__c =:c2.VerkaeuferbueroFormel__c]))
                    {Buchungskreis__c B21=new Buchungskreis__c(id=Buch1.id,Verkaufsb_ro__c =c1.VerkaeuferbueroFormel__c);                     
                     B2.add(B21);}}
                    else 
                        if(c1.Laender__c!=c2.Laender__c)
                    {for (Account acc1:([Select id, BillingCountry from Account where BillingCountry =:c2.Laender__c]))
                    {Account A71=new Account(id=acc1.id,BillingCountry =c1.Laender__c);                     
                     A7.add(A71);}}
                    else 
                        if(c1.BranchenschluesselFormel__c!=c2.BranchenschluesselFormel__c)
                    {for (Account acc1:([Select id, Branche_SAP__c from Account where Branche_SAP__c =:c2.BranchenschluesselFormel__c]))
                    {Account A81=new Account(id=acc1.id,Branche_SAP__c =c1.BranchenschluesselFormel__c);                     
                     A8.add(A81);}}
                    else 
                        if(c1.Verkaeufergruppe1Formel__c!=c2.Verkaeufergruppe1Formel__c)
                    {for (Account acc1:([Select id, Verkaeufergruppe1__c, Verkaeufergruppe2__c, LZLD_Gebiet__c,LZLD_Region__c, Regional_Leiter__c, LFB__c from Account where Verkaeufergruppe1__c =:c2.Verkaeufergruppe1Formel__c or Verkaeufergruppe2__c=:c2.Verkaeufergruppe1Formel__c or LZLD_Gebiet__c=:c2.Verkaeufergruppe1Formel__c or LZLD_Region__c=:c2.Verkaeufergruppe1Formel__c or Regional_Leiter__c=:c2.Verkaeufergruppe1Formel__c or LFB__c=:c2.Verkaeufergruppe1Formel__c]))
                    {Account A91=new Account(id=acc1.id);
                     if(acc1.Verkaeufergruppe1__c ==c2.Verkaeufergruppe1Formel__c){A91.Verkaeufergruppe1__c =c1.Verkaeufergruppe1Formel__c; }
                     if(acc1.Verkaeufergruppe2__c ==c2.Verkaeufergruppe1Formel__c){A91.Verkaeufergruppe2__c =c1.Verkaeufergruppe1Formel__c; }
                     if(acc1.LZLD_Gebiet__c ==c2.Verkaeufergruppe1Formel__c){A91.LZLD_Gebiet__c =c1.Verkaeufergruppe1Formel__c; }
                     if(acc1.LZLD_Region__c ==c2.Verkaeufergruppe1Formel__c){A91.LZLD_Region__c =c1.Verkaeufergruppe1Formel__c; }
                     if(acc1.Regional_Leiter__c ==c2.Verkaeufergruppe1Formel__c){A91.Regional_Leiter__c =c1.Verkaeufergruppe1Formel__c; }
                     if(acc1.LFB__c ==c2.Verkaeufergruppe1Formel__c){A91.LFB__c =c1.Verkaeufergruppe1Formel__c; }
                     A9.add(A91);}}
                    else
                        if(c1.Status_Profitcenter__c!=c2.Status_Profitcenter__c)
                    {for (Account acc1:([Select id, Status_Profitcenter__c from Account where Status_Profitcenter__c =:c2.Status_Profitcenter__c]))
                    {Account A111=new Account(id=acc1.id,Status_Profitcenter__c =c1.Status_Profitcenter__c);                     
                     A10.add(A111);}}
                    
                }
            }
        }
        splitupdate(A1);
        splitupdate(A2);
        splitupdate(A3);
        splitupdate(A4);
        splitupdate(A5);
        splitupdate(A6);
        splitupdate(A7);
        splitupdate(A8);
        splitupdate(A9);
        splitupdate(A10);
        splitupdate(B1);
        splitupdate(B2);
        
    }
    
    public void insertcode1(List<Codetabelle__c> newcode){
        List<Account>A1=new List<Account>();
        List<Account>A2=new List<Account>();
        List<Account>A3=new List<Account>();
        List<Account>A4=new List<Account>();
        List<Account>A5=new List<Account>();
        List<Account>A6=new List<Account>();
        List<Account>A7=new List<Account>();
        List<Account>A8=new List<Account>();
        List<Account>A9=new List<Account>();
        List<Account>A10=new List<Account>();
        List<Buchungskreis__c>B1=new List<Buchungskreis__c>();
        List<Buchungskreis__c>B2=new List<Buchungskreis__c>();
        
        for (Codetabelle__c c1: newcode){
            if(c1.BuchungskreisID__c!=null)
            {for (Account acc1:([Select id, BuKr__c from Account where BuKr__c =:c1.BuchungskreisID__c]))
            {Account A11=new Account(id=acc1.id,BuKr__c =c1.BuchungskreisFormel__c);                     
             A1.add(A11);}}
            else 
                if(c1.KontengruppenID__c!=null)
            {for (Account acc1:([Select id, Kontengr__c from Account where Kontengr__c =:c1.KontengruppenID__c]))
            {Account A21=new Account(id=acc1.id,Kontengr__c =c1.KontengruppenFormel__c);                     
             A2.add(A21);}}
            else 
                if(c1.KundengruppenID__c!=null)
            {for (Account acc1:([Select id, Kundengrp__c from Account where Kundengrp__c =:c1.KundengruppenID__c]))
            {Account A31=new Account(id=acc1.id,Kundengrp__c =c1.KundengruppenFormel__c);                     
             A3.add(A31);}}
            else 
                if(c1.KundenbezirkeID__c!=null)
            {for (Account acc1:([Select id, Kundenbezirk__c from Account where Kundenbezirk__c =:c1.KundenbezirkeID__c]))
            {Account A41=new Account(id=acc1.id,Kundenbezirk__c =c1.KundenbezirkeFormel__c);                     
             A4.add(A41);}}
            else 
                if(c1.VerkaeufergruppeDebitorID__c!=null)
            {for (Account acc1:([Select id, Verk_uferg__c from Account where Verk_uferg__c =:c1.VerkaeufergruppeDebitorID__c]))
            {Account A51=new Account(id=acc1.id,Verk_uferg__c =c1.VerkaeufergruppeDebitorFormel__c);                     
             A5.add(A51);}
             
            for (Buchungskreis__c Buch1:([Select id, Verk_ufergruppe__c from Buchungskreis__c where Verk_ufergruppe__c =:c1.VerkaeufergruppeDebitorID__c]))
            {Buchungskreis__c B11=new Buchungskreis__c(id=Buch1.id,Verk_ufergruppe__c =c1.VerkaeufergruppeDebitorFormel__c);                     
             B1.add(B11);}}
            else 
                if(c1.VerkaeuferbueroID__c!=null)
            {for (Account acc1:([Select id, Verk_Buero__c from Account where Verk_Buero__c =:c1.VerkaeuferbueroID__c]))
            {Account A61=new Account(id=acc1.id,Verk_Buero__c =c1.VerkaeuferbueroFormel__c);                     
             A6.add(A61);}
            
            for (Buchungskreis__c Buch1:([Select id, Verkaufsb_ro__c from Buchungskreis__c where Verkaufsb_ro__c =:c1.VerkaeuferbueroID__c]))
            {Buchungskreis__c B21=new Buchungskreis__c(id=Buch1.id,Verkaufsb_ro__c =c1.VerkaeuferbueroFormel__c);                     
             B2.add(B21);}}
            else 
                if(c1.Laendercode__c!=null)
            {for (Account acc1:([Select id, BillingCountry from Account where BillingCountry =:c1.Laendercode__c]))
            {Account A71=new Account(id=acc1.id,BillingCountry =c1.Laender__c);                     
             A7.add(A71);}}
            else 
                if(c1.BranchenschluesselID__c!=null)
            {for (Account acc1:([Select id, Branche_SAP__c from Account where Branche_SAP__c =:c1.BranchenschluesselID__c]))
            {Account A81=new Account(id=acc1.id,Branche_SAP__c =c1.BranchenschluesselFormel__c);                     
             A8.add(A81);}}
            else 
                if(c1.Verkaeufergruppe1ID__c!=null)
            {for (Account acc1:([Select id, Verkaeufergruppe1__c, Verkaeufergruppe2__c, LZLD_Gebiet__c,LZLD_Region__c, Regional_Leiter__c, LFB__c from Account where Verkaeufergruppe1__c =:c1.Verkaeufergruppe1ID__c or Verkaeufergruppe2__c=:c1.Verkaeufergruppe1ID__c or LZLD_Gebiet__c=:c1.Verkaeufergruppe1ID__c or LZLD_Region__c=:c1.Verkaeufergruppe1ID__c or Regional_Leiter__c=:c1.Verkaeufergruppe1ID__c or LFB__c=:c1.Verkaeufergruppe1ID__c]))
            {Account A91=new Account(id=acc1.id);
             if(acc1.Verkaeufergruppe1__c ==c1.Verkaeufergruppe1ID__c){acc1.Verkaeufergruppe1__c =c1.Verkaeufergruppe1Formel__c; }
             if(acc1.Verkaeufergruppe2__c ==c1.Verkaeufergruppe1ID__c){acc1.Verkaeufergruppe2__c =c1.Verkaeufergruppe1Formel__c; }
             if(acc1.LZLD_Gebiet__c ==c1.Verkaeufergruppe1ID__c){acc1.LZLD_Gebiet__c =c1.Verkaeufergruppe1Formel__c; }
             if(acc1.LZLD_Region__c ==c1.Verkaeufergruppe1ID__c){acc1.LZLD_Region__c =c1.Verkaeufergruppe1Formel__c; }
             if(acc1.Regional_Leiter__c ==c1.Verkaeufergruppe1ID__c){acc1.Regional_Leiter__c =c1.Verkaeufergruppe1Formel__c; }
             if(acc1.LFB__c ==c1.Verkaeufergruppe1ID__c){acc1.LFB__c =c1.Verkaeufergruppe1Formel__c; }
             A9.add(A91);}}
            else
                if(c1.Status_Profitcenter_ID__c!=null)
            {for (Account acc1:([Select id, Status_Profitcenter__c from Account where Status_Profitcenter__c =:c1.Status_Profitcenter_ID__c]))
            {Account A111=new Account(id=acc1.id,Status_Profitcenter__c =c1.Status_Profitcenter__c);                     
             A10.add(A111);}}      
        }
        
        splitupdate(A1);
        splitupdate(A2);
        splitupdate(A3);
        splitupdate(A4);
        splitupdate(A5);
        splitupdate(A6);
        splitupdate(A7);
        splitupdate(A8);
        splitupdate(A9);
        splitupdate(A10);
        splitupdate(B1);
        splitupdate(B2);
        
    }
  
}
Can we acheive this through lightning component to show the duplicate cases on the bases of Email, Casenumber and in subject if casenumber is mentioned.
Something like this.

User-added image
Thank you in advance
Hi,
Need help to write the test class for the following controller.

public with sharing class TrainingEventParticipantController {
    @AuraEnabled
    public  static List<TrainingEventParticipant__c> getparticipant(String eventid) {
        return [select id, name, AccountName__c, ContactId__r.Name, ContactId__c, SupervisorContactId__c, Status__c, Role__c,
                 CancelRequest__c from TrainingEventParticipant__c where TrainingEventId__c=:eventid];
    }
    @AuraEnabled
    public static String saveparticipant(List<TrainingEventParticipant__c> events) {
        try {
            Database.update(events, true);
            return LABEL.SuccessMessageTitle;
        }  catch (Exception e) {
            String errormsgCPA =  String.valueOf(e.getMessage());
            return errormsgCPA;
        }
    }
}

Thank you in advance
Shruthi
global class GDPRAnonymizationBatch Implements Database.batchable<sobject>{
     global final string query;
     global GDPRAnonymizationBatch(string q){
                   
          query=q;
     }
   
     global Database.QueryLocator start(Database.BatchableContext BC){
     //TODO: Bitte Query hier direkt anlegen und nicht per Konstruktor definieren
     //TODO: Konstruktor löschen
     return Database.getQueryLocator('SELECT Id,IsPersonAccount, Name ,PersonEmail from Account WHERE IsPersonAccount=True and MarkedForDeletion__c = true');
  }
                                     
     global  void execute(Database.BatchableContext BC,List<SObject> scope){
     
     for(Account acc: (List<Account>)scope){
          GDPRAnonymizationHelper helper=new GDPRAnonymizationHelper();
         
          //TODO: Es fehlen Aufrufe zu Methoden, z.B. für TasksAndActivities
          helper.AnonymizaAccountActivitiesAndTasks(acc.id);
          helper.AnonymizaRelatedVehicles(acc.id);
          helper.AnonymizaRelatedJobs(acc.id);
          helper.AnonymizaAccountFields(acc.id);          
          }
         
          //TODO: Accounts sollten nicht gelöscht werden
          Update scope;
   
    }
    global void finish(Database.BatchableContext BC){
     
       
    }
 }


And this the handler class for the above batch job

public with sharing class GDPRAnonymizationHelper {
    public void AnonymizaAccountFields(Id accountId) {
        Account anonymizaAcc= new Account(id=accountId);//[SELECT id from Account where id=:accountId];
        anonymizaAcc.Name= null;
        anonymizaAcc.Comment__c= null;
        anonymizaAcc.Car_Owner_Name__c= null;
        anonymizaAcc.Car_Owner_Address__c= null;
        anonymizaAcc.Test_Criteria_Matches_Vehicle__c= null;
        anonymizaAcc.Shipping_Additional_Information__c= null;
       // anonymizaAcc.BillingAddress= '';
        anonymizaAcc.Phone= null;
        anonymizaAcc.Phone_2__c= null;
        anonymizaAcc.PersonMobilePhone= null;
        anonymizaAcc.PersonMobilePhone2__c= null;
        anonymizaAcc.PersonEmail= null;
        update anonymizaAcc;
    }
    public void AnonymizaAccountActivitiesAndTasks(Id accountId) {
        //TODO: Keine Implementierung für diese Methode - die Methode wird auch nirgends aufgerufen
    }
    public void AnonymizaRelatedVehicles(Id accountId) {
       
        List<Vehicle__c> lstVehicles =new List<Vehicle__c>();
        for(Vehicle__c  anonymizaveh: [SELECT id,Account__c from Vehicle__c where Account__c=:accountId ]){
            anonymizaveh.VIN__c= null;          
            anonymizaveh.Special_Remarks__c= null;
            anonymizaveh.Comment_on_blocked_vehicle__c= null;
            anonymizaveh.Different_Owner_First_Name__c= null;
            anonymizaveh.Different_Owner_Last_Name__c= null;
            anonymizaveh.Different_Owner_Street__c= null;
            anonymizaveh.Different_Owner_ZIP_Code__c= null;
            anonymizaveh.Different_Owner_Email__c= null;
            anonymizaveh.Different_Owner_State_Province__c= null;
            lstVehicles.add(anonymizaveh);
        }
        //TODO: Fahrzeuge sollten nicht gelöscht sondern upgedated werden
        Database.Update(lstVehicles, false);
       
    }
    public void AnonymizaRelatedJobs(Id accountId) {
        List<Job__c> listjob =new List<Job__c>();
        for(Job__c  anonymizajob: [SELECT id,Account_Information__c from Job__c where Account_Information__c=:accountId ]){
            //  anonymizajob.Test_Customer_Id__c= '';
            //  anonymizajob.Vehicle_VIN__c= '';
            anonymizajob.All_neccessary_files_attached__c= null;
            anonymizajob.Comments_Up_to_Date_and_Appropriate__c= null;
            listjob.add(anonymizajob);
        }
        //TODO: Jobs sollten nicht gelöscht sondern upgedated werden
        Database.Update(listjob, false);
    }
   
}

i m tried this but i can achieve only 38% which is very less
How can i write the query here directly by deleting the constructor.


global class GDPRAnonymizationBatch Implements Database.batchable<sobject>{
     global final string query;
     global GDPRAnonymizationBatch(string q){
         
          
          query=q;
     }
   
     global Database.QueryLocator start(Database.BatchableContext BC){

     //TODO: Please create query here directly and do not define it by constructor and delete contructor

     return Database.getQueryLocator(query);
     }
     global  void execute(Database.BatchableContext BC,List<SObject> scope){
     
     for(Account acc: (List<Account>)scope){
          GDPRAnonymizationHelper helper=new GDPRAnonymizationHelper();
          
          //TODO: Es fehlen Aufrufe zu Methoden, z.B. für TasksAndActivities
          helper.AnonymizaRelatedVehicles(acc.id);
          helper.AnonymizaRelatedJobs(acc.id);
          helper.AnonymizaAccountFields(acc.id);          
          }
         
          //TODO: Accounts should not be deleted
          Update scope;
    
    }
    global void finish(Database.BatchableContext BC){
    
      
    }

 }




And this is the query i need to add to this batch job and here the Batch Helper class as well.
public with sharing class GDPRAnonymizationHelper {

    public void AnonymizaAccountFields(Id accountId) {
        Account anonymizaAcc= new Account(id=accountId);//[SELECT id from Account where id=:accountId];
        anonymizaAcc.Name= null;
        anonymizaAcc.Comment__c= null;
        anonymizaAcc.Car_Owner_Name__c= null;
        anonymizaAcc.Car_Owner_Address__c= null;
        anonymizaAcc.Test_Criteria_Matches_Vehicle__c= null;
        anonymizaAcc.Shipping_Additional_Information__c= null;
       // anonymizaAcc.BillingAddress= '';
        anonymizaAcc.Phone= null;
        anonymizaAcc.Phone_2__c= null;
        anonymizaAcc.PersonMobilePhone= null;
        anonymizaAcc.PersonMobilePhone2__c= null;
        anonymizaAcc.PersonEmail= null;

        update anonymizaAcc;
    }

    public void AnonymizaAccountActivitiesAndTasks(Id accountId) {
        //TODO: Keine Implementierung für diese Methode - die Methode wird auch nirgends aufgerufen
    }

    public void AnonymizaRelatedVehicles(Id accountId) {
        
        List<Vehicle__c> lstVehicles =new List<Vehicle__c>();
        for(Vehicle__c  anonymizaveh: [SELECT id,Account__c from Vehicle__c where Account__c=:accountId ]){
            anonymizaveh.VIN__c= null;          
            anonymizaveh.Special_Remarks__c= null;
            anonymizaveh.Comment_on_blocked_vehicle__c= null;
            anonymizaveh.Different_Owner_First_Name__c= null;
            anonymizaveh.Different_Owner_Last_Name__c= null;
            anonymizaveh.Different_Owner_Street__c= null;
            anonymizaveh.Different_Owner_ZIP_Code__c= null;
            anonymizaveh.Different_Owner_Email__c= null;
            anonymizaveh.Different_Owner_State_Province__c= null;
            lstVehicles.add(anonymizaveh);
        }
        //TODO: Fahrzeuge sollten nicht gelöscht sondern upgedated werden
        Database.update(lstVehicles, false);
        
    }

    public void AnonymizaRelatedJobs(Id accountId) {
        List<Job__c> listjob =new List<Job__c>();
        for(Job__c  anonymizajob: [SELECT id,Account_Information__c from Job__c where Account_Information__c=:accountId ]){
            //  anonymizajob.Test_Customer_Id__c= '';
            //  anonymizajob.Vehicle_VIN__c= '';
            anonymizajob.All_neccessary_files_attached__c= null;
            anonymizajob.Comments_Up_to_Date_and_Appropriate__c= null;
            listjob.add(anonymizajob);
        } 
        //TODO: Jobs sollten nicht gelöscht sondern upgedated werden
        Database.Update(listjob, false);
    }
    

}


And this should be the query
SELECT Id FROM Account WHERE MarkedForDeletion__c = true OR Opt_In_Confirmed__c < LAST_5_YEARS
 
I have a schedule batch job to send reminder mail 
Here is the batch job.

global class SendReminderEmail implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext BC){
      return Database.getQueryLocator('SELECT Id,IsPersonAccount = true, Name ,PersonEmail from Account WHERE MarkedForDeletion__c = true OR Opt_In_Confirmed__c < LAST_5_YEARS');
     }
    global void execute(Database.BatchableContext BC,List<SObject> scope) {
     List<Account> accountList =  (List<Account>)scope;
     
     EmailTemplate et = [SELECT id FROM EmailTemplate WHERE developerName = 'Opt-In Anfordern'];
     List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
            for(Account acc : accountList){
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                    mail.setTemplateId(et.Id);
                    //mail.setToAddresses(acc.PersonEmail);
                    mail.setToAddresses(new List<String>{'shruthi.jeevangikar@abilex.de'});
                    mail.setSubject(et.subject);
                    mail.setHTMLBody(et.Body);
                    //mail.setTargetObjectId(primaryContact);
                    mail.setWhatId(acc.Id);
                    mail.setSaveAsActivity(true);
                    mail.setUseSignature(true);
                    mails.add(mail);
    }
       
       Messaging.sendEmail(mails);
  }
 
  global void finish(Database.BatchableContext BC){
  }
}    
======
For this i started writting the test class like this :

@istest
global class SendReminderEmailTest{
    public static testmethod void sendreminderemailTest(){
      
        Id templateId = [SELECT id, Name FRom EmailTemplate WHERE developername ='Opt-In Anfordern'].id;
        Account acct = new Account();
        acct.FirstName = 'Test';
        acct.LastName = 'LastName';
        acct.PersonEmail = 'test@test.com';
        
        insert acct;
        
               
        
    }
        
}

can someone guide me further 
global class GDPRAnonymizationBatch Implements Database.batchable<sobject>{
     global final string query;
     global GDPRAnonymizationBatch(string q){
         
          query=q;
     }
   
     global Database.QueryLocator start(Database.BatchableContext BC){

      return Database.getQueryLocator(query);
     }
     global  void execute(Database.BatchableContext BC,List<SObject> scope){
     
     
         for(Account acc: (List<Account>)scope){
         GDPRAnonymizationHelper helper=new GDPRAnonymizationHelper();
         
           helper.AnonymizaRelatedVehicles(acc.id);
           helper.AnonymizaRelatedJobs(acc.id);
         helper.AnonymizaAccountFields(acc.id);
         }
         
         delete scope;
    
    }
    global void finish(Database.BatchableContext BC){
    
      
    }

 }
Hi 
i want to include this error info into my test class now my test class is covring 91% but i need 100% coverage.

for(Database.Error error : errors) {
                errorStrings = errorStrings + ' ' + error.getMessage();
            }
        }
        return errorStrings;
    }
Hi,

This is the trigger

trigger No_Contacts_Not_Related_to_Account on Task (before insert, before update) {
    List<Task> tList = trigger.new;
    List<Id> idList = new List<Id>();
    for(Task t : tList) {
        if(t.whoId != null) idList.add(t.whoId);
    }
    Map<Id, Contact> cMap = new Map<Id, Contact>([select id, accountId from contact where Id in: idList]);

    List<Task> tList_failed = new List<Task>();
    for(Task t : tList) {
        if(t.whoId != null && t.whatId != null && t.whatId != cMap.get(t.whoId).accountId) tList_failed.add(t);
    }

  if(tList_failed.size() > 0) tList[0].addError('Achtung: Ansprechpartner ist nicht beim ausgewählten Debitor hinterlegt ');
}


And here is the Test class but i get this error message "invalid Parameter value" dont know why.

@isTest
Private class No_Contacts_Not_Related_to_Account_Test {

    static testMethod void testTrigger() {
        // Create test Account
        Account acc = new Account(Name = 'Test Account');
        insert acc;

        // Create test Contact related to Account
        Contact con = new Contact(FirstName = 'Test', LastName = 'Contact', AccountId = acc.Id);
        insert con;

        // Create test Contact not related to Account
        Contact con2 = new Contact(FirstName = 'Test2', LastName = 'Contact2');
        insert con2;

        // Create test Tasks with related and not related Contacts
        Task t1 = new Task(Subject = 'Test Task 1', WhoId = con.Id, WhatId = acc.Id);
        Task t2 = new Task(Subject = 'Test Task 2', WhoId = con2.Id, WhatId = acc.Id);

        Test.startTest();
        // Insert Tasks and verify that the trigger throws an error on t2
        try {
            insert new List<Task>{t1, t2};
            System.assert(false, 'Expected error was not thrown');
        } catch (DmlException e) {
            System.assertEquals('Achtung: Ansprechpartner ist nicht beim ausgewählten Debitor hinterlegt ', e.getMessage());
        }
        Test.stopTest();
    }
}

Need help with this test class

Thank you

 
Hi ,

Need help to write the test class 

public with sharing class DuplicateCasesController {
    @AuraEnabled
    public static List<Case> searchForDuplicates(String email, String caseNumber, String origin, String status) {   
        List<Case> duplicateCases = new List<Case>();
        
        // Query for cases with the same email and case number, and same subject if the case number is mentioned
        String caseNumberCondition = String.isBlank(caseNumber) ? '' : ' AND CaseNumber = :caseNumber';
        String origincondition = String.isBlank(origin) ? '' : ' AND Origin = :origin';
        String statuscondition = string.isBlank(status)? '' : ' AND Status = :status';
        string query = 'SELECT CaseNumber, Status,RelatedTo__c,SuppliedEmail FROM Case WHERE SuppliedEmail = ' + email;
        query += caseNumberCondition += origincondition;
       // query += origin;
     //   query += status;
        List<Case> cases = Database.Query(query);
       
        // Add the duplicate cases to the list to be returned
        duplicateCases.addall(cases);
        
        return duplicateCases;
    }
}

Thank you in advance

 
Hi,
I have a customfield 'RelatedTo__C' in Case.
And when Dupliacte case is created need to know where the case number was involved in Email or both in Email and subject and this should update the customfield.

I have tried this but i m unable to complete this code

global class ExampleClass implements Messaging.InboundEmailHandler {
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {

    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
    
  String subject = email.subject;
 
  if(subject.contains(CaseNumber))
  {
      //Custom code to assign to Case which has same Case number
  }

Thank you in advance
Hi,

I have a requirement to update the checkbox "DocumentsApproved__c" 
when both files "Passport' and 'Status Certificate" are uploaded.

And i  was trying to acheive this through Trigger.
Can someone help me i have tried this but its not working.

trigger ContentDocumentLinkTrigger on ContentDocumentLink ( after INSERT, before DELETE ) {
    List<String> linkedEntIds = new List<String>();
    
    for( ContentDocumentLink link : Trigger.new ) {
        linkedEntIds.add( link.LinkedEntityId );
    }
    
    List<ContentDocumentLink> conDocLinks = new   List<ContentDocumentLink>();
    conDocLinks = [
        SELECT  LinkedEntityId
        FROM    ContentDocumentLink
        WHERE   Id IN :Trigger.newMap.keyset()
        AND     LinkedEntity.Type = 'Account' 
        AND     ContentDocument.Title LIKE 'Diplomatic Passport'
        AND     LinkedEntityId IN :linkedEntIds
    ];
    
    if( !conDocLinks.isEmpty() ) {
        List<Account> accToUpdate = new List<Account>();
        
        for( ContentDocumentLink conDocLink : conDocLinks ) {
            Account acc = new Account();
            
            acc.Id  = conDocLink.LinkedEntityId;
            acc.DocumentsApproved__c   = Trigger.isInsert;
            
            accToUpdate.add( acc );
        }
        
        UPDATE accToUpdate;
    }
}
 
Hello,
Need help to write a test class for the apex class.

Thank you in advance

public without sharing class Fileuploadcttrl {
    @AuraEnabled(cacheable=true)
    public static List<ContentVersion> fetchPassportFiles(String recordId){
        List<ContentVersion> documents =new List<ContentVersion>();
        DateTime nowDT=System.now();
        String formatted=nowDT.format('dd_MM_yyyy');
      //  set<id> contentdocIds=new set<id>();
        for(ContentVersion cv : [SELECT Id,ContentDocumentId, Title, CreatedDate, FileType, ContentSize From ContentVersion WHERE FirstPublishLocationId =: recordId]){
                   
            if( cv.Title.contains('Diplomatic Passport') && cv.Title!='')
            {
                cv.Title = cv.title + ' ' + nowDT;
                documents.add(cv);
            }
         //   contentdocIds.add(cv.ContentDocumentId);
        }
     //   updateDocumentTitle(contentdocIds);
        return documents;
    }
//@future
    public static void updateDocumentTitle(set<id> contentdocIds){
        DateTime nowDT=System.now();
        String formatted=nowDT.format('dd_MM_yyyy');
         list<ContentDocument> contDocList=new list<ContentDocument>();
        for (ContentDocument doc:[select id, Title from ContentDocument where id=:contentdocIds]){
                if(doc.Title!=''&& doc.Title!='null'){
                    doc.Title = doc.title + ' ' + nowDT;
                    contDocList.add(doc);    
                }
        }
        update contDocList;
    }

   @AuraEnabled(cacheable=true)
    public static List<ContentVersion> fetchStatusFiles(String recordId){
        List<ContentVersion> documents =new List<ContentVersion>();
        DateTime nowDT=System.now();
        String formatted=nowDT.format('dd_MM_yyyy');
        for(ContentVersion cvs : [SELECT Id, Title, CreatedDate, FileType, ContentSize From ContentVersion WHERE FirstPublishLocationId =: recordId]){
                   
            if( cvs.Title.contains('Status Certificate') && cvs.Title!='')
            {
               cvs.Title = cvs.title + ' ' + nowDT;
                documents.add(cvs);
            }
        }
        return documents;
    }
                     
}
Hi,
I m trying to convert this apex class into a batch and need help.
Thank you in advance
public class CLS_CodetabelleChange {
    
    public void splitupdate(List<Account> AccountListe){
          List<Account>updateListe=new List<Account>();
          List<Account>restListe=new List<Account>();
          if (!AccountListe.isEmpty()){
          for (Integer i = 0; i < AccountListe.size(); i++) {
                if (i < 49999) {
                    updateListe.add(AccountListe.get(i));
                }else{
                    restListe.add(AccountListe.get(i));
                }
              }
              update updateListe;
              splitupdate(restListe);
          }
    }
    
        public void splitupdate(List<Buchungskreis__c> BuchungskreisListe){
          List<Buchungskreis__c>updateListe=new List<Buchungskreis__c>();
          List<Buchungskreis__c>restListe=new List<Buchungskreis__c>();
          if (!BuchungskreisListe.isEmpty()){
          for (Integer i = 0; i < BuchungskreisListe.size(); i++) {
                if (i < 49999) {
                    updateListe.add(BuchungskreisListe.get(i));
                }else{
                    restListe.add(BuchungskreisListe.get(i));
                }
              }
              update updateListe;
              splitupdate(restListe);
          }
    }
    
    public void updatecode1(List<Codetabelle__c> newcode, List<Codetabelle__c> oldcode){
        List<Account>A1=new List<Account>();
        List<Account>A2=new List<Account>();
        List<Account>A3=new List<Account>();
        List<Account>A4=new List<Account>();
        List<Account>A5=new List<Account>();
        List<Account>A6=new List<Account>();
        List<Account>A7=new List<Account>();
        List<Account>A8=new List<Account>();
        List<Account>A9=new List<Account>();
        List<Account>A10=new List<Account>();
        List<Buchungskreis__c>B1=new List<Buchungskreis__c>();
        List<Buchungskreis__c>B2=new List<Buchungskreis__c>();
        
        for (Codetabelle__c c1: newcode){
            for (Codetabelle__c c2: oldcode){
                if (c1.id==c2.id){
                    if(c1.BuchungskreisFormel__c!=c2.BuchungskreisFormel__c)
                    {for (Account acc1:([Select id, BuKr__c from Account where BuKr__c =:c2.BuchungskreisFormel__c]))
                    {Account A11=new Account(id=acc1.id,BuKr__c =c1.BuchungskreisFormel__c);                     
                     A1.add(A11);}}
                    else 
                        if(c1.KontengruppenFormel__c!=c2.KontengruppenFormel__c)
                    {for (Account acc1:([Select id, Kontengr__c from Account where Kontengr__c =:c2.KontengruppenFormel__c]))
                    {Account A21=new Account(id=acc1.id,Kontengr__c =c1.KontengruppenFormel__c);                     
                     A2.add(A21);}}
                    else 
                        if(c1.KundengruppenFormel__c!=c2.KundengruppenFormel__c)
                    {for (Account acc1:([Select id, Kundengrp__c from Account where Kundengrp__c =:c2.KundengruppenFormel__c]))
                    {Account A31=new Account(id=acc1.id,Kundengrp__c =c1.KundengruppenFormel__c);                     
                     A3.add(A31);}}
                    else 
                        if(c1.KundenbezirkeFormel__c!=c2.KundenbezirkeFormel__c)
                    {for (Account acc1:([Select id, Kundenbezirk__c from Account where Kundenbezirk__c =:c2.KundenbezirkeFormel__c]))
                    {Account A41=new Account(id=acc1.id,Kundenbezirk__c =c1.KundenbezirkeFormel__c);                     
                     A4.add(A41);}}
                    else 
                        if(c1.VerkaeufergruppeDebitorFormel__c!=c2.VerkaeufergruppeDebitorFormel__c)
                    {for (Account acc1:([Select id, Verk_uferg__c from Account where Verk_uferg__c =:c2.VerkaeufergruppeDebitorFormel__c]))
                    {Account A51=new Account(id=acc1.id,Verk_uferg__c =c1.VerkaeufergruppeDebitorFormel__c);                     
                     A5.add(A51);}
                     
                     for (Buchungskreis__c Buch1:([Select id, Verk_ufergruppe__c from Buchungskreis__c where Verk_ufergruppe__c =:c2.VerkaeufergruppeDebitorFormel__c]))
                    {Buchungskreis__c B11=new Buchungskreis__c(id=Buch1.id,Verk_ufergruppe__c =c1.VerkaeufergruppeDebitorFormel__c);                     
                     B1.add(B11);}
                    
                    }
                    else 
                        if(c1.VerkaeuferbueroFormel__c!=c2.VerkaeuferbueroFormel__c)
                    {for (Account acc1:([Select id, Verk_Buero__c from Account where Verk_Buero__c =:c2.VerkaeuferbueroFormel__c]))
                    {Account A61=new Account(id=acc1.id,Verk_Buero__c =c1.VerkaeuferbueroFormel__c);                     
                     A6.add(A61);}
                     
                    for (Buchungskreis__c Buch1:([Select id, Verkaufsb_ro__c from Buchungskreis__c where Verkaufsb_ro__c =:c2.VerkaeuferbueroFormel__c]))
                    {Buchungskreis__c B21=new Buchungskreis__c(id=Buch1.id,Verkaufsb_ro__c =c1.VerkaeuferbueroFormel__c);                     
                     B2.add(B21);}}
                    else 
                        if(c1.Laender__c!=c2.Laender__c)
                    {for (Account acc1:([Select id, BillingCountry from Account where BillingCountry =:c2.Laender__c]))
                    {Account A71=new Account(id=acc1.id,BillingCountry =c1.Laender__c);                     
                     A7.add(A71);}}
                    else 
                        if(c1.BranchenschluesselFormel__c!=c2.BranchenschluesselFormel__c)
                    {for (Account acc1:([Select id, Branche_SAP__c from Account where Branche_SAP__c =:c2.BranchenschluesselFormel__c]))
                    {Account A81=new Account(id=acc1.id,Branche_SAP__c =c1.BranchenschluesselFormel__c);                     
                     A8.add(A81);}}
                    else 
                        if(c1.Verkaeufergruppe1Formel__c!=c2.Verkaeufergruppe1Formel__c)
                    {for (Account acc1:([Select id, Verkaeufergruppe1__c, Verkaeufergruppe2__c, LZLD_Gebiet__c,LZLD_Region__c, Regional_Leiter__c, LFB__c from Account where Verkaeufergruppe1__c =:c2.Verkaeufergruppe1Formel__c or Verkaeufergruppe2__c=:c2.Verkaeufergruppe1Formel__c or LZLD_Gebiet__c=:c2.Verkaeufergruppe1Formel__c or LZLD_Region__c=:c2.Verkaeufergruppe1Formel__c or Regional_Leiter__c=:c2.Verkaeufergruppe1Formel__c or LFB__c=:c2.Verkaeufergruppe1Formel__c]))
                    {Account A91=new Account(id=acc1.id);
                     if(acc1.Verkaeufergruppe1__c ==c2.Verkaeufergruppe1Formel__c){A91.Verkaeufergruppe1__c =c1.Verkaeufergruppe1Formel__c; }
                     if(acc1.Verkaeufergruppe2__c ==c2.Verkaeufergruppe1Formel__c){A91.Verkaeufergruppe2__c =c1.Verkaeufergruppe1Formel__c; }
                     if(acc1.LZLD_Gebiet__c ==c2.Verkaeufergruppe1Formel__c){A91.LZLD_Gebiet__c =c1.Verkaeufergruppe1Formel__c; }
                     if(acc1.LZLD_Region__c ==c2.Verkaeufergruppe1Formel__c){A91.LZLD_Region__c =c1.Verkaeufergruppe1Formel__c; }
                     if(acc1.Regional_Leiter__c ==c2.Verkaeufergruppe1Formel__c){A91.Regional_Leiter__c =c1.Verkaeufergruppe1Formel__c; }
                     if(acc1.LFB__c ==c2.Verkaeufergruppe1Formel__c){A91.LFB__c =c1.Verkaeufergruppe1Formel__c; }
                     A9.add(A91);}}
                    else
                        if(c1.Status_Profitcenter__c!=c2.Status_Profitcenter__c)
                    {for (Account acc1:([Select id, Status_Profitcenter__c from Account where Status_Profitcenter__c =:c2.Status_Profitcenter__c]))
                    {Account A111=new Account(id=acc1.id,Status_Profitcenter__c =c1.Status_Profitcenter__c);                     
                     A10.add(A111);}}
                    
                }
            }
        }
        splitupdate(A1);
        splitupdate(A2);
        splitupdate(A3);
        splitupdate(A4);
        splitupdate(A5);
        splitupdate(A6);
        splitupdate(A7);
        splitupdate(A8);
        splitupdate(A9);
        splitupdate(A10);
        splitupdate(B1);
        splitupdate(B2);
        
    }
    
    public void insertcode1(List<Codetabelle__c> newcode){
        List<Account>A1=new List<Account>();
        List<Account>A2=new List<Account>();
        List<Account>A3=new List<Account>();
        List<Account>A4=new List<Account>();
        List<Account>A5=new List<Account>();
        List<Account>A6=new List<Account>();
        List<Account>A7=new List<Account>();
        List<Account>A8=new List<Account>();
        List<Account>A9=new List<Account>();
        List<Account>A10=new List<Account>();
        List<Buchungskreis__c>B1=new List<Buchungskreis__c>();
        List<Buchungskreis__c>B2=new List<Buchungskreis__c>();
        
        for (Codetabelle__c c1: newcode){
            if(c1.BuchungskreisID__c!=null)
            {for (Account acc1:([Select id, BuKr__c from Account where BuKr__c =:c1.BuchungskreisID__c]))
            {Account A11=new Account(id=acc1.id,BuKr__c =c1.BuchungskreisFormel__c);                     
             A1.add(A11);}}
            else 
                if(c1.KontengruppenID__c!=null)
            {for (Account acc1:([Select id, Kontengr__c from Account where Kontengr__c =:c1.KontengruppenID__c]))
            {Account A21=new Account(id=acc1.id,Kontengr__c =c1.KontengruppenFormel__c);                     
             A2.add(A21);}}
            else 
                if(c1.KundengruppenID__c!=null)
            {for (Account acc1:([Select id, Kundengrp__c from Account where Kundengrp__c =:c1.KundengruppenID__c]))
            {Account A31=new Account(id=acc1.id,Kundengrp__c =c1.KundengruppenFormel__c);                     
             A3.add(A31);}}
            else 
                if(c1.KundenbezirkeID__c!=null)
            {for (Account acc1:([Select id, Kundenbezirk__c from Account where Kundenbezirk__c =:c1.KundenbezirkeID__c]))
            {Account A41=new Account(id=acc1.id,Kundenbezirk__c =c1.KundenbezirkeFormel__c);                     
             A4.add(A41);}}
            else 
                if(c1.VerkaeufergruppeDebitorID__c!=null)
            {for (Account acc1:([Select id, Verk_uferg__c from Account where Verk_uferg__c =:c1.VerkaeufergruppeDebitorID__c]))
            {Account A51=new Account(id=acc1.id,Verk_uferg__c =c1.VerkaeufergruppeDebitorFormel__c);                     
             A5.add(A51);}
             
            for (Buchungskreis__c Buch1:([Select id, Verk_ufergruppe__c from Buchungskreis__c where Verk_ufergruppe__c =:c1.VerkaeufergruppeDebitorID__c]))
            {Buchungskreis__c B11=new Buchungskreis__c(id=Buch1.id,Verk_ufergruppe__c =c1.VerkaeufergruppeDebitorFormel__c);                     
             B1.add(B11);}}
            else 
                if(c1.VerkaeuferbueroID__c!=null)
            {for (Account acc1:([Select id, Verk_Buero__c from Account where Verk_Buero__c =:c1.VerkaeuferbueroID__c]))
            {Account A61=new Account(id=acc1.id,Verk_Buero__c =c1.VerkaeuferbueroFormel__c);                     
             A6.add(A61);}
            
            for (Buchungskreis__c Buch1:([Select id, Verkaufsb_ro__c from Buchungskreis__c where Verkaufsb_ro__c =:c1.VerkaeuferbueroID__c]))
            {Buchungskreis__c B21=new Buchungskreis__c(id=Buch1.id,Verkaufsb_ro__c =c1.VerkaeuferbueroFormel__c);                     
             B2.add(B21);}}
            else 
                if(c1.Laendercode__c!=null)
            {for (Account acc1:([Select id, BillingCountry from Account where BillingCountry =:c1.Laendercode__c]))
            {Account A71=new Account(id=acc1.id,BillingCountry =c1.Laender__c);                     
             A7.add(A71);}}
            else 
                if(c1.BranchenschluesselID__c!=null)
            {for (Account acc1:([Select id, Branche_SAP__c from Account where Branche_SAP__c =:c1.BranchenschluesselID__c]))
            {Account A81=new Account(id=acc1.id,Branche_SAP__c =c1.BranchenschluesselFormel__c);                     
             A8.add(A81);}}
            else 
                if(c1.Verkaeufergruppe1ID__c!=null)
            {for (Account acc1:([Select id, Verkaeufergruppe1__c, Verkaeufergruppe2__c, LZLD_Gebiet__c,LZLD_Region__c, Regional_Leiter__c, LFB__c from Account where Verkaeufergruppe1__c =:c1.Verkaeufergruppe1ID__c or Verkaeufergruppe2__c=:c1.Verkaeufergruppe1ID__c or LZLD_Gebiet__c=:c1.Verkaeufergruppe1ID__c or LZLD_Region__c=:c1.Verkaeufergruppe1ID__c or Regional_Leiter__c=:c1.Verkaeufergruppe1ID__c or LFB__c=:c1.Verkaeufergruppe1ID__c]))
            {Account A91=new Account(id=acc1.id);
             if(acc1.Verkaeufergruppe1__c ==c1.Verkaeufergruppe1ID__c){acc1.Verkaeufergruppe1__c =c1.Verkaeufergruppe1Formel__c; }
             if(acc1.Verkaeufergruppe2__c ==c1.Verkaeufergruppe1ID__c){acc1.Verkaeufergruppe2__c =c1.Verkaeufergruppe1Formel__c; }
             if(acc1.LZLD_Gebiet__c ==c1.Verkaeufergruppe1ID__c){acc1.LZLD_Gebiet__c =c1.Verkaeufergruppe1Formel__c; }
             if(acc1.LZLD_Region__c ==c1.Verkaeufergruppe1ID__c){acc1.LZLD_Region__c =c1.Verkaeufergruppe1Formel__c; }
             if(acc1.Regional_Leiter__c ==c1.Verkaeufergruppe1ID__c){acc1.Regional_Leiter__c =c1.Verkaeufergruppe1Formel__c; }
             if(acc1.LFB__c ==c1.Verkaeufergruppe1ID__c){acc1.LFB__c =c1.Verkaeufergruppe1Formel__c; }
             A9.add(A91);}}
            else
                if(c1.Status_Profitcenter_ID__c!=null)
            {for (Account acc1:([Select id, Status_Profitcenter__c from Account where Status_Profitcenter__c =:c1.Status_Profitcenter_ID__c]))
            {Account A111=new Account(id=acc1.id,Status_Profitcenter__c =c1.Status_Profitcenter__c);                     
             A10.add(A111);}}      
        }
        
        splitupdate(A1);
        splitupdate(A2);
        splitupdate(A3);
        splitupdate(A4);
        splitupdate(A5);
        splitupdate(A6);
        splitupdate(A7);
        splitupdate(A8);
        splitupdate(A9);
        splitupdate(A10);
        splitupdate(B1);
        splitupdate(B2);
        
    }
  
}
Can we acheive this through lightning component to show the duplicate cases on the bases of Email, Casenumber and in subject if casenumber is mentioned.
Something like this.

User-added image
Thank you in advance
Hi,
Need help to write the test class for the following controller.

public with sharing class TrainingEventParticipantController {
    @AuraEnabled
    public  static List<TrainingEventParticipant__c> getparticipant(String eventid) {
        return [select id, name, AccountName__c, ContactId__r.Name, ContactId__c, SupervisorContactId__c, Status__c, Role__c,
                 CancelRequest__c from TrainingEventParticipant__c where TrainingEventId__c=:eventid];
    }
    @AuraEnabled
    public static String saveparticipant(List<TrainingEventParticipant__c> events) {
        try {
            Database.update(events, true);
            return LABEL.SuccessMessageTitle;
        }  catch (Exception e) {
            String errormsgCPA =  String.valueOf(e.getMessage());
            return errormsgCPA;
        }
    }
}

Thank you in advance
Shruthi
global class GDPRAnonymizationBatch Implements Database.batchable<sobject>{
     global final string query;
     global GDPRAnonymizationBatch(string q){
                   
          query=q;
     }
   
     global Database.QueryLocator start(Database.BatchableContext BC){
     //TODO: Bitte Query hier direkt anlegen und nicht per Konstruktor definieren
     //TODO: Konstruktor löschen
     return Database.getQueryLocator('SELECT Id,IsPersonAccount, Name ,PersonEmail from Account WHERE IsPersonAccount=True and MarkedForDeletion__c = true');
  }
                                     
     global  void execute(Database.BatchableContext BC,List<SObject> scope){
     
     for(Account acc: (List<Account>)scope){
          GDPRAnonymizationHelper helper=new GDPRAnonymizationHelper();
         
          //TODO: Es fehlen Aufrufe zu Methoden, z.B. für TasksAndActivities
          helper.AnonymizaAccountActivitiesAndTasks(acc.id);
          helper.AnonymizaRelatedVehicles(acc.id);
          helper.AnonymizaRelatedJobs(acc.id);
          helper.AnonymizaAccountFields(acc.id);          
          }
         
          //TODO: Accounts sollten nicht gelöscht werden
          Update scope;
   
    }
    global void finish(Database.BatchableContext BC){
     
       
    }
 }


And this the handler class for the above batch job

public with sharing class GDPRAnonymizationHelper {
    public void AnonymizaAccountFields(Id accountId) {
        Account anonymizaAcc= new Account(id=accountId);//[SELECT id from Account where id=:accountId];
        anonymizaAcc.Name= null;
        anonymizaAcc.Comment__c= null;
        anonymizaAcc.Car_Owner_Name__c= null;
        anonymizaAcc.Car_Owner_Address__c= null;
        anonymizaAcc.Test_Criteria_Matches_Vehicle__c= null;
        anonymizaAcc.Shipping_Additional_Information__c= null;
       // anonymizaAcc.BillingAddress= '';
        anonymizaAcc.Phone= null;
        anonymizaAcc.Phone_2__c= null;
        anonymizaAcc.PersonMobilePhone= null;
        anonymizaAcc.PersonMobilePhone2__c= null;
        anonymizaAcc.PersonEmail= null;
        update anonymizaAcc;
    }
    public void AnonymizaAccountActivitiesAndTasks(Id accountId) {
        //TODO: Keine Implementierung für diese Methode - die Methode wird auch nirgends aufgerufen
    }
    public void AnonymizaRelatedVehicles(Id accountId) {
       
        List<Vehicle__c> lstVehicles =new List<Vehicle__c>();
        for(Vehicle__c  anonymizaveh: [SELECT id,Account__c from Vehicle__c where Account__c=:accountId ]){
            anonymizaveh.VIN__c= null;          
            anonymizaveh.Special_Remarks__c= null;
            anonymizaveh.Comment_on_blocked_vehicle__c= null;
            anonymizaveh.Different_Owner_First_Name__c= null;
            anonymizaveh.Different_Owner_Last_Name__c= null;
            anonymizaveh.Different_Owner_Street__c= null;
            anonymizaveh.Different_Owner_ZIP_Code__c= null;
            anonymizaveh.Different_Owner_Email__c= null;
            anonymizaveh.Different_Owner_State_Province__c= null;
            lstVehicles.add(anonymizaveh);
        }
        //TODO: Fahrzeuge sollten nicht gelöscht sondern upgedated werden
        Database.Update(lstVehicles, false);
       
    }
    public void AnonymizaRelatedJobs(Id accountId) {
        List<Job__c> listjob =new List<Job__c>();
        for(Job__c  anonymizajob: [SELECT id,Account_Information__c from Job__c where Account_Information__c=:accountId ]){
            //  anonymizajob.Test_Customer_Id__c= '';
            //  anonymizajob.Vehicle_VIN__c= '';
            anonymizajob.All_neccessary_files_attached__c= null;
            anonymizajob.Comments_Up_to_Date_and_Appropriate__c= null;
            listjob.add(anonymizajob);
        }
        //TODO: Jobs sollten nicht gelöscht sondern upgedated werden
        Database.Update(listjob, false);
    }
   
}

i m tried this but i can achieve only 38% which is very less
How can i write the query here directly by deleting the constructor.


global class GDPRAnonymizationBatch Implements Database.batchable<sobject>{
     global final string query;
     global GDPRAnonymizationBatch(string q){
         
          
          query=q;
     }
   
     global Database.QueryLocator start(Database.BatchableContext BC){

     //TODO: Please create query here directly and do not define it by constructor and delete contructor

     return Database.getQueryLocator(query);
     }
     global  void execute(Database.BatchableContext BC,List<SObject> scope){
     
     for(Account acc: (List<Account>)scope){
          GDPRAnonymizationHelper helper=new GDPRAnonymizationHelper();
          
          //TODO: Es fehlen Aufrufe zu Methoden, z.B. für TasksAndActivities
          helper.AnonymizaRelatedVehicles(acc.id);
          helper.AnonymizaRelatedJobs(acc.id);
          helper.AnonymizaAccountFields(acc.id);          
          }
         
          //TODO: Accounts should not be deleted
          Update scope;
    
    }
    global void finish(Database.BatchableContext BC){
    
      
    }

 }




And this is the query i need to add to this batch job and here the Batch Helper class as well.
public with sharing class GDPRAnonymizationHelper {

    public void AnonymizaAccountFields(Id accountId) {
        Account anonymizaAcc= new Account(id=accountId);//[SELECT id from Account where id=:accountId];
        anonymizaAcc.Name= null;
        anonymizaAcc.Comment__c= null;
        anonymizaAcc.Car_Owner_Name__c= null;
        anonymizaAcc.Car_Owner_Address__c= null;
        anonymizaAcc.Test_Criteria_Matches_Vehicle__c= null;
        anonymizaAcc.Shipping_Additional_Information__c= null;
       // anonymizaAcc.BillingAddress= '';
        anonymizaAcc.Phone= null;
        anonymizaAcc.Phone_2__c= null;
        anonymizaAcc.PersonMobilePhone= null;
        anonymizaAcc.PersonMobilePhone2__c= null;
        anonymizaAcc.PersonEmail= null;

        update anonymizaAcc;
    }

    public void AnonymizaAccountActivitiesAndTasks(Id accountId) {
        //TODO: Keine Implementierung für diese Methode - die Methode wird auch nirgends aufgerufen
    }

    public void AnonymizaRelatedVehicles(Id accountId) {
        
        List<Vehicle__c> lstVehicles =new List<Vehicle__c>();
        for(Vehicle__c  anonymizaveh: [SELECT id,Account__c from Vehicle__c where Account__c=:accountId ]){
            anonymizaveh.VIN__c= null;          
            anonymizaveh.Special_Remarks__c= null;
            anonymizaveh.Comment_on_blocked_vehicle__c= null;
            anonymizaveh.Different_Owner_First_Name__c= null;
            anonymizaveh.Different_Owner_Last_Name__c= null;
            anonymizaveh.Different_Owner_Street__c= null;
            anonymizaveh.Different_Owner_ZIP_Code__c= null;
            anonymizaveh.Different_Owner_Email__c= null;
            anonymizaveh.Different_Owner_State_Province__c= null;
            lstVehicles.add(anonymizaveh);
        }
        //TODO: Fahrzeuge sollten nicht gelöscht sondern upgedated werden
        Database.update(lstVehicles, false);
        
    }

    public void AnonymizaRelatedJobs(Id accountId) {
        List<Job__c> listjob =new List<Job__c>();
        for(Job__c  anonymizajob: [SELECT id,Account_Information__c from Job__c where Account_Information__c=:accountId ]){
            //  anonymizajob.Test_Customer_Id__c= '';
            //  anonymizajob.Vehicle_VIN__c= '';
            anonymizajob.All_neccessary_files_attached__c= null;
            anonymizajob.Comments_Up_to_Date_and_Appropriate__c= null;
            listjob.add(anonymizajob);
        } 
        //TODO: Jobs sollten nicht gelöscht sondern upgedated werden
        Database.Update(listjob, false);
    }
    

}


And this should be the query
SELECT Id FROM Account WHERE MarkedForDeletion__c = true OR Opt_In_Confirmed__c < LAST_5_YEARS