i'm trying to deploy an apex class, and i have the following error when trying to validate the changeset in production, could someone help ? Thanks ! :)
Apex class description :
The batch has to convert a lead without creating an opportunity, ToConvert... are two custom fields on the leads containing some IDs.
Error message :
System.DmlException: ConvertLead failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, You do not have the required permissions. To continue, you must have the 'Read' permission on the selected account record.: [] Stack Trace: Class.AutomaticLeadConversion.execute: line 22, column 1.
Apex class code :
public with sharing class AutomaticLeadConversion implements
Database.Batchable<SObject>, Database.RaisesPlatformEvents{
public Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator([SELECT Id, ToConvertAccountId__c, ToConvertContactId__c, IsConverted FROM Lead WHERE IsConverted = false and ToConvertAccountId__c != null and ToConvertContactId__c != null]);
}
public void execute(Database.BatchableContext bc, List<Lead> records){
List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();
for(Lead record:records){
Database.LeadConvert lc = new Database.LeadConvert();
if (record.IsConverted == false){
lc.setConvertedStatus('Qualifié');
lc.setLeadId(record.Id);
lc.setDoNotCreateOpportunity(true);
lc.setAccountId(record.ToConvertAccountId__c);
lc.setContactId(record.ToConvertContactId__c);
leadConverts.add(lc);
}
}
Database.convertLead(leadConverts, true);
}
public void finish(Database.BatchableContext bc){
}
}