0
votes

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){

    }
}
1
NB : line 22 is this one "Database.convertLead(leadConverts, true);" – tiuse

1 Answers

0
votes

The problem is that you are converting a lead which is probably assigned to que if that is the case make sure that lead is assigned to person instead of que. or pass the owner id

lc.setOwnerId(USER_ID);