+ Start a Discussion
Dee Dee AaronDee Dee Aaron 

Help to write test class

Hi there. I have a trigger that works. I just need help writing the test class. Can you please provide a test class instead of linking me to a page that says "how to write a test class". Thank you for your help.

trigger FeedCommentTest on FeedComment (after insert) 
    for(FeedComment f : Trigger.New)
        if(UserInfo.getProfileId()  == '00e6w000000QHyUAAW')
            Sales_Engineering_Request__c SalesEngineeringRequestToUpdate = [SELECT ID FROM SALES_ENGINEERING_REQUEST__c WHERE ID =: f.ParentId];
            SalesEngineeringRequestToUpdate.Status__c = 'Approved';
            Update SalesEngineeringRequestToUpdate;

Best Answer chosen by Dee Dee Aaron
AnudeepAnudeep (Salesforce Developers) 
NOTE: The code provided is an example. You'll need to review and make modifications for your organization.
private class FeedCommentTest {
    @isTest static void testFeedComment() {
        User usr = new User();
        usr.ProfileId = [SELECT Id FROM Profile WHERE Name != 'System Administrator' limit 1].Id;// replace this with the profile name associated with id 00e6w000000QHyUAAW             
        usr.LastName = 'Test';
        usr.Email = 'test@test.com';
        usr.Username = 'test@test.com' + System.currentTimeMillis();
        usr.CompanyName = 'Salesforce';
        usr.Title = 'Title';
        usr.Alias = 'Roger';
        usr.TimeZoneSidKey = 'America/Los_Angeles';
        usr.EmailEncodingKey = 'UTF-8';
        usr.LanguageLocaleKey = 'en_US';
        usr.LocaleSidKey = 'en_US';
        System.runAs(usr) {
            //Parent Record
            Account acc = new Account(Name = 'Test Account');
            insert acc;
            Sales_Engineering_Request__c ser = new Sales_Engineering_Request__c(); 
            //populate required fields of this object and perform insert
            insert ser;
            //Create Related Feed Item Record
            FeedItem fi = new FeedItem(ParentId = ser.Id, Body = 'Test Body');
            insert fi;
            //Create Feed Comment Record
            FeedComment fc = new FeedComment(FeedItemId = fi.Id, parentId = ser.id, CommentBody = 'Test Comment');
            insert fc;
            //Get Feed Comment Record
            FeedComment objFC = [Select Id, CommentBody, FeedItemId, ParentId FROM FeedComment LIMIT 1];
            //Check Feed Comment Parent Id
            System.assertEquals(objFC.ParentId, ser.Id);

Please mark this answer as Best if you find the information shared helpful. Thank You!