0

I'm trying to fetch all article types and run SOQL on them but getting an error: The article type you are searching for has not been deployed

Is there a way through SOQL or Apex through which I can get article type status? Right now there are few articles in environment whose article type status is 'In Development'

SOQL being fired FIND 'direct case to verify api fix' RETURNING Solution (Id,SolutionName,LastModifiedDate,SolutionNote,CreatedById ORDER BY LastModifiedDate DESC), Case(Id,Subject,Description,LastModifiedDate,CreatedById ORDER BY LastModifiedDate DESC), LiSFIntg_stage__non_community__kav (Id,Title, Summary, LastPublishedDate, KnowledgeArticleId,CreatedById, UrlName, LastModifiedDate WHERE PublishStatus = 'Online' AND language = 'en_US' ORDER BY LastPublishedDate DESC), LiSFIntg_stage__Community_Article__kav (Id,Title, Summary, LastPublishedDate, KnowledgeArticleId,CreatedById, UrlName, LastModifiedDate WHERE PublishStatus = 'Online' AND language = 'en_US' ORDER BY LastPublishedDate DESC), LiSFIntg_stage__some_label__kav (Id,Title, Summary, LastPublishedDate, KnowledgeArticleId,CreatedById, UrlName, LastModifiedDate WHERE PublishStatus = 'Online' AND language = 'en_US' ORDER BY LastPublishedDate DESC) LIMIT 100

2
  • can you post your SOQL query Commented Aug 9, 2017 at 16:23
  • @SantanuBoral - added SOQL in the post
    – Sahil
    Commented Aug 9, 2017 at 19:02

2 Answers 2

2

How to achieve this via Apex:

  1. Use MetadataService API

MetadataService class can be downloaded from here: https://github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataService.cls

  1. Use above class in your Apex code to know the status of required Articles.

Example:

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

List<String> articleList = new List<String>{'QnA__kav', 'InstallationGuide__kav'};
List<MetadataService.Metadata> custObjList = service.readMetadata('CustomObject',  articleList).getRecords();

for(MetadataService.MetaData metaData : custObjList) {
    MetadataService.CustomObject custObj = (MetadataService.CustomObject)metaData;
    system.debug('fullName--->' + custObj.fullName + ', deploymentStatus--->' + custObj.deploymentStatus);
}
  1. Add the Remote Site Url to avoid below error:

System.CalloutException: IO Exception: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = https://ap5.salesforce.com/services/Soap/m/38.0

A little further detail on the endpoint url: Endpoint url is formed by MetadataService class using below code:

public String endpoint_x = URL.getSalesforceBaseUrl().toExternalForm() + '/services/Soap/m/38.0';

Here, the endpoint url is eventually the same Salesforce instance url where MetadataService class is placed.

Screenshots to assist further:

enter image description here

enter image description here

enter image description here

enter image description here

1
  • Even though I've added remote site settings as mentioned in point #3, I'm still getting below exception 17:24:15.205 (1631047351)|EXCEPTION_THROWN|[11553]|System.CalloutException: IO Exception: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = https://lisfintg-stage.na55.visual.force.com/services/Soap/m/38.0 Don't understand where it's picking this URL from while URL added under remote site settings is https://na55.salesforce.com
    – Sahil
    Commented Aug 15, 2017 at 7:08
0

You need to use Metadata API to retrieve the status.

Refer ArticleType

deploymentStatus

A string which represents the deployment status of a custom object or field. Valid values are:

  • InDevelopment
  • Deployed

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .