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

    // 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!

  • 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 '13 at 22:29

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?

  • 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 '13 at 19:58
  • Have to use @isTest(seeAllData=true). Dec 5 '13 at 20:11

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.