• SalesforceUser11
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 1
    Replies
Hi,

I am writing a test class. I have covered 3 lines bt I am not getting how to cover remainig. Can anyoe suggest

Class:
global class ACN_ExceptionDebugProvider implements ACN_ExceptionProviderService {
    global ACN_ExceptionLibrary.ExceptionResponse ProcessException (ACN_ExceptionLibrary.ExceptionRequest request) {
        ACN_ExceptionLibrary.ExceptionResponse response = new ACN_ExceptionLibrary.ExceptionResponse();
        response.Id = request.Id;
        response.Name = request.Name;
        response.DataProviderName = request.DataProviderName;
        response.ExceptionMap = request.ExceptionMap;
        response.ExtendedProperties = request.ExtendedProperties;
        
        System.debug(request);
        
        return response;
    }
}

Test Class: Need coverage from 3rd line 

@IsTest
private class ACN_ExceptionDebugProviderTest {

@testSetup
private static void testSetup() {

}

@isTest
private static void testProcessException() {
try {
    Test.startTest();
    new ACN_ExceptionDebugProvider().ProcessException(null);
    Test.stopTest();
} catch(Exception e) {

}
}
}

 
Hi,

Below is the class

global class ACN_TopicController {
    public static ConnectAPI.ManagedTopicCollection getNavigationTopics(){
        Id communityId = ACN_NavigationLibrary.GetCurrentCommunityId() ;
        return ConnectAPI.ManagedTopics.getManagedTopics(communityId, ConnectApi.ManagedTopicType.Navigational);
    }

    public static ConnectAPI.ManagedTopicCollection getNavigationTopics(Integer level){
        Id communityId = ACN_NavigationLibrary.GetCurrentCommunityId() ;
        return ConnectAPI.ManagedTopics.getManagedTopics(communityId, ConnectApi.ManagedTopicType.Navigational, level);
    }

    public static ConnectAPI.ManagedTopicCollection getNavigationTopics(List<Id> topicIds, Integer level){
        Id communityId = ACN_NavigationLibrary.GetCurrentCommunityId() ;
        return ConnectAPI.ManagedTopics.getManagedTopics(communityId, ConnectApi.ManagedTopicType.Navigational, topicIds, level);
    }
}
Hi,

My test class is passed but test coverage is 0%. Can any one help to increase tets coverage:

APex Class: 

public class TopicOfInterestUserAsgmtDataAccessor implements TopicOfInterestUserAssignmentDAI {
    public List<Topic_of_Interest_User_Assignment__c> getSubscribedTopicsOfInterestByUserId(Id userId) {
        return [
            SELECT Id, 
                User__c, 
                TopicofInterest__c 
            FROM Topic_of_Interest_User_Assignment__c 
            WHERE User__c = :userId];
    }

    public List<Topic_of_Interest_User_Assignment__c> getSubscribedTopicsOfInterestLabelsByUserId(Id userId) {
        return [
            SELECT Id, 
                User__c, 
                toLabel(TopicofInterest__c) 
            FROM Topic_of_Interest_User_Assignment__c 
            WHERE User__c = :userId];
    }

    public void upsertUserTopicSelections(List<Topic_of_Interest_User_Assignment__c> newOrExistingTopics) {
        upsert newOrExistingTopics;    
    }

    public void deleteUserTopicSelections(List<Topic_of_Interest_User_Assignment__c> existingTopics) {
        delete existingTopics;
    }

}

Test Class:
@IsTest
private class TopicOfInterestUserAsgmtDataAccessorTest {

    @testSetup
    private static void testSetup() {
    }

    @isTest
   Private static void testgetSubscribedTopicsOfInterestByUserId() {

        Profile p = [SELECT Id FROM Profile WHERE Name = 'System Administrator'];
        User u = new User(Alias = 'standt', Email = 'standarduser@testorg.com',
                EmailEncodingKey = 'UTF-8', LastName = 'Testing', LanguageLocaleKey = 'en_US',
                LocaleSidKey = 'en_US', ProfileId = p.Id,
                TimeZoneSidKey = 'America/New_York', UserName = 'standarduser1@testorg.com');

        System.runAs(u) {

            Topic_of_Interest_User_Assignment__c tci = new Topic_of_Interest_User_Assignment__c();
            tci.User__c = u.Id;
            tci.TopicofInterest__c = 'Administrative';
            insert  tci;
            system.debug('**************tci'+tci);
        }
    }
}
Hello,

I am wrirting test class. I have included all the objects in my test class but its coverage is 0%. Can anyone suggest me what to do so test coverage will increase.

Apex Class:

/**
* Email services are automated processes that use Apex classes
* to process the contents, headers, and attachments of inbound
* email.
Create book record from the inbound email
*/
global class InboundEmailtoVacancy implements Messaging.InboundEmailHandler {
    
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,Messaging.InboundEnvelope envelope) {
        
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
        Review_Vacancy__c vacancy = new Review_Vacancy__c();
        
        //----Insert Record            
        vacancy.Email_Subject__c = email.subject; 
        vacancy.From_Address__c = email.fromAddress;
        if(email.htmlBody == Null){
            vacancy.Email_Body__c = email.plainTextBody;
        }
        else
            vacancy.Email_Body__c = email.htmlBody;  
        
        String emailBody1 = email.plainTextBody;
        String s1 = 'Order Reference:';
        String s2 = 'Job:';
        String s3 = 'Job Location:';
        String s4 = 'StartDate:';
        String s5 = 'EndDate:';
        String s6 = 'Start Time';
        String s7 = 'End Time';
        String s8 = 'Number Required:';
        String s9 = 'Additional Details';
        String s10 = 'Borough:';
        //-----Order Num     
        String AfterS1 = emailBody1.substringAfter(s1);
        String OrRefS1 = AfterS1.substringBefore(s2);
        
        System.debug('AfterS1--Order Ref----'+AfterS1);
        System.debug('OrRefS1--Order Ref----'+OrRefS1);
        //-----Job   
        String AfterS2 = emailBody1.substringAfter(s2);
        String OrRefS2 = AfterS2.substringBefore(s3);   
        //-----Job Location
        String AfterS3 = emailBody1.substringAfter(s3);
        String OrRefS3 = AfterS3.substringBefore(s4); 
        //-----StartDate
        String AfterS4 = emailBody1.substringAfter(s4);
        String OrRefS4 = AfterS4.substringBefore(s5); 
        //-----EndDate
        String AfterS5 = emailBody1.substringAfter(s5);
        String OrRefS5 = AfterS5.substringBefore(s6); 
        //-----Start Time
        String AfterS6 = emailBody1.substringAfter(s6);
        String OrRefS6 = AfterS6.substringBefore(s7); 
        //-----End Time
        String AfterS7 = emailBody1.substringAfter(s7);
        String OrRefS7 = AfterS7.substringBefore(s8); 
        //-----Number Required
        String AfterS8 = emailBody1.substringAfter(s8);
        String OrRefS8 = AfterS8.substringBefore(s9);
        //-----Borough
        String AfterS10 = emailBody1.substringAfter(s10);
        String OrRefS10 = AfterS10.substringBefore(s9);
        //-----Additional Details
        String AfterS9 = emailBody1.substringAfter(s9);
        //String OrRefS9 = AfterS9.substringBefore(s10);
        
        
        vacancy.Order_Reference__c = OrRefS1;
        vacancy.Job__c = OrRefS2;
        vacancy.Job_Location__c = OrRefS3;
        vacancy.StartDate__c = OrRefS4;
        vacancy.EndDate__c = OrRefS5;
        vacancy.Start_Time__c = OrRefS6;
        vacancy.End_Time__c = OrRefS7;
        vacancy.Number_Required__c = OrRefS8;
        vacancy.Borough__c = OrRefS10;
        //vacancy.Additional_Details__c = OrRefS9;
        insert vacancy ;
        
        // Save attachments, if any Image or text file
        
        If((email.textAttachments) != Null){
            for (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {
                Attachment attachment = new Attachment();
                
                attachment.Name = tAttachment.fileName;
                attachment.Body = Blob.valueOf(tAttachment.body);
                attachment.ParentId = vacancy.Id;
                insert attachment;
            }
        }
        // Save Email as PDF attachments
        if(email.htmlBody == Null){
            Attachment attachment1 = new Attachment();
            attachment1.Name = 'EmailBody';
            attachment1.Body = Blob.valueOf(email.plainTextBody);
            attachment1.ParentId = vacancy.Id;
            insert attachment1;
        }
        else
        {
            Attachment attachment1 = new Attachment();
            attachment1.Name = 'EmailBody';
            attachment1.Body = Blob.valueOf(email.htmlBody);
            attachment1.ParentId = vacancy.Id;
            insert attachment1;
        }
        
        result.success = true;
        return result;
    }
}


Test Class:

//Test Method for main class
@isTest 
private class InboundEmailtoVacancyTestTest{
    
    static testMethod void testEmailServiceHtmlBodyNull()
    {
        // create a new email and envelope object
        
        Messaging.InboundEmail email = new Messaging.InboundEmail() ;
        Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
        
        // setup the data for the email
        
        email.subject = 'Test Job Applicant';
        email.fromAddress = 'someaddress@email.com';
        email.htmlBody = null;
        email.plainTextBody = 'Test plainTextBody';
        env.fromAddress = 'someaddress@email.com';
        
        
        Review_Vacancy__c vacancy = new Review_Vacancy__c();
        system.debug(' email.htmlBody1  ************************'+email.htmlBody);
        vacancy.Email_Body__c = email.plainTextBody;
        vacancy.Email_Subject__c = email.subject; 
        vacancy.From_Address__c = email.fromAddress;
        insert vacancy;
        system.debug('Insert Vacancy'+vacancy);
        
        // add an Binary attachment
        // Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment();
       // attachment.body = blob.valueOf('my attachment text');
       // attachment.fileName = 'textfileone.txt';
       // attachment.mimeTypeSubType = 'text/plain';
        //email.binaryAttachments = new Messaging.inboundEmail.BinaryAttachment[] { attachment };
            
            // add an Text atatchment
            
        Messaging.InboundEmail.TextAttachment attachmenttext = new Messaging.InboundEmail.TextAttachment();
        Attachment attachment = new Attachment();
        attachment.Name = 'textfileone.txt';
        attachment.body = blob.valueOf('my attachment text');
        attachment.ParentId = vacancy.Id;
        insert attachment;
        
        email.textAttachments =   new Messaging.inboundEmail.TextAttachment[] { attachmenttext };
            
            // call the email service class and test it with the data in the testMethod
            /// inBoundEmail  testInbound=new inBoundEmail();
            //testInbound.handleInboundEmail(email, env);
            
            
            // Create Attachmenat data
            
        Attachment attachmnt =new Attachment();
        attachmnt.name='textfileone.txt';
        attachmnt.body =blob.valueOf('my attachment text');
        attachmnt.ParentId =vacancy.Id;
        insert  attachmnt ;
        
        
    }
    
    static testMethod void testEmailServiceHtmlBodyNotNull() {
        system.debug('testEmailService testEmailServiceHtmlBodyNotNull***************');
        // create a new email and envelope object
        Messaging.InboundEmail email = new Messaging.InboundEmail();
        system.debug('Inbound Email testEmailServiceHtmlBodyNotNull**********************');
        Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
        system.debug('Inbound Envelope  testEmailServiceHtmlBodyNotNull**********************');
        email.subject = 'Test Job Applicant';
        email.fromname = 'FirstName LastName';
        email.htmlBody = 'Test htmlBody';
        email.plainTextBody = 'Test plainTextBody';
        env.fromAddress = 'someaddress@email.com';
        
        Review_Vacancy__c vacancy = new Review_Vacancy__c();
        vacancy.Email_Subject__c = email.subject; 
        vacancy.From_Address__c = email.fromAddress;
        system.debug(' Review_Vacancy__c Obj testEmailServiceHtmlBodyNotNull************************');
        system.debug(' email.htmlBody testEmailServiceHtmlBodyNotNull ************************'+email.htmlBody);
        
        String s1;
        String s2;
        String s3;
        String s4;
        
        vacancy.Email_Body__c = email.htmlBody;  
        String emailBody1 = email.plainTextBody;
        s1 = 'Order Reference:';
        s2 = 'Job:';
        s3 = 'Job Location:';
        s4 = 'StartDate:';
        String s5 = 'EndDate:';
        String s6 = 'Start Time';
        String s7 = 'End Time';
        String s8 = 'Number Required:';
        String s9 = 'Additional Details';
        String s10 = 'Borough:';
        //-----Order Num     
        String AfterS1 = s1;
        String OrRefS1 = s2;
        String AfterS2 = s2;
        String OrRefS2 = s3;   
        //-----Job Location
        String AfterS3 = s3;
        String OrRefS3 = s4; 
        //-----StartDate
        String AfterS4 = s4;
        String OrRefS4 = s5; 
        //-----EndDate
        String AfterS5 = s5;
        String OrRefS5 = s6; 
        //-----Start Time
        String AfterS6 = s6;
        String OrRefS6 = s7; 
        //-----End Time
        String AfterS7 = s7;
        String OrRefS7 = s8; 
        //-----Number Required
        String AfterS8 = s8;
        String OrRefS8 = s9;
        //-----Borough
        String AfterS10 = s10;
        String OrRefS10 = s9;
        //-----Additional Details
        String AfterS9 = s9;
        
        
        vacancy.Order_Reference__c = OrRefS1;
        vacancy.Job__c = OrRefS2;
        vacancy.Job_Location__c = OrRefS3;
        vacancy.StartDate__c = OrRefS4;
        vacancy.EndDate__c = OrRefS5;
        vacancy.Start_Time__c = OrRefS6;
        vacancy.End_Time__c = OrRefS7;
        vacancy.Number_Required__c = OrRefS8;
        vacancy.Borough__c = OrRefS10;
        insert vacancy;
        system.debug('Insert Vacancy testEmailServiceHtmlBodyNotNull'+vacancy);
        
        
    }
    
}

Thanks,
Utz
Hello,

My client was using professional edition. I have developed some things in sandbox. Now he is upgrading his org from production to enterprise edition.
I cant refresh my sandbox as i will loose all data in my sandbox. i need to match Production liscences only. there is button on company profile in sandbox named as 'Match Production Liscences'. My query is will i loose any data from sandbox if i clicked on this button and matched liscences.

Thanks & Regards,
Utz
Hi,

My test class is passed but test coverage is 0%. Can any one help to increase tets coverage:

APex Class: 

public class TopicOfInterestUserAsgmtDataAccessor implements TopicOfInterestUserAssignmentDAI {
    public List<Topic_of_Interest_User_Assignment__c> getSubscribedTopicsOfInterestByUserId(Id userId) {
        return [
            SELECT Id, 
                User__c, 
                TopicofInterest__c 
            FROM Topic_of_Interest_User_Assignment__c 
            WHERE User__c = :userId];
    }

    public List<Topic_of_Interest_User_Assignment__c> getSubscribedTopicsOfInterestLabelsByUserId(Id userId) {
        return [
            SELECT Id, 
                User__c, 
                toLabel(TopicofInterest__c) 
            FROM Topic_of_Interest_User_Assignment__c 
            WHERE User__c = :userId];
    }

    public void upsertUserTopicSelections(List<Topic_of_Interest_User_Assignment__c> newOrExistingTopics) {
        upsert newOrExistingTopics;    
    }

    public void deleteUserTopicSelections(List<Topic_of_Interest_User_Assignment__c> existingTopics) {
        delete existingTopics;
    }

}

Test Class:
@IsTest
private class TopicOfInterestUserAsgmtDataAccessorTest {

    @testSetup
    private static void testSetup() {
    }

    @isTest
   Private static void testgetSubscribedTopicsOfInterestByUserId() {

        Profile p = [SELECT Id FROM Profile WHERE Name = 'System Administrator'];
        User u = new User(Alias = 'standt', Email = 'standarduser@testorg.com',
                EmailEncodingKey = 'UTF-8', LastName = 'Testing', LanguageLocaleKey = 'en_US',
                LocaleSidKey = 'en_US', ProfileId = p.Id,
                TimeZoneSidKey = 'America/New_York', UserName = 'standarduser1@testorg.com');

        System.runAs(u) {

            Topic_of_Interest_User_Assignment__c tci = new Topic_of_Interest_User_Assignment__c();
            tci.User__c = u.Id;
            tci.TopicofInterest__c = 'Administrative';
            insert  tci;
            system.debug('**************tci'+tci);
        }
    }
}