2

Once a lead is converted, there is a special oppty that is created, which is related to the converted lead. This is mostly used by marketing for lead-to-cash reports.

What happens with our salesteam, is that they do not create an oppty once the lead is converted.

This causes marketing to "loose" data.

How can I make sure that the oppty will be created upon conversion?

In the past, the conversion page was uneditable. SF help pages offer the opposite of my need: How to make sure that an oppty will NOT be created.

I want to hide the checkbox - so an oppty will always be create.

Can I?

4

You cannot hide the checkbox on the conversion page. You can however prevent conversion without an opportunity using a validation rule on Lead (Setup -> Customize -> Leads -> Validation Rules -> New). Give your new rule a name, and set the error condition formula to IsConverted && ConvertedOpportunityId == null. Set an error message, for example, 'All converted leads must have an opportunity. Please uncheck the "Do not create a new opportunity box" and try again.'

2
  • O M F G !!!! If I could give you +1000 for this simple, easy solution, I would !!! THis works perfect !! Are you married? ^^
    – Saariko
    Jan 29 '14 at 16:41
  • 3
    As a developer, my first instinct is to write code for any problem. I'm trying to work on that impulse :) Jan 29 '14 at 16:48
4

You can create a Visualforce page, and a custom extension to enforce this logic. You can also write a trigger that forces this:

trigger PreventLeadConvertNoOppTrigger on Lead (after update) {
    for(Lead record: Trigger.new) {
        if(record.IsConverted && !Trigger.oldMap.get(record.Id).IsConverted && record.ConvertedOpportunityId == null) {
            record.ConvertedOpportunityId.addError('You must provide an opportunity when converting leads.');
        }
    }
}
5
  • Beat me by 10 seconds. Good work. :) Jan 28 '14 at 20:32
  • 1
    @sfdc_ninja It's not a race! Besides, I'm not a big fan of the trigger method, because you get an ugly "validation failed while converting" and you have to click the back button to try again.
    – sfdcfox
    Jan 28 '14 at 20:33
  • I agree, but a trigger was the only way I could think of off the top of my head to easily do this. Jan 28 '14 at 20:34
  • @sfdc_ninja Like my answer says; you can do Visualforce, too. Probably more like a few hundred lines of code instead of 5, especially if you want the deduplication logic that you get for free from the standard page. I'm even less of a fan that way around.
    – sfdcfox
    Jan 28 '14 at 20:35
  • I agree. I just didn't think of the VF solution until you mentioned it, but you're right, even less ideal than the trigger Jan 28 '14 at 20:37
2

I know this isn't config only which is likely more ideal, but you could write an after trigger on leads and create the opportunity there.

Something like this

trigger LeadTrigger on Lead (after update) {
    set<Id> leadIDs = new set<Id>();
    for(Lead l : newLeads){
         if(l.isConverted == true && oldMap.get(l.Id).isConverted == false && l.ConvertedOpportunityId == null){
              leadIDs.add(l.Id);            
         }
    }
    list<Opportunity> opps = new list<Opportunity>();
    for(Lead l : [Select Id, Name, Other_fields_you_want From Lead Where Id In : leadIds]){
         opps.add(new Opportunity(
              Name = 'Opp Name',
              Your_Field__c = 'Your Value'
         ));
    }
    insert opps;
}
2
  • 1
    The flaw with that, though, is that the opportunity won't be automatically linked to the lead through the converted opportunity id field. You'll still lose the association of that lead to the opportunity. This only matters for reporting, of course...
    – sfdcfox
    Jan 28 '14 at 20:32
  • It is a good point. You're solution of just adding an error in the trigger might work better in that case Jan 28 '14 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.