You need to sign in to do that
Don't have an account?
Nic 121
How to I assign a topic to a question in APEX?
I was wondering if anyone has had any experience assigning a Topic to a record from the Question object before.
Some background
We are currently buiding a custom site using VisualForce and custom JS to essentially provide our own interface to the standard SF community functionality.
The page I'm currently working on is our Q&A page - specifically the page through which customers can post their own Questions to our customer community.
The Goal
The issue is, we need to be able to filter our questions by topic - not just by data category. This must also be achieved purely in APEX without any standard apex components on the VF page.
What has been done so far
So far, I have enabled topics for the question object (under Topics for Objects in SF setup). I have enabled system permissions for the appropriate profiles to create, edit, and assign topics. Yet I keep running into an apex exception when I try to assign the topic to the question.
Attempt 1: Manually insert a record into the TopicAssignment object
In the code, I create and insert a question (and topic if required). This works without any problems. Then I run the following:
I then found a new class in the ConnectApi called Topics which does not yet appear to be documented.
Both of the above errors still occur if the class has sharing off - e.g.
I am hoping to achieve this without having to create a new object as a workaround.
So, I was wondering if anyone else has had this issue? Has anyone succesfully assigned a topic to a question in pure APEX? Can anyone help?
Thank you very much,
Nic
Some background
We are currently buiding a custom site using VisualForce and custom JS to essentially provide our own interface to the standard SF community functionality.
The page I'm currently working on is our Q&A page - specifically the page through which customers can post their own Questions to our customer community.
The Goal
The issue is, we need to be able to filter our questions by topic - not just by data category. This must also be achieved purely in APEX without any standard apex components on the VF page.
What has been done so far
So far, I have enabled topics for the question object (under Topics for Objects in SF setup). I have enabled system permissions for the appropriate profiles to create, edit, and assign topics. Yet I keep running into an apex exception when I try to assign the topic to the question.
Attempt 1: Manually insert a record into the TopicAssignment object
In the code, I create and insert a question (and topic if required). This works without any problems. Then I run the following:
TopicAssignment a = new TopicAssignment(TopicId=t.Id, EntityId=q.Id, NetworkId=n.Id); insert a;This line will throw the following error:
Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Entity ID: id value of incorrect type: 906N00000004EF7IAM: [EntityId]Attempt 2: Use the ConnectApi
I then found a new class in the ConnectApi called Topics which does not yet appear to be documented.
ConnectApi.Topics.assignTopic(networkId question.Id, topic.Id);Using this instead yields the following error:
Failed to assign topic to 906N00000004EFC. Please ensure you have permissions to assign topics for this record.
Both of the above errors still occur if the class has sharing off - e.g.
public without sharing class ClassName { }
I am hoping to achieve this without having to create a new object as a workaround.
So, I was wondering if anyone else has had this issue? Has anyone succesfully assigned a topic to a question in pure APEX? Can anyone help?
Thank you very much,
Nic
Also unfortunately, the solution for a missing SF feature is always the same. Spend money and waste time. In our implementation we ended up adding new indexed string fields on the objects we needed, and used a completely custom end user interface - as the built in functionality didn't come close to what we needed.
So essentially, we had to implement our own Q&A page, without relying on the standard components. This was a pretty big and unnecessary undertaking, but it was the only way. And that of course is only the beginning if you want the topics assigned to integrate with chatter, et al. I'm sorry that I don't have any better news for you.
All Answers
[1] https://developer.salesforce.com/forums/?id=906F0000000MJlTIAW
Thanks for the reply. I'm not too sure what extra steps there may be. If your profile has the system permissions required, then you should be able to add topics to an object by typing in 'Topics for Objects' in the quick search box. I don't recall any extra step.
Does the question object not appear on that page?
I have just realized that there is a Question__c object present added by some managed package, and that may be what I have enabled under topics. If so, this may not be possible without a new object.
I was just wondering, is that UI pictured above standard in SF? If so, how do you access it - it would be great to see which Question object is enabled.
Cheers
[1] https://developer.salesforce.com/blogs/developer-relations/2015/02/using-metadata-api-describe-objects.html
Cheers for the link. I guess that answers it, it's not possible to assign topics to a Question. Also, that metadata page is really useful. Cheers.
Also unfortunately, the solution for a missing SF feature is always the same. Spend money and waste time. In our implementation we ended up adding new indexed string fields on the objects we needed, and used a completely custom end user interface - as the built in functionality didn't come close to what we needed.
So essentially, we had to implement our own Q&A page, without relying on the standard components. This was a pretty big and unnecessary undertaking, but it was the only way. And that of course is only the beginning if you want the topics assigned to integrate with chatter, et al. I'm sorry that I don't have any better news for you.