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
JmBessonartJmBessonart 

Package Install Failed cause by a custom Validation Rule

Hi,

I have a test class that create a new Opportunity to work with. The problem is that some customers have their own validation rules in some of the Opportunity object, and cause the insert fail.

 

 

Opportunity newOppty = new Opportunity(StageName='Qualification', Probability=10, Amount=100.00, Type='Existing Customer - Downgrade', LeadSource='Web', IsPrivate=false, Name='John Bess Oppty', ForecastCategoryName='Pipeline', CloseDate=Date.today());
insert newOppty;

 

 There is a way to know if there are any validation rule on the opportunity fields before the insert and create a valid Opportunity?? What is the best practice in this case?, because I can't what the users can have differents validations depend of each Org. 

 

Thanks

J.

JmBessonartJmBessonart

Any one??

 

Right now i'm using try catch, but i think there NEED to be a better way to do it .

 

 

Opportunity currentOppty;
try {
Opportunity newOppty = new Opportunity(StageName='Qualification', Probability=10, Amount=100.00, Type='Existing Customer - Downgrade', LeadSource='Web', IsPrivate=false, Name='John Bess Oppty', ForecastCategoryName='Pipeline', CloseDate=Date.today());
insert newOppty;
currentOppty = newOppty;
}
catch (Exception e) {
List<Opportunity> opttyList = [select name from Opportunity limit 1];
if (opttyList.size() > 0) {
currentOppty = opttyList[0];
}
}

 

Thanks in advance!!

J.

 

 

Message Edited by JmBessonart on 10-23-2009 05:59 AM
neoocmwtfneoocmwtf

Same here. I REALLY need some mechanism like disabling rules on tests or some function that builds a valid opportunity for me. Otherwise I'm lost!

Hope someone can help..

Thanks!

ascuccimarraascuccimarra

I'm having that same problem. A way around it could be using a custom oppty, but that doesn't apply to our needs.
Anyone knows any work around to disable validation rules?

 

 

 Thanks!