• JonReeves
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 12
    Replies

Hey I still struggling writing a Parent-Child query for the Content object...

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_erd_content.htm#sforce_api_erd_content

 

I'm trying to Return the ContentVersion Fields WHERE its Parent (ContentDocument) is in a particular Workspace...

I belive I need to access 3 tables.. ContentWorkspaceDoc, ContentDocument, ContentVersion. But I cannot seem to form a working SOQL that accesses these tables in one query. Can anyone help?

 

I consistently get an error: Didn't understand relationship 'ContentWorkspaceDoc'

 

When I look up the object it doesn't note a relationship name for the Joins, but the Diagram I posted above clearly shows there is a relationship.

I've got one main objective:

To Return all Content Documents (latest version) which the user should have access to (based on the Public Group assignment to a Library).

 

Any ideas how these tables co-exist and what method would you use to achieve the end result.

 

I could hardcode a list of Library IDs and try and build a relational SOQL which would only bring back DocumentVersions in those Libraries, kinda like...:

SELECT
	ContentVersion.Id, ContentVersion.Title
FROM
	ContentVersion
WHERE
	ContentDocument.id = ContentVersion.ContentDocumentId
	AND
		ContentWorkspaceDoc.ContentDocumentId = ContentDocument.Id
	AND
		(ContentWorkspaceDoc.ContentWorkspaceId = 1
		OR ContentWorkspaceDoc.ContentWorkspaceId = 2
		OR ContentWorkspaceDoc.ContentWorkspaceId = 3)
GROUP BY
	ContentVersion.Id

 

but I'd rather beable to fetch dynamically based on which libraries we give the user access to (via Public Groups). I can't however find how Public Groups and Libraries relate (Groups and ContentWorkspaces).

 

Any ideas?

I'm trying to query all KnowledgeArticleVersions but return back thier Vote and View Stats.

 

Here is the Relational Diag:

http://www.salesforce.com/us/developer/docs/api/Content/images/174/freeze/core/en/xmlsource/dev_guides/api/images/Sforce_knowledge_objects.png

 

However when I Describe the KnowledgeArticle there is no RelationshipName for KnowledgeArticleVersion... any ideas how I can query across these 4 tables?

 

This works to bring back any Article:

SELECT Id, (SELECT NormalizedScore FROM VoteStats WHERE Channel = 'Csp'), (SELECT NormalizedScore FROM ViewStats WHERE Channel = 'Csp') FROM KnowledgeArticle

 But I want to restrict the results with:

SELECT Title FROM KnowledgeArticleVersion WHERE PublishStatus = 'Online' AND Language = 'en_US'

 

 Cheers,

J

So I have a VF page which renders as JSON, but I can't do any AJAX requests to it, because everytime I fetch the address:

https://c.na1.visual.force.com/apex/pageName

it gets rewritten as:

https://na1.salesforce.com/visualforce/session?url=https://c.na1.visual.force.com/apex/pageName

 

The redirect kills any AJAX methods I try.

 

Any suggestions? I'm curious if there is another way I can reach the VF page.. a static link or something.

I posted this in the Apex Class secdtion, but realised it might be better here....I'm hoping this is a simple syntax question.

 

I'm trying to find a way I can pass a variable from a VF Page to an extensionController. I was expecting it to be something like:

{!myClass(variable)} or {!myClass, variable} but I'm not seeing it referenced anywhere like this.

 

Basically I'm trying to build a table in my VF page, to show all the KnowledgeArticles we have, I'd like to add 2 columns to display the NormalizedScore of both the Views and the Votes, so I figured I have to write a extensionClass, however because the VF Page is a list of Articles I don't have access to the Id param in the page to build a SOQL off of. I figured I could call something like... <apex:outputText value="{!myClass, article.Id}" /> passing the Id over to myClass and allowing me to find the Vote/View. The context of this line.

 

the context of that line would be this:

    <apex:outputPanel layout="block"> 
        <table>
            <tr>
                <th>Article Title</th>
                <th>Type</th>
                <th>Ratings</th>
                <th>Most Viewed</th>
            </tr>                
            <knowledge:articleList articleVar="article" sortBy="mostViewed" pageSize="100" pageNumber="1" keyword="{!$CurrentPage.parameters.search}" articleTypes="{!$CurrentPage.parameters.types}">
                <tr>
                    <td>
                        <a href="{!URLFOR($Action.KnowledgeArticle.View, article.id)}">{!article.title}</a>
                        <p>{!article.summary}</p>
                    </td>
                    <td>{!article.articleTypeLabel}</td>
                    <td><apex:outputText value="{!myClass, article.id}" /></td>
                    <td></td>
                </tr>
            </knowledge:articleList>
        </table>
    </apex:outputPanel>

 thanks for any advice.

J

I'm hoping this is a simple syntax question.

 

I'm trying to find a way I can pass a variable from a VF Page to an extensionController. I was expecting it to be something like:

{!myClass(variable)} or {!myClass, variable} but I'm not seeing it referenced anywhere like this.

 

Basically I'm trying to build a table in my VF page, to show all the KnowledgeArticles we have, I'd like to add 2 columns to display the NormalizedScore of both the Views and the Votes, so I figured I have to write a extensionClass, however because the VF Page is a list of Articles I don't have access to the Id param in the page to build a SOQL off of. I figured I could call something like... <apex:outputText value="{!myClass, article.Id}" /> passing the Id over to myClass and allowing me to find the Vote/View. The context of this line.

 

the context of that line would be this:

    <apex:outputPanel layout="block"> 
        <table>
            <tr>
                <th>Article Title</th>
                <th>Type</th>
                <th>Ratings</th>
                <th>Most Viewed</th>
            </tr>                
            <knowledge:articleList articleVar="article" sortBy="mostViewed" pageSize="100" pageNumber="1" keyword="{!$CurrentPage.parameters.search}" articleTypes="{!$CurrentPage.parameters.types}">
                <tr>
                    <td>
                        <a href="{!URLFOR($Action.KnowledgeArticle.View, article.id)}">{!article.title}</a>
                        <p>{!article.summary}</p>
                    </td>
                    <td>{!article.articleTypeLabel}</td>
                    <td><apex:outputText value="{!myClass, article.id}" /></td>
                    <td></td>
                </tr>
            </knowledge:articleList>
        </table>
    </apex:outputPanel>

 thanks for any advice.

J

Just got through my first testMethod with 100% Code Coverage. However when I try and deloy it tells me:

"Average test coverage across all Apex Classes and Triggers is 66%, at least 75% test coverage is required."

 

Anyone stumble across this before?

 

cheers,

Jon

So I'm going through the process of customizing our Customer Portal in SF.

 

In the case of a Knowledge Article, I've successfully located where to assign a built VF page.. ( Setup > Knowledge > Article Types > {select article} > Channel Displays > Customer Portal > {select VF Page} ). My custom VF page appears as it should for chosen Article Type when a Portal user clicks on a Knowlegde Article when viewing the Knowledge Tab.

 

In the case of everything else, I'm at a loss where I go to customize pages. For example, where to I find the VF page that shows the Knowledge List / Homepage, or Cases or Content etc... I found this document:

https://na1.salesforce.com/help/doc/en/salesforce_pkb_implementation_guide.pdf

 

On Page 11, it references a few VF Pages and a Class that I cannot find in our instance of SF... KnowledgeHome, KnowledgeProduct, KnowledgeSearch and KnowledgeLayout. The class is called KnowledgeController. Or where they are referenced, so I can reference my Own VF page in place of them for the Customer Channel Display.

 

I realise that I could put alot of CSS into the Header of the Portal to override the page's layout and style, but any change made by SF in the future might cause problems.

 

I assume that every section of the portal can have a custom VF page built for it, I'm just not sure where I assign these pages to make them visible to the Portal user.

 

Any help would be great.

cheers,

Jon

Hey Guys,

I ran into a problem a few weeks back (still waiting on support... level3 now) with the ArticleRenderToolBar element of VF. I'm wondering if anyone else has this problem, or can offer a clue to what I might be doing wrong, or if its really a bug?

 

So we built a really simple VF page (for a knowledge article) to test the RatingBar control. The only line it had (other than the require page etc.. ones) in it was this (taken from a SF guide pdf):

<knowledge:articleRendererToolBar articleId="{!$CurrentPage.parameters.id}" canVote="true" showChatter="false" />

 

I've tried various attribute combinations, but I've not beable to get the Voting stars to function... If I inspect the Page in Chrome I note a 404 error finding /vote/. However if I utilize the default salesforce article display (i.e.. not a custom VF page), then the ratingbar works and these is no 404 error, infact the requested address isn't /vote/ its something like /123456789/vote.js

 

Is anyone else having this problem, or am I using the code incorrectly?

 

I should note that the Bar actually displays the correct Article info when you expand it, so the ID passed is correct (which was my first worry). 

 

cheers for any advice.

Jon

Hey guys,

we've recently started implementing SF, and I'm helping out with the VF pages and Apex Classes. My background is mainly web development, but have struggled through the Apex Class parts of this process. During the trial I wrote a class that we were able to utilize, However since going live I've been introduced to the Sandbox and TestMethod steps.

 

I spent the best part of yesterday wrestling with my Class, trying to build some testMethods to cover the code. I understand the importance of this and want to do it properly however I've ran into a few issues that I was hoping I might get help on.

 

I should note that the class works absolutely fine, I'm just unable to edit it in any way until I can write a testMethod that works.

 

First some info... I've written an extension class for an Article Type (Knowledge) standard controller. It is currently implemented like so:

public class queryDocument{
     
    public queryDocument(ApexPages.StandardController stdController) {
    }

}

 This appeared to be the accepted way to get an extension written.

 

So my questions are as follows:

  1. How do I get access to the Record's Fields in the Class without using: "ApexPages.currentPage().getParameters().get('id');" and running a SOQL for each method.
  2. Or How can I write a testMethod (within this Class) to spoof the CurrentRecord / or Page... I think I've got this done, but wanted to check
    // Do an Insert
    List<Virtual_Support_Team__kav> testList = new List<Virtual_Support_Team__kav>{};
    Virtual_Support_Team__kav testItem = new Virtual_Support_Team__kav(Title = 'TestTitle', UrlName = 'TestTitle', Section_Code__c = 'TestCode', Product__c = 'TestProduct');
    testList.add(testItem);
    Insert testList;
    // Retrieve Insert
    List<Virtual_Support_Team__kav> insertedItem = [SELECT Title, Id, KnowledgeArticleId FROM Virtual_Support_Team__kav WHERE Id IN :testList];
    
    // Set ID
    PageReference testPage = new PageReference('/apex/VirtualSupportTeam?id='+insertedItem[0].KnowledgeArticleId ); 
    Test.setCurrentPage(testPage);
  3. Lastly my main problem/question... The KnowledgeArticleVersion table (which is what is the model used when requesting custom object Virtual_Support_Team__kav), requires that your SELECT includes a PublishStatus and Language condition (WHERE). The problem is, any INSERT done via the API by default gets the PublishStatus = Draft, and you cannot set this to Online, which is the condition I SELECT based on in my code. How can I ever get the testMethod to cover these portions of code? An example of my code is below:
    /**[ Video Content from Guide Article ]********************/
    public List<ContentVersion> getVideoContentFromGuide() {
    	// Get Article ID
    	String articleId = ApexPages.currentPage().getParameters().get('id');
    	
    	// Get current Article Details
    	List<Virtual_Support_Team__kav> art = new List<Virtual_Support_Team__kav>();
    	art = [SELECT Section_Code__c, Product__c FROM Virtual_Support_Team__kav WHERE KnowledgeArticleId = :articleId AND PublishStatus = 'Online' AND Language = 'en_US'];
    
    	// Prepare Related List Object
    	List<ContentVersion> videos = new List<ContentVersion>();
    			
    	//Handle no Article
    	if (art.size() != 0){
    		// Build Search Term
    		String searchTerm = art[0].Product__c + '%Training Video%[%' + art[0].Section_Code__c + '%]%';
    		
    		// Look for Video Content
    		videos = [SELECT Id, ContentDocument.title, ContentDocument.LatestPublishedVersionId, ContentUrl, FileType FROM ContentVersion WHERE ContentDocument.Title LIKE :searchTerm AND PublishStatus = 'P' AND isLatest = true LIMIT 1];
    	}
    	
    	// List of Video from Content Library
    	return videos;      
    }

Any advice would be greatly appreciated. As I'm at a bit of a loss.

cheers,

Jon

Hey I still struggling writing a Parent-Child query for the Content object...

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_erd_content.htm#sforce_api_erd_content

 

I'm trying to Return the ContentVersion Fields WHERE its Parent (ContentDocument) is in a particular Workspace...

I belive I need to access 3 tables.. ContentWorkspaceDoc, ContentDocument, ContentVersion. But I cannot seem to form a working SOQL that accesses these tables in one query. Can anyone help?

 

I consistently get an error: Didn't understand relationship 'ContentWorkspaceDoc'

 

When I look up the object it doesn't note a relationship name for the Joins, but the Diagram I posted above clearly shows there is a relationship.

I've got one main objective:

To Return all Content Documents (latest version) which the user should have access to (based on the Public Group assignment to a Library).

 

Any ideas how these tables co-exist and what method would you use to achieve the end result.

 

I could hardcode a list of Library IDs and try and build a relational SOQL which would only bring back DocumentVersions in those Libraries, kinda like...:

SELECT
	ContentVersion.Id, ContentVersion.Title
FROM
	ContentVersion
WHERE
	ContentDocument.id = ContentVersion.ContentDocumentId
	AND
		ContentWorkspaceDoc.ContentDocumentId = ContentDocument.Id
	AND
		(ContentWorkspaceDoc.ContentWorkspaceId = 1
		OR ContentWorkspaceDoc.ContentWorkspaceId = 2
		OR ContentWorkspaceDoc.ContentWorkspaceId = 3)
GROUP BY
	ContentVersion.Id

 

but I'd rather beable to fetch dynamically based on which libraries we give the user access to (via Public Groups). I can't however find how Public Groups and Libraries relate (Groups and ContentWorkspaces).

 

Any ideas?

So I have a VF page which renders as JSON, but I can't do any AJAX requests to it, because everytime I fetch the address:

https://c.na1.visual.force.com/apex/pageName

it gets rewritten as:

https://na1.salesforce.com/visualforce/session?url=https://c.na1.visual.force.com/apex/pageName

 

The redirect kills any AJAX methods I try.

 

Any suggestions? I'm curious if there is another way I can reach the VF page.. a static link or something.

I posted this in the Apex Class secdtion, but realised it might be better here....I'm hoping this is a simple syntax question.

 

I'm trying to find a way I can pass a variable from a VF Page to an extensionController. I was expecting it to be something like:

{!myClass(variable)} or {!myClass, variable} but I'm not seeing it referenced anywhere like this.

 

Basically I'm trying to build a table in my VF page, to show all the KnowledgeArticles we have, I'd like to add 2 columns to display the NormalizedScore of both the Views and the Votes, so I figured I have to write a extensionClass, however because the VF Page is a list of Articles I don't have access to the Id param in the page to build a SOQL off of. I figured I could call something like... <apex:outputText value="{!myClass, article.Id}" /> passing the Id over to myClass and allowing me to find the Vote/View. The context of this line.

 

the context of that line would be this:

    <apex:outputPanel layout="block"> 
        <table>
            <tr>
                <th>Article Title</th>
                <th>Type</th>
                <th>Ratings</th>
                <th>Most Viewed</th>
            </tr>                
            <knowledge:articleList articleVar="article" sortBy="mostViewed" pageSize="100" pageNumber="1" keyword="{!$CurrentPage.parameters.search}" articleTypes="{!$CurrentPage.parameters.types}">
                <tr>
                    <td>
                        <a href="{!URLFOR($Action.KnowledgeArticle.View, article.id)}">{!article.title}</a>
                        <p>{!article.summary}</p>
                    </td>
                    <td>{!article.articleTypeLabel}</td>
                    <td><apex:outputText value="{!myClass, article.id}" /></td>
                    <td></td>
                </tr>
            </knowledge:articleList>
        </table>
    </apex:outputPanel>

 thanks for any advice.

J

Just got through my first testMethod with 100% Code Coverage. However when I try and deloy it tells me:

"Average test coverage across all Apex Classes and Triggers is 66%, at least 75% test coverage is required."

 

Anyone stumble across this before?

 

cheers,

Jon

Hey Guys,

I ran into a problem a few weeks back (still waiting on support... level3 now) with the ArticleRenderToolBar element of VF. I'm wondering if anyone else has this problem, or can offer a clue to what I might be doing wrong, or if its really a bug?

 

So we built a really simple VF page (for a knowledge article) to test the RatingBar control. The only line it had (other than the require page etc.. ones) in it was this (taken from a SF guide pdf):

<knowledge:articleRendererToolBar articleId="{!$CurrentPage.parameters.id}" canVote="true" showChatter="false" />

 

I've tried various attribute combinations, but I've not beable to get the Voting stars to function... If I inspect the Page in Chrome I note a 404 error finding /vote/. However if I utilize the default salesforce article display (i.e.. not a custom VF page), then the ratingbar works and these is no 404 error, infact the requested address isn't /vote/ its something like /123456789/vote.js

 

Is anyone else having this problem, or am I using the code incorrectly?

 

I should note that the Bar actually displays the correct Article info when you expand it, so the ID passed is correct (which was my first worry). 

 

cheers for any advice.

Jon

Hey guys,

we've recently started implementing SF, and I'm helping out with the VF pages and Apex Classes. My background is mainly web development, but have struggled through the Apex Class parts of this process. During the trial I wrote a class that we were able to utilize, However since going live I've been introduced to the Sandbox and TestMethod steps.

 

I spent the best part of yesterday wrestling with my Class, trying to build some testMethods to cover the code. I understand the importance of this and want to do it properly however I've ran into a few issues that I was hoping I might get help on.

 

I should note that the class works absolutely fine, I'm just unable to edit it in any way until I can write a testMethod that works.

 

First some info... I've written an extension class for an Article Type (Knowledge) standard controller. It is currently implemented like so:

public class queryDocument{
     
    public queryDocument(ApexPages.StandardController stdController) {
    }

}

 This appeared to be the accepted way to get an extension written.

 

So my questions are as follows:

  1. How do I get access to the Record's Fields in the Class without using: "ApexPages.currentPage().getParameters().get('id');" and running a SOQL for each method.
  2. Or How can I write a testMethod (within this Class) to spoof the CurrentRecord / or Page... I think I've got this done, but wanted to check
    // Do an Insert
    List<Virtual_Support_Team__kav> testList = new List<Virtual_Support_Team__kav>{};
    Virtual_Support_Team__kav testItem = new Virtual_Support_Team__kav(Title = 'TestTitle', UrlName = 'TestTitle', Section_Code__c = 'TestCode', Product__c = 'TestProduct');
    testList.add(testItem);
    Insert testList;
    // Retrieve Insert
    List<Virtual_Support_Team__kav> insertedItem = [SELECT Title, Id, KnowledgeArticleId FROM Virtual_Support_Team__kav WHERE Id IN :testList];
    
    // Set ID
    PageReference testPage = new PageReference('/apex/VirtualSupportTeam?id='+insertedItem[0].KnowledgeArticleId ); 
    Test.setCurrentPage(testPage);
  3. Lastly my main problem/question... The KnowledgeArticleVersion table (which is what is the model used when requesting custom object Virtual_Support_Team__kav), requires that your SELECT includes a PublishStatus and Language condition (WHERE). The problem is, any INSERT done via the API by default gets the PublishStatus = Draft, and you cannot set this to Online, which is the condition I SELECT based on in my code. How can I ever get the testMethod to cover these portions of code? An example of my code is below:
    /**[ Video Content from Guide Article ]********************/
    public List<ContentVersion> getVideoContentFromGuide() {
    	// Get Article ID
    	String articleId = ApexPages.currentPage().getParameters().get('id');
    	
    	// Get current Article Details
    	List<Virtual_Support_Team__kav> art = new List<Virtual_Support_Team__kav>();
    	art = [SELECT Section_Code__c, Product__c FROM Virtual_Support_Team__kav WHERE KnowledgeArticleId = :articleId AND PublishStatus = 'Online' AND Language = 'en_US'];
    
    	// Prepare Related List Object
    	List<ContentVersion> videos = new List<ContentVersion>();
    			
    	//Handle no Article
    	if (art.size() != 0){
    		// Build Search Term
    		String searchTerm = art[0].Product__c + '%Training Video%[%' + art[0].Section_Code__c + '%]%';
    		
    		// Look for Video Content
    		videos = [SELECT Id, ContentDocument.title, ContentDocument.LatestPublishedVersionId, ContentUrl, FileType FROM ContentVersion WHERE ContentDocument.Title LIKE :searchTerm AND PublishStatus = 'P' AND isLatest = true LIMIT 1];
    	}
    	
    	// List of Video from Content Library
    	return videos;      
    }

Any advice would be greatly appreciated. As I'm at a bit of a loss.

cheers,

Jon