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
AbanteAbante 

Restrict lead conversion

Hello everyone,

 

 

I'ld like to restrict the lead conversion when the user is not the lead owner. What's the easiest way?

 

 

Thanks in advance

 

Javier Jiménez

Abante Asesores

Navatar_DbSupNavatar_DbSup

Hi,

 

You can a validation rule on the lead to restrict the user for conversion of lead.

 

Try the below validation rule criteria as reference:

 

AND(OwnerId != $User.Id , IsConverted )

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

b-Forceb-Force

you are having two options to restrict this 

 

you can override standard Convert button by VF page 

below is VF page code 

<apex:page standardController="Lead" Extensions="CustomConvertor" action="{!Validate}"> 
<script type="text/javascript">
var er='{!Err}';
if(er != '')
{
	alert(er)
	location.href= '/'+'{!recId}';
}
</script>
</apex:page>

 

 

Apex Code

public with sharing class CustomConvertor 
{
	public string Err {get;set;}
    public Lead obj ;
    public string recId {get;set;}
    public CustomConvertor(ApexPages.StandardController controller) 
    {
        obj= (Lead)controller.getRecord();
        obj=[Select Id,OwnerId from Lead where Id = : obj.Id];
    }
    
    public pagereference Validate()
    {
    	
       Pagereference objRet;
       if(obj.OwnerId == Userinfo.getUserId())
       {     
        objRet= new Pagereference('/lead/leadconvert.jsp');
        objRet.getParameters().put('id',obj.Id);
        objRet.getParameters().put('nooverride','1');
       }else
       {
       		recId = obj.Id;
       		Err='Unable to convert ';
       }
       return objRet;
        
    }

}

 

 

Please overide standard convert button by below page

 

 

Approach 2: 

 

Create anather custom button for Lead Conversion with content source as execute javascript

 

Code is here 

 

if('{!$User.Id}' == '{!Lead.OwnerId}')
{	
location.href='/lead/leadconvert.jsp?retURL=%2F'+'{!Lead.Id}'+'&id='+'{!Lead.Id}';
}else
{
alert('you cant convert this lead');
}

 

Please let us know if you face any issue with above code

 

Thanks