• Mark Steves
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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