wrong constructor declaration reference

Issue #2423 resolved
Adam Stepanek created an issue

Hi Scott,

in following inner class I have two similar constructors, one of which is private. Any reference to the inner class outside of its parent class reference the private constructor, despite the parameters declaration should point to the public one. Deployment is successful. Unfortunately, I was not able to reproduce this behaviour with any less complex class system.

public class TemplateService {
    public List<Field> getFields() {
        // ...
        for (Template_Field_Junction__mdt templateFieldJunction : template.Template_Field_Junctions__r) {
            templateServiceFields.add(new Field(
                    templateFieldJunction,
                    fieldMap.get(templateFieldJunction.Field__c),
                    record
            ));
        }
        // ...
    }

    public class Field {
        /**
         * Must be present because of exception: 'System.TypeException: TemplateService.Field does not have a no-arg constructor'
         */
        public Field() {
        }

        private Field(Template_Field_Junction__mdt fieldJunction, Template_Field__mdt field, Object value) {
           // ...
        }

        public Field(Template_Field_Junction__mdt fieldJunction, Template_Field__mdt field, SObject record) {
            this(fieldJunction, field, getFormattedValue(field, fieldJunction, record));
        }
    }
}

The reference on line 5 is correctly mapped to the public constructor.

@IsTest
private class TemplateServiceTest {
    @IsTest
    static void testFieldParentValue() {
        final String FIELD_NAME = 'Buyer_Name';
        Order ord = [SELECT Id, Contact__r.Name FROM Order LIMIT 1];
        Template_Field__mdt field = getField(FIELD_NAME);
        Template_Field_Junction__mdt junction = getJunction(field.Id);

        TemplateService.Field templateServiceField = new TemplateService.Field(junction, field, ord);

        Assert.areEqual(FIELD_NAME, templateServiceField.name);
        Assert.areEqual('Joe tester', templateServiceField.value);
    }
}

And here the reference on line 10 is incorrectly mapped to the private constructor.

Comments (4)

  1. Log in to comment