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

lead history

I am trying to anonymize leads. I am updating the salesforce fields and then deleting the history of the field (.
public static String LeadGDPRAnonymizeFieldUpdate(Lead LeadTobeUpdated)
	{

		LeadTobeUpdated.FirstName = '**********';
		LeadTobeUpdated.LastName = '**********';
		LeadTobeUpdated.FirstNameLocal = '**********';
		LeadTobeUpdated.LastNameLocal = '**********';
		LeadTobeUpdated.MobilePhone = '**********';
		Return 'Success';
	}

and
public static String LeadGDPRDeleteFieldHistory(List<Id> sLeadID)
	{
		List<LeadHistory> leadHistory = new List<sObject> ();
		leadHistory.addAll([SELECT Id FROM LeadHistory WHERE LeadId IN :sLeadID]);
		Database.delete(leadHistory);

		return 'Success';

	}
When I call these functions in the main fuction:
        GDPRLeadUpdate(leadId);
        GDPRLeadDeleteHistoryOption(leadId);
THere are still values in lead field history.

Any thoughts!
Raj VakatiRaj Vakati
You need to call this method as "LeadGDPRDeleteFieldHistory" future call or async 



i tried to call both methods at same time but not to delete and t tried to call the LeadGDPRDeleteFieldHistory as salesforce future call i am able to 
Glyn Anderson (Slalom)Glyn Anderson (Slalom)
This doesn't solve your problem, but your second method could be written as:
public static String LeadGDPRDeleteFieldHistory(List<Id> sLeadID)
{
    delete [SELECT Id FROM LeadHistory WHERE LeadId IN :sLeadID];

    return 'Success';
}
It's a little easier to understand what's going on.