Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Re: REQUIRED_FIELD_MISSING, Required fields are mi...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
REQUIRED_F IELD_MISSI NG, Required fields are missing: [Active_In gredients_ _c]:
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-14-2012 09:56 PM
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;
}
}
Naresh
Solved! Go to Solution.
Re: REQUIRED_F IELD_MISSI NG, Required fields are missing: [Active_In gredients_ _c]:
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-14-2012 10:13 PM
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.
Certified Salesforce Developer
Check out my blog. http://andrewwilkinsonsf.blogspot.com/
Re: REQUIRED_F IELD_MISSI NG, Required fields are missing: [Active_In gredients_ _c]:
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-14-2012 10:34 PM
After Modifying this. Getting this error now
System.StringException: Invalid id: CP
Competitor_Product__c cp1 = new Competitor_Product
insert cp1;
Tried by giving different values on Active_Ingredients but whatever i give it is saying invalid id that string or number
Naresh
Re: REQUIRED_F IELD_MISSI NG, Required fields are missing: [Active_In gredients_ _c]:
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-14-2012 10:51 PM
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 = Ingr
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.
Certified Salesforce Developer
Check out my blog. http://andrewwilkinsonsf.blogspot.com/

