You need to sign in to do that
Don't have an account?
Pallavi singh
How to achieve the 75% code coverage for this batch job
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
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
Can you try the below Test class.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
Can you share the updated code here.
Thanks,
global class GDPRAnonymizationBatch Implements Database.batchable<sobject>{
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 OR WHERE Privacy_Policy_Confirmed_Timestamp__c < LAST_N_YEARS:5)');
}
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){
}
}
yes sure
Thanks,
Can you try the below Test class.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
I have question regarding the Lightning component do you have time today?
You can put it as fresh question. I will try to address it if I can.
Thanks,