You need to sign in to do that
Don't have an account?
Trigger - FIELD_CUSTOM_VALIDATION_EXCEPTION
I have the following error when i deployed from Sandbox - Production
Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Please submit for Operations Review before generating a quote.: []", Failure Stack Trace: "Class.TestingOrderFormLock.OrderFormLock: line 15, column 1"
This error is caused by the following trigger below - which doesnt allow users to generate a quote before a field in the opportunity is checked.
/*
Developed by Oscar Ngan, 2012-Oct-2
Goal: If the field Ready_for_Quote_Generation__c in Opportunity is not checked, quote record cannot be created.
*/
trigger QuoteGenerationCheck on Quote (after insert) {
List<Id> quoteID = new List<Id>();
for (Quote q : trigger.new)
quoteID.add(q.id);
Map<Id, Quote> quotes = new Map<Id, Quote>([select id, opportunity.Ready_for_Quote_Generation__c from Quote where id in :quoteID]);
for (Quote q : trigger.new)
{
if (quotes.get(q.id).opportunity.Ready_for_Quote_Generation__c == false)
q.addError('Please submit for Operations Review before generating a quote.');
}
}
This is my test class which wont deploy into production.
@isTest
private class TestingOrderFormLock{
static TestMethod void OrderFormLock(){
date closedDate = date.newInstance(2025,2,3);
test.startTest();
Account a = new Account(Name ='Testing',CurrencyISOCode='USD');
insert a;
Opportunity oppC = new Opportunity (Name = 'TestingClosed Opp', StageName = 'Closed Won', CloseDate = closedDate, Ready_for_Quote_Generation__c = true, AccountId = a.id,Competitor_s_new__c = 'Not Yet Defined' );
insert oppC;
Opportunity opp = new Opportunity(Ready_for_Quote_Generation__c = true, name='testOpp',StageName='90% - Contracts/ Order Forms',CurrencyIsoCode='USD',closeDate=system.today(),AccountId = a.id );
insert opp;
Quote q = new Quote (Name= 'Testing', OpportunityId = opp.Id,Ready_for_Quote_Generation__c =true,Verification_Code__c='1',ExpirationDate=system.today().addDays(1));
insert q;
Send_Quote_History__c sq = new Send_Quote_History__c(Quote__c = q.id);
insert sq;
// Create an approval request for the account
Approval.ProcessSubmitRequest req1 =
new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(q.id);
// Submit the approval request for the account
Approval.ProcessResult result = Approval.process(req1);
test.stopTest();
}
}
This is my trigger - to lock the Quote page once one quote has already been generated.
trigger OrderFormLock on Quote (after update, after insert) {
for (Quote qu: Trigger.New){
if(qu.Check_if_quote_was_sent__c > 0) {
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Quotation Sent');
req1.setObjectId(qu.id);
Approval.ProcessResult result = Approval.Process(req1);
}
}
}
It looks like you have a validation rule which is preventig you from creating a new Quote in line 15 of your test class. I would check the validation rules on Quote in your production environment, find the one that returns the error message "Please submit for Operations Review before generating a quote," and then make sure that the Quote satisfies that criteria in your test class.
Thanks for the reply. I am unable to find which part of the line 14 & 15
The below is the trigger is which the validation rule appears.
Is there something wrong with my test class, that doesnt allow this ready for quote generation to be checked before
trigger QuoteGenerationCheck on Quote (after insert) {
List<Id> quoteID = new List<Id>();
for (Quote q : trigger.new)
quoteID.add(q.id);
Map<Id, Quote> quotes = new Map<Id, Quote>([select id, opportunity.Ready_for_Quote_Generation__c from Quote where id in :quoteID]);
for (Quote q : trigger.new)
{
if (quotes.get(q.id).opportunity.Ready_for_Quote_Generation__c == false)
q.addError('Please submit for Operations Review before generating a quote.');
}
}
The problem is in your test class. You need to modify line 14 of your test class (the one that begins with "Quote q = ") by providing the quote object with valid data. When you try to insert that record, there is a custom validation rule in your org that is preventing it from being inserted.