2

I have validation rule and trigger where i need to restrict users from converting lead if they are not the owners, both of them doesn't seems to work..what was the issue?

Validation rule:

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

Trigger:

trigger leadPreventer on Lead (before insert, before update)
  {
    if(trigger.isUpdate)
     {
       for(Lead l:Trigger.new)       
        {       
           if (l.IsConverted && UserInfo.getUserId()!=l.OwnerId)       
            {           
              l.addError('Its not possible');
            }       
        }
     }
  }
5
  • 1
    Have you tried adding debug statements to your trigger to verify the values?
    – Mike Chale
    Sep 19, 2014 at 19:59
  • Agree with @MikeChale. Debug statements inside the for loop and a log after this is run would be very helpful to see. Sep 19, 2014 at 20:13
  • You tried these individually, right? They were not both active at the same time.
    – Jagular
    Sep 19, 2014 at 20:15
  • I haven't added any debug statements since i thought it's pretty straightforward but i will check on that.
    – Admin_BA
    Sep 19, 2014 at 20:36
  • @Jagular. Yes i did and it doesn't works either
    – Admin_BA
    Sep 19, 2014 at 20:37

2 Answers 2

4

From the validation rule it looks like you might have Lead conversion setting as unchecked.

If you go to Setup - Customize - Leads - Settings and check if "Enforce Validation and Triggers from Lead Convert" is checked or not.

Ideally if it is unchecked then Validation Rule and Triggers on Lead conversion will be ignored.

Update: Since you cannot enable "Enforce Validation and Triggers from Lead Convert" in your org, due to your org being an old one as rightly pointed out by @Jenny B.

You can get these settings to be displayed from salesforce, or add your custom button on Lead for conversion and gracefully decline a conversion if initiated by user other than record owner. If the user who clicks on your convert button is the owner of lead record then forward him to convert lead page ( which is https://na10.salesforce.com/lead/leadconvert.jsp?id={!Lead.ID}), else throw an alert message.

2
  • When i go to lead settings i don't see that, i only see these 2 options Preserve Lead Status and Enable Conversions on the Salesforce1 App
    – Admin_BA
    Sep 19, 2014 at 20:38
  • 1
    @Admin_BA not sure how old your org is, but according to this answer, salesforce.stackexchange.com/questions/16061/…, you may need to have salesforce enable it if you have an older org.
    – Jenny B
    Sep 19, 2014 at 23:36
0

Please check this validation rule:

IsConverted =True && $User.Id <> OwnerId

I hope it will work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .