You need to sign in to do that
Don't have an account?
REQUIRED_FIELD_MISSING, Required fields are missing: [Active_Ingredients__c]:
Hi,
I am getting below error.
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Active_Ingredients__c]: [Active_Ingredients__c]
Class.AddCompProduct_Test.myUnitTest: line 26, column 1
@isTest
private class AddCompProduct_Test {
//Create Testing User
private static User localUser;
static testMethod void myUnitTest() {
// TO DO: implement unit test
createTestUser();
System.runAs(localUser){
// Run the tests as user with the System Administrator profile
Test.startTest();
Territory__c testT = new Territory__c(Name = 'tesTerritory');
insert testT;
Post_Code__c postCode = new Post_Code__c(Country__c = 'Australia', Name = '1234', Town__c = 'TestTown',
State__c = 'testState',Territory__c = testT.Id);
insert postCode;
Account testAccount = new Account(name='TEST_ACCOUNT',Country__c = 'Australia', Town__c = 'TestTown', Post_Code1__c='1234', MobilePhone__c='+61-4444-333-333',Phone ='+61 (22) 4444 4444');
insert testAccount;
Crop__c crop;
insert (crop=new Crop__c(Name = 'Funny ANZ Crop'));
Active_Ingredient__c Ingredient;
insert (Ingredient=new Active_Ingredient__c (Name = 'CP 20mg/L'));
Competitor_Product__c cp1 = new Competitor_Product__c( Active__c=true, Active_Ingredient__c = 'CP 20mg/L', Name='CP COMP ANZ ');
insert cp1;
Competitor_Product__c cp2 = new Competitor_Product__c( Active__c=true, Species__c = 'Apple', Name='Seeds COMP ANZ ');
insert cp2;
AddCompProduct controller = new AddCompProduct();
controller.options.country = 'Australia';
controller.options.filterCP = new string[]{'Competitor CP'};
controller.options.filterSE = new string[]{'Competitor Seeds'};
controller.options.pageSizes = new integer[]{10};
Set<string> x;
x = controller.options.productFamilyFilterCP;
x = controller.options.productFamilyFilterSE;
x = controller.options.productFamilyFilter;
List<SelectOption> so;
so = controller.options.PageSizesSO;
boolean b;
b = controller.isOk;
string str1 = controller.doResetSearch;
controller.doResetSearch = 'reset';
controller.selectedProductFamily = 'Competitor CP';
so = controller.productFamilies;
so = controller.productProducers;
b = controller.readyForSearch;
PageReference pr;
pr = controller.changeProductFamily();
b = controller.isCP;
b = controller.isSE;
pr = controller.doSearch();
controller.pageSizeTop = 10;
pr = controller.rePaginateTop();
controller.pageSizeBottom = 10;
pr = controller.rePaginateBottom();
b = controller.canGoBack;
b = controller.canGoForward;
pr = controller.nextPage();
pr = controller.prevPage();
integer i;
i = controller.pageNo + controller.totalProducts + controller.totalPages;
List<AddCompProduct.ProductData> pd = controller.productData;
b = controller.hasProductData;
system.debug('----------------------------' + pd.size());
AddCompProduct.ProductData ppd = new AddCompProduct.ProductData(new Competitor_Product__c( Active__c=true, Species__c = 'Apple', Name='Seeds COMP ANZ '), controller);
b = ppd.isCP;
b = ppd.isSE;
Test.stopTest();
}
}
private static void createTestUser(){
ID adminProfileID = [SELECT Id FROM Profile WHERE Name = 'System Administrator'].ID;
localUser= new User(username='localuserforUnitTest@20110308test.com',
alias = 'testu',
email='localuserforUnitTest@20110308test.com',
emailencodingkey='UTF-8',
lastname='Syngenta',
CommunityNickname ='mahi45678',
languagelocalekey='en_US',
localesidkey='en_US',
profileid = adminProfileID,
timezonesidkey='Europe/Berlin'
);
insert localUser;
}
}
To me it looks like that field on that object is a lookup to an Active_Ingredient__c object. For that field put:
Competitor_Product__c cp1 = new Competitor_Product__c( Active__c=true, Active_Ingredients__c = Ingredient.Id, Name='CP COMP ANZ ');
insert cp1;
This will make it a lookup to an object you created. On lookups you have to supply an Id from a real object.
All Answers
The Active_Ingredients__c field needs to be set on the Active_Ingredient__c object.
insert (Ingredient=new Active_Ingredient__c (Name = 'CP 20mg/L',Active_Ingredients__c='Some value'));
I don't know the data type of the field but you need to set that value.
After Modifying this. Getting this error now
System.StringException: Invalid id: CP
Competitor_Product__c cp1 = new Competitor_Product__c( Active__c=true, Active_Ingredients__c = 'CP', Name='CP COMP ANZ ');
insert cp1;
Tried by giving different values on Active_Ingredients but whatever i give it is saying invalid id that string or number
To me it looks like that field on that object is a lookup to an Active_Ingredient__c object. For that field put:
Competitor_Product__c cp1 = new Competitor_Product__c( Active__c=true, Active_Ingredients__c = Ingredient.Id, Name='CP COMP ANZ ');
insert cp1;
This will make it a lookup to an object you created. On lookups you have to supply an Id from a real object.