+ Start a Discussion
sakthidharan Ambayiramsakthidharan Ambayiram 

I am getting the below error when writing test class for the below class

Apex Class
/*
Having the Utilities of the Askiiris Integration
*/
public without Sharing class Integration_Util {
    Public Static FINAL String DML_ERROR='Error Occured While Saving Record To database';
    /*
Method to log the integration trace in notes
*/
    Public Static void InsertNote(id parentId,string body,string title,boolean isPrivate,boolean ExceptionOccured){
        note resp = new note();
        resp.parentId = parentId; 
        resp.body =body; 
        resp.title = title; 
        resp.isPrivate = isPrivate; 
        database.insert(resp,false); 
    }
     /*
Method to send the Exception Email to CMSO-PS
*/
    public static void sendExceptionEmail(String[] emailId,String subject,String emailBody){
        Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
        semail.setToAddresses(emailId); 
        semail.setSubject(subject); 
        semail.setHtmlBody(emailBody); 
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail}); 
    } 
    /*
Method to get the Integration Credentials
*/
    Public Static CredentialsWrapper getCredetials( String credentialDevName){
        Integration_Credentials_Mapping__mdt mdt=[select id,Production_End_point_URI__c,Sanbox_End_point_URI__c,
                                                  Sandbox_password__c,Sandbox_user_name__c,Production_password__c,
                                                  Production_user_name__c,security_hns__c,Suffix_URL_1__c,Suffix_URL_2__c,
                                                  Sandbox_Auth_URI__c,Production_Auth_URI__c
                                                  From Integration_Credentials_Mapping__mdt 
                                                  where DeveloperName=:credentialDevName LIMIT 100];
        
        boolean isSandbox=[SELECT issandbox from organization LIMIT 1].isSandbox;
        CredentialsWrapper credwrap=new CredentialsWrapper();
        if(isSandbox){
            credwrap.enpointUrl=mdt.Sanbox_End_point_URI__c;
            credwrap.username =mdt.Sandbox_user_name__c;
            credwrap.password =mdt.Sandbox_password__c;
            credwrap.authTokenUrl =mdt.Sandbox_Auth_URI__c; 
        }else{
            credwrap.enpointUrl=mdt.Production_End_point_URI__c;
            credwrap.username=mdt.Production_user_name__c;
            credwrap.password=mdt.Production_password__c;
            credwrap.authTokenUrl =mdt.Production_Auth_URI__c; 
        }
        credwrap.hnsUrl=mdt.security_hns__c;
        credwrap.isSandbox=isSandbox;
        credwrap.suffixUrl1=mdt.Suffix_URL_1__c;
        credwrap.suffixUrl2=mdt.Suffix_URL_2__c;
        
        return credwrap;
    } 
    /*
Wrapper class used wrap the Integration Credentials
*/
    Public without sharing class CredentialsWrapper{
        Public String username;
        Public String password;
        Public String enpointUrl;
        Public String hnsUrl;
        public Boolean isSandbox;
        Public String suffixUrl1;
        public String suffixUrl2;
        Public String authTokenUrl;
        
    }
    
}

My Test Class

@isTest
public class Integration_Util_UT {

    private static testmethod void InsertNote() {
    Integration_Util.InsertNote('00300000003T2PGAA0','hello','hello',True,True);
     }                    
                    
    private static testmethod void sendExceptionEmail() {
        Integration_Util.sendExceptionEmail('fdgd@df.com','hello','hello');
       }                
                    
    private static testmethod void getCredetials() {
        Integration_Util.getCredetials('hello');
        }                    
}                

My error : "Method does not exist or incorrect signature: void sendExceptionEmail(String, String, String) from the type Integration_Util"
Also the current code coverage is 31%, please hep me to get code coverage 
Thanks in advance
Best Answer chosen by sakthidharan Ambayiram
Abdul KhatriAbdul Khatri
Change the below line in your test class
private static testmethod void sendExceptionEmail() {
    Integration_Util.sendExceptionEmail('fdgd@df.com','hello','hello');
}

to this
private static testmethod void sendExceptionEmail() {
    Integration_Util.sendExceptionEmail(new List<String> {'fdgd@df.com'},'hello','hello');
}

All Answers

Abdul KhatriAbdul Khatri
Change the below line in your test class
private static testmethod void sendExceptionEmail() {
    Integration_Util.sendExceptionEmail('fdgd@df.com','hello','hello');
}

to this
private static testmethod void sendExceptionEmail() {
    Integration_Util.sendExceptionEmail(new List<String> {'fdgd@df.com'},'hello','hello');
}
This was selected as the best answer
sakthidharan Ambayiramsakthidharan Ambayiram
thanks Abdul

I am getting code coverage 50% now
can u plz how to test or handle the below piece of code in Integration_Util class  for writing a test class
I dont know how to cover it in test class for this , since i am new to salesforce


boolean isSandbox=[SELECT issandbox from organization LIMIT 1].isSandbox;
        CredentialsWrapper credwrap=new CredentialsWrapper();
        if(isSandbox){
            credwrap.enpointUrl=mdt.Sanbox_End_point_URI__c;
            credwrap.username =mdt.Sandbox_user_name__c;
            credwrap.password =mdt.Sandbox_password__c;
            credwrap.authTokenUrl =mdt.Sandbox_Auth_URI__c; 
        }else{
            credwrap.enpointUrl=mdt.Production_End_point_URI__c;
            credwrap.username=mdt.Production_user_name__c;
            credwrap.password=mdt.Production_password__c;
            credwrap.authTokenUrl =mdt.Production_Auth_URI__c; 
        }
        credwrap.hnsUrl=mdt.security_hns__c;
        credwrap.isSandbox=isSandbox;
        credwrap.suffixUrl1=mdt.Suffix_URL_1__c;
        credwrap.suffixUrl2=mdt.Suffix_URL_2__c;
        
        return credwrap;
    } 

thanks in Advance
Abdul KhatriAbdul Khatri
Can you make sure you have DeveloperName 'hello' that you are passing to this Method
Integration_Util.getCredetials('hello');
You need to pass what you have defined in the meta data types. 
 
sakthidharan Ambayiramsakthidharan Ambayiram
Still not able to cover the **Query ,if, else part *of class in my test class
this is my new Test Class, code coverage is 50 % still...

@isTest
public class Integration_Util_UT {

    private static testmethod void InsertNote() {
    Integration_Util.InsertNote('00300000003T2PGAA0','hello','hello',True,True);
     }                    
                
    private static testmethod void sendExceptionEmail() {
        Integration_Util.sendExceptionEmail(new List<String> {'fdgd@df.com'},'hello','hello');
       }                
                    
    private static testmethod void getCredetials() {
        Integration_Util.getCredetials('Swetha Raj');
           Integration_Credentials_Mapping__mdt mdt=New Integration_Credentials_Mapping__mdt(id='01p37000003AWOj',Sanbox_End_point_URI__c='sfsh46t',
                                                  Sandbox_password__c='Pass',Sandbox_user_name__c='Sakthi',Sandbox_Auth_URI__c='hfhfye74jj',
                                                  Production_password__c='Pass', Production_user_name__c='SAkthi',security_hns__c='kj6',
                                                  Suffix_URL_1__c='kk',Suffix_URL_2__c='ff',Production_Auth_URI__c='dufe75hfh', 
                                                                                          Production_End_point_URI__c='sjde649yrhf');
        
    }
}
 
Abdul KhatriAbdul Khatri
Can you please check if the below SOQL returning anything
 
[select id,Production_End_point_URI__c,Sanbox_End_point_URI__c,                                          Sandbox_password__c,Sandbox_user_name__c,Production_password__c,                                                  Production_user_name__c,security_hns__c,Suffix_URL_1__c,Suffix_URL_2__c,                                                  Sandbox_Auth_URI__c,Production_Auth_URI__c From Integration_Credentials_Mapping__mdt                                                  where DeveloperName=:credentialDevName LIMIT 100];