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
MurphmanMurphman 

Problem with validation rule for forecatsed amount

I wrote this rul but it is not working correctly. When a salesman in converting a lead to a opportunity i want the forcasted amount to be greater than zero.  See detail below.   Validation Rule Detail
Error: Invalid Data.
Review all error messages below to correct your data.
Rule NameForecasted_AmountActiveChecked
Error Condition FormulaAND(
NOT(ISNEW()),
ISBLANK(Amount))
Error MessageTo save a new Opportunity. The forecasted $ amount needs to be greater than $0. If you do not know at least the ballpark range for sales, it is not yet an Opportunity, but a lead that requires further qualification.Error LocationAmount
DescriptionAmount Forecasted for Opportunity is less than $0. All Opportunities must have a forecasted $ amount
Created By, 10/12/2011 9:47 AM
Andy BoettcherAndy Boettcher

What is not working?  Is the Opportunity being created but no error appearing?

MurphmanMurphman

To answer your question as it stands right now the validation rule only works when you make a change to the opportunity and try to resave it.

 

Let me state my problem and maybe you have a better solution.  My salesman create opportunites with no dollar amounts.  I want to force them to enter a dollar amount in the lead before they convert it to an opportunity if they dont know the estimated amount the lead sould not be converted. I guess I have to add the field and the validation rule on the leads screen.  But how do I get the amount to carry over to the opportunities screen?

 

If you have a better solution please let me know.

 

Thanks for the help!

Brian

Andy BoettcherAndy Boettcher

That's kind of a tricky place to enter some business logic.  I have had customers approach me with very similar questions and what I've had to do is to override the "Convert" button with a Visualforce page, have my logic run in the related Controller, and then push the related Ids and whatnot through to the standard Convert Lead page after that.

 

Is that something you'd be interested in pursuing?  Let me know - I can help you lay some groundwork.

MurphmanMurphman

Is there any other work around?  How do other companies handle it?

Andy BoettcherAndy Boettcher

I can only speak on behalf of my experience - the first company I helped through putting more advanced business logic (more advanced than just pushing a button on it) ended up having to do a VF/APEX route.  The kicker is that you're creating the converted records through a backend Database method - not a "normal" synchronous database insert.  Once you start that process - you're committed.

 

I'm 100% open to hearing the other community members here chime in on this though - anyone else found / created a better solution?

 

-Andy

alok29novalok29nov

Hi Murphman,

 

One work around for your requirement is that you create a Forecatsed_Amount on your lead object and make it mandatory/required.

 

And the second step is you can map your Forecatsed_Amount to Opportunity Amount field( You might need to create a custom amount field on your opportunity object as standard fields dont appear in mapping fiieds and hide the standard field).

You can do that by  going to Lead(setup->customize->Lead->Fields->Map Lead Fields).

 

And if you want to force Sales rep the  to the amount only when he tries to convert it from lead to opportunity then The only way you can do that by  using VF and apex otherwise you can use the above approach.

 

Please let me know if you have any issue doing above.

 

Thanks

~Alok

CaptainObviousCaptainObvious

Building on alok29nov's suggestion, you can create a custom Convert button on the Lead object with OnClick javascript.

Add the Forcasted Amount field to the Lead object and map it to a similar field on the Opportunity (I dont think you can map it to the Amount field).

On the Lead page layout, hide the standard Convert button and replace it with your custom Convert button (the name can be the same).

The OnClick Javascript on your custom button would look something like this:

 

var pattern = /[^0-9.-]+/g; 
var f_amount = '{!Lead.Forecasted_Amount__c}'; 
f_amount = parseFloat(f_amount.replace(pattern,'')); 
if ( f_amount > 0 ) { top.location.replace('/lead/leadconvert.jsp?retURL=%2F{!Lead.Id}&id={!Lead.Id}'); } 
else { alert('You must enter a Forecasted Amount greater than 0'); }

 

If the Forecasted Amount is greater than 0, the standard Salesforce leadconvert function will be used.
If the amount is 0 or has not been entered, the user will receive an alert message and conversion will not take place.