function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sdfc devSdfc dev 

Test code coverage

Hi,

 

pulic void getLoginResult(String username, String password){
	mysoap.Soap connection = new mysoap.Soap();
	mysoap.LoginResult loginResult = connection.login(username, password);
	mysoap.SessionHeader_element sessionHeader =  new mysoap.SessionHeader_element();
	sessionHeader.sessionId  =	loginResult.sessionId;
	connection.SessionHeader = sessionHeader;
	connection.endpoint_x  =  loginResult.serverUrl;
}

 

mysoap is enterprise wsdl generated from my salesforce org.

 

How do I get code coverage for the above method?

 

Thanks in advance

sf@143sf@143
I think you are using enterprise API in java code. For this code their is no code coverage. The code coverage is for salesforce apex classes and triggers.
Abhi_TripathiAbhi_Tripathi

Hi,

This method will cover itself if you have called it somewhere, for which you are writing test class

 

OR

 

You can call it easliy write after defining your controller like

 

yourClassName controller = new yourClassName();

 

//Assigning value

controller.UserName = 't@sfdc.com'

controller.Password = 'testing';

 

//Calling method

controller.getLoginResult(userName, password);

 

Check out this post for test classes basics

http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html

Sdfc devSdfc dev

Hi,

 

Thanks for your reply abhi.

 

pulic void getLoginResult(String username, String password){
	try{
		if (!String.isBlank(username) && !String.isBlank(password)){
			mysoap.Soap connection = new mysoap.Soap();
			mysoap.LoginResult loginResult = connection.login(username, password);
			mysoap.SessionHeader_element sessionHeader =  new mysoap.SessionHeader_element();
			sessionHeader.sessionId  =	loginResult.sessionId;
			connection.SessionHeader = sessionHeader;
			connection.endpoint_x  =  loginResult.serverUrl;
		}
	}catch(Exception ex){
		System.debug('Exception is '+ex.getMessage());
	}
}

 

I am doing exactly the same as suggested above but it fails in getting sessionId and executes the catch block.

 

Here it fails "sessionHeader.sessionId = loginResult.sessionId;"

 

It is because both username and password are dummy ones.

 

Is there  any workaround to resolve this issue in test class?

 

Thanks in advance