You need to sign in to do that
Don't have an account?
Dee Dee Aaron
Help with test class - where to insert required fields?
Hi. With the help of another user on the forum, I was able to use a sample test class. I just don't know how or where to add the required fields?
The two required fields that need to be inserted:
Name (Name) *Standard Text field.
Layer (Layer__c) *This is a picklist. The 2 options are "Layer 2" "Layer 3"
Can you please insert them for me?
*I see another area in the test class that says "insert f". I'm not sure what I need to insert in that spot?
Test class:
@isTest
public class FeedCommentTriggerTest {
@isTest
public static void testFeedCommentTrigger() {
//Create a User with Profile 'Net Planning Department'
Id pid = [Select Id FROM Profile WHERE Name = 'Net Planning Department'].Id;
User u = new User();
u.ProfileId = pid;
//here fill all the required fields for the User Record
insert u;
SALES_ENGINEERING_REQUEST__c s = new SALES_ENGINEERING_REQUEST__c();
s.Status__c = //any Value othe than "Approved" and "Unable to Meet Request"
//here fill all the required fields for the SALES_ENGINEERING_REQUEST__c Record
insert s;
//Since test class runs in the current user mode and in this Trigger lines will be covered only when the //User has a Profile - 'Net Planning Department' hence we need trigger this event as the new User created with this //Profile
System.runAs(u) {
FeedComment f = new FeedComment();
f.ParentId = s.Id;
//here fill all the required fields for FeedCommentRecord
Test.startTest();
insert f;
Test.stopTest();
}
SALES_ENGINEERING_REQUEST__c updatedRecord = [SELECT Id,Status__c FROM SALES_ENGINEERING_REQUEST__c WHERE Id =: s.Id];
System.assertequals('Approved',updatedRecord.Status__c);
}
}
Thank you for your help!
The two required fields that need to be inserted:
Name (Name) *Standard Text field.
Layer (Layer__c) *This is a picklist. The 2 options are "Layer 2" "Layer 3"
Can you please insert them for me?
*I see another area in the test class that says "insert f". I'm not sure what I need to insert in that spot?
Test class:
@isTest
public class FeedCommentTriggerTest {
@isTest
public static void testFeedCommentTrigger() {
//Create a User with Profile 'Net Planning Department'
Id pid = [Select Id FROM Profile WHERE Name = 'Net Planning Department'].Id;
User u = new User();
u.ProfileId = pid;
//here fill all the required fields for the User Record
insert u;
SALES_ENGINEERING_REQUEST__c s = new SALES_ENGINEERING_REQUEST__c();
s.Status__c = //any Value othe than "Approved" and "Unable to Meet Request"
//here fill all the required fields for the SALES_ENGINEERING_REQUEST__c Record
insert s;
//Since test class runs in the current user mode and in this Trigger lines will be covered only when the //User has a Profile - 'Net Planning Department' hence we need trigger this event as the new User created with this //Profile
System.runAs(u) {
FeedComment f = new FeedComment();
f.ParentId = s.Id;
//here fill all the required fields for FeedCommentRecord
Test.startTest();
insert f;
Test.stopTest();
}
SALES_ENGINEERING_REQUEST__c updatedRecord = [SELECT Id,Status__c FROM SALES_ENGINEERING_REQUEST__c WHERE Id =: s.Id];
System.assertequals('Approved',updatedRecord.Status__c);
}
}
Thank you for your help!
try this following Test Class Dummy code.
I don't know that Layer__c this filed is of which record so you check and set this filed.
let me know, if it's helps you and close your query as best mark of this.
Thank You