You need to sign in to do that
Don't have an account?
Jose Bernal 2
Territory2Type and Territory2Model creation for testing
Hi guys,
I'm trying to create objects of Territory2Type and Territory2Model classes but it says that DML is not allowed. I also tried SOAP calls but these are not allowed for testing. What should I do?
Best regards,
Are you trying to insert Territory2Type and Territory2Model records in Test class ? No need to insert records, you can directly query it in test class. It is accessible in test classes.
For Ex : - list<Territory2Type> terriType = [SELECT id, DeveloperName from Territory2Type where DeveloperName = 'Territory'];
DML is not allowed for Territory2Type but you can perform DML on Territory2Model.
Ex : Territory2Model terrModel = new Territory2Model();
terrModel .DeveloperName='ModelName'; // required field
terrModel.Name = 'Name'; // required field
insert terrModel ;
Thanks
All Answers
Are you trying to insert Territory2Type and Territory2Model records in Test class ? No need to insert records, you can directly query it in test class. It is accessible in test classes.
For Ex : - list<Territory2Type> terriType = [SELECT id, DeveloperName from Territory2Type where DeveloperName = 'Territory'];
DML is not allowed for Territory2Type but you can perform DML on Territory2Model.
Ex : Territory2Model terrModel = new Territory2Model();
terrModel .DeveloperName='ModelName'; // required field
terrModel.Name = 'Name'; // required field
insert terrModel ;
Thanks
System.runAs(createMockUserForProfile('System Administrator')) {
model = new Territory2Model(
Name = name,
DeveloperName = name);
insert model;
System.assert(model != null);
}
However, Territory2Type is not as easy to create. Would there be any option for that?
Thanks,
For ex :-
List<sObject> listTerritoryType = Test.loadData(Territory2Type.sObjectType, 'TerritoryType');
or you can create manually in org and can query it.
Thanks