2

I am difficulty with regards to deploying my apex trigger and test to the product salesforce account, Can anyone help on this as it is urgent, the trigger is:

trigger LeadAssigmnent on Lead (after insert) {

  List<Lead> ls = new List<Lead>();   
  for (Lead leadInLoop : Trigger.new) {
    if(leadInLoop.LeadSource == 'Marketing')
    {               
            ls.add(new Lead(id = leadInLoop.id));
    }
    Database.DMLOptions dmo = new Database.DMLOptions();
    dmo.assignmentRuleHeader.useDefaultRule = true;

    //leadInLoop.setOptions(dmo);
    Database.update(ls, dmo);                   
  }
}

And My test Class as follows:

@isTest
private class LeadAssignmentTest {

  static testMethod void leadAssignmentTest() {
    // TO DO: implement unit test
    //List<Id> TestlIds=new List<id>();

    // Insert a new Lead record
    Lead newLead = new Lead();
    newLead.company='Test, Inc';
    newLead.LastName='Tester';
    newLead.FirstName='Testy';
    newLead.Country='Russia';
    newLead.Description='Test Message for Russia';
    newLead.LeadSource='Marketing';
    if(newLead.LeadSource == 'Marketing'){          
            insert newLead;                
    }        
  }
}

I am getting the following Error:

Run Failures: TestCreateProjFromOpp.runMethod System.DmlException: Insert failed. First exception on row 1; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (pricebook entry is inactive): [PricebookEntryId]

Can you guys please help, maybe point out what I am doing wrong on the above problem please.

Thanks in Advance.

  • Note I am not working with any products on this trigger, thus the confusion... – Local Jun 16 '14 at 16:07
  • Could there be other triggers that execute code ? – Samuel De Rycke Jun 16 '14 at 16:39
  • No other triggers, none I know of in the system, this is the only custom trigger on this system., Thank You – Local Jun 17 '14 at 8:08
  • The error message implies that there is a class called TestCreateProjFromOpp which appears to be triggered somehow. You're getting that error while running your test class right, or while deploying? – Samuel De Rycke Jun 17 '14 at 8:13
  • I am getting it while deploying, any ideas in how to fix this or work around it? would really help the problem is that I did not work on any other class other than this trigger, but as you say it my be triggered... – Local Jun 17 '14 at 8:18
1

When deploying to a production org, all apex tests on your will be executed. In time when there is no strict governance, or tests are written in a way that they rely on real data those tests can go corrupt.

Run Failures: TestCreateProjFromOpp.runMethod System.DmlException: Insert failed. First exception on row 1; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (pricebook entry is inactive): [PricebookEntryId]

Knowing that the error is generated in your deploy process, it is easily interpreted. There's a class called TestCreateProjFromOpp which has a runMethod. You'll have to look which apex test class or method is testing this, as it is likely using a hardcoded reference to a pricebook that is no longer active in your org.

You'll have to activate the pricebook to have your tests pass, or rewrite your test code in a developer environment and deploy it to production.

As of the summer 14 / API 31.0 release you'll be able to create pricebook entries from apex test code and no longer have to rely on actual data for this. This isn't in the documentation yet, but can be referenced on page 249 of the current release notes.

1

After Spending time on this problem, I am came up with a different approach to me solution/test class and this worked for me and I was able to deploy my code to the production org. following is the solution that worked for maybe someone else can relate their problem and use my solution into their scenario... Thanks Guys for the help:

@isTest(seealldata=true)
private class LeadAssignmentTest {

    static testMethod void leadAssignmentTest() {
        // TO DO: implement unit test
        List<Id> TestlIds=new List<id>();

        // Insert a new Lead record
        Lead newLead = new Lead(company='Test, Inc', LastName='Tester', FirstName='Testy', Country='Russia', LeadSource='Web');
        Test.startTest();
        newLead.LeadSource = 'Marketing';
        TestlIds.add(newLead.Id);

        //newLead.PriceBookEntryID = [select id from PriceBookEntry WHERE IsActive = TRUE limit 1][0].ID;

        insert newLead;
        Test.stopTest();      
    }
}

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.