• NetD
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies

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);
        }
    }
}

  • September 03, 2013
  • Like
  • 0

Hi, I am not a coder so I would very much appreciate some help on how to code the follow simple trigger (i think):

 

I have a custom object that embedded in the Opportunity object with master-detail relationship.

 

On this custom object I have created a custom look-up field to relate with the User object.

 

What I need is a trigger to auto-populate this "User " look-up field with the "Opportunity Owner" whenever a record is created on this custom object.

 

Please help me! thank you!!

  • May 23, 2013
  • Like
  • 0

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);
        }
    }
}

  • September 03, 2013
  • Like
  • 0

Hi, I am not a coder so I would very much appreciate some help on how to code the follow simple trigger (i think):

 

I have a custom object that embedded in the Opportunity object with master-detail relationship.

 

On this custom object I have created a custom look-up field to relate with the User object.

 

What I need is a trigger to auto-populate this "User " look-up field with the "Opportunity Owner" whenever a record is created on this custom object.

 

Please help me! thank you!!

  • May 23, 2013
  • Like
  • 0