Skip to main content
Hi...

ALL

i want to delete Lead Records Based on the company name.But i am facing this Error any one can can support me.

public class DML_Delete 

{    

    

    public static void RecordsDeletefromLead (string StartText)

    {

        

        if(StartText !='Null' && StartText !='')

        {

            StartText +='%';

           Map<id,Lead>  DeleteLead =new Map<id,Lead> ([select id,Company from Lead where Company Like:StartText]);

        }

        if(!DeleteLead.isEmpty())

        {

            delete DeleteLead;

        }        

    } 

}
2 个回答
  1. 2017年11月17日 14:28

    Hi,

    You are accessing DeleteLead out side of if condtion please use like this.

    public with sharing class DML_Delete {

    public static void RecordsDeletefromLead (String StartText){

    if(StartText != null && StartText != ''){

    StartText +='%';

    List<Lead> DeleteLead = new List<Lead>();

    DeleteLead = [select id,Company from Lead where Company Like:StartText];

    System.debug('DeleteLead'+DeleteLead);

    if(DeleteLead.size()>0){

    delete DeleteLead;

    }

    }

    }

    }

    Mark as a best if it helps you.

    Regards,

    Suraj

0/9000