7

The following test method will not compile or save from my IDE. It give an error of: "(OIGForceTest) DML not allowed on AdditionalNumber "

static testMethod void testGetDirectoryNumbers() {
    // Perform our data preparation. 
    List<AdditionalNumber> addNums = new List<AdditionalNumber>{}; 
    for(Integer i = 0; i < 5; i++){ 
        AdditionalNumber a = new AdditionalNumber(Name = 'AdditionalNumber' + i, Phone = '555555' + i); 
        addNums.add(a); 
    } 

    // Insert the AdditionalNumber records
    insert addNums;  //DML not allowed???        
    String directoryNumbers = OIGForce.getDirectoryNumbers();
    System.debug('directoryNumbers: ' + directoryNumbers);
}  

Has anyone else seen this error?
Is it truly impossible to insert an AdditionalNumber record in Apex, even for testing? Any workarounds or thoughts would be appreciated!

1
  • You could try creating them via the REST API called Apex that should work, but of course will not work in a test, since callouts are not allowed in tests. Dec 5, 2013 at 22:29

1 Answer 1

1

Have you tried creating a CallCenter record and setting CallCenterId in the AdditionalNumber records you're inserting?

Maybe you need to create a CallCenter record and include a list of AdditionalNumber records in the AdditionalNumbers child relationship?

2
  • 3
    I was just experimenting with that, and checked the docs. Apparently, you can only create them through the API, and not through Apex Code. See the following code: DescribeSObjectResult r = Schema.AdditionalNumber.SObjectType.getDescribe(); System.assert(r.iscreateable());
    – sfdcfox
    Dec 5, 2013 at 19:58
  • Have to use @isTest(seeAllData=true). Dec 5, 2013 at 20:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .