Solved?
The root cause is my inaccuracy in object initiating: i just forgot to add new
.
But the misleading error message is still in place. So other APEX devs may hit the same issue.
Initial Question
It's a bit strange thing i hit, but since i am not very experienced APEX dev yet... Please give me an idea what's wrong below?
I am coding a custom code which is going to force sync our customer data from SFDC to Zendesk. So i installed a managed package which should do all the Zendesk API work. The package's namespace prefix is zdapiv1
.
This code which uses the prefix compiles like a charm:
@isTest
global with sharing class ZdSyncOrg {
private static zdapiv1.ZendeskConnection zconn;
private static zdapiv1.ZendeskConnection getConnection() {
if (null == zconn) {
zconn = zdapiv1.ZendeskConnection.createWithAPIToken('subdomain','email@example.com','token');
}
return zconn;
}
@isTest static void testGetConnection() {
zdapiv1.ZendeskConnection conn = getConnection();
System.assertNotEquals(null, conn);
System.assertEquals(conn, zconn);
}
}
But when i add another method i see [OPERATION FAILED]: classes/ZdSyncOrg.cls: Variable does not exist: zdapiv1 (Line: 23, Column: 22)
.
Here is the example:
@isTest
global with sharing class ZdSyncOrg {
private static zdapiv1.ZendeskConnection zconn;
private static zdapiv1.ZendeskOrganizationsAPI orgApi;
private static zdapiv1.ZendeskConnection getConnection() {
if (null == zconn) {
zconn = zdapiv1.ZendeskConnection.createWithAPIToken('subdomain','email@example.com','token');
}
return zconn;
}
@isTest static void testGetConnection() {
zdapiv1.ZendeskConnection conn = getConnection();
System.assertNotEquals(null, conn);
System.assertEquals(conn, zconn);
}
private static zdapiv1.ZendeskOrganizationsAPI getOrgApi() {
if (null == orgApi) {
// The error points to the following line:
orgApi = zdapiv1.ZendeskOrganizationsAPI(getConnection());
}
return orgApi;
}
}
That puzzles me a lot. Why the same namespace prefix cannot be used in the other method? And how to work that around?