Data Category Visibility Issue - salesforce

I am facing Data Category visibility related issue.
The scenario is i'm following -
I have One Community User which one is using for login into my community.
This User's role is Inheriting Visibility for Category Group from it's parant role and it's Visibility is No categories are visible to parent role and subordinates.
But This User's Permission set have Custom Visibility Permission is like -
All Category Group > child Category > sub child Category
for ex :
All Products > Computers > Laptops
And I am accessing lick bellow query from apex to display related article in community.
Select Id, Title, KnowledgeArticleId, Summary, CreatedDate, UrlName From KnowledgeArticleVersion WHERE Language = 'en_US' and PublishStatus='Online' WITH DATA CATEGORY Products at (Computers__c) limit 10 UPDATE VIEWSTAT
but I am not getting any articles.
getting error like --
Invalid data category name provided: Products. There is no data category matching the given developer name on the data category group: Computers__c
If anyone have solution for this please let me know.
Thank you,
Harsiddhi.

You probably have already figured this out by now, however you need to use the API name for your Group as well, i.e. 'Products' becomes 'Products__c'.
Should be something more like this:
Select Id, Title, KnowledgeArticleId, Summary, CreatedDate, UrlName From KnowledgeArticleVersion WHERE Language = 'en_US' and PublishStatus='Online' WITH DATA CATEGORY Products__c at (Computers__c)

Queries are not dependent on permission sets.
The error in the SOQL query can be looked upon at the query editor. Whenever there is a wrong API name in the query, there comes down an indication in the Query Editor under Developer Console that:
No such column 'field_name' on entity
Thus we can look back at the object fields and relationships and can ensure if the right API name is there.

Related

Query of Arrays in Salesforce

I need to do 1 of two things (I believe):
1- Get a Custom Object ID so I can query it directly
2- Get a list of values of a specific field within the Object entries.
Ultimate End goal:
Add and modify rows in my custom object via external API. However to do this I need to check and make sure my new entry/row does not already exist.
What I have:
I have a custom object (called Customer_Arrays__c). It is a table that I can add new rows to (I will call entrys). Each entry has 6 or 7 fields. 1 of these fields is called (external_ID__c). This is the field I utilize to match to new incoming data to see if the entry already exists, or if it needs to add a new row to my table. This Customer_Arrays__c is a child to my opportunity I believe – it is part of every opportunity and each line item I add has a field defaulted to the opportunity.
Help I need:
1- How do I query the value of my Cutomer_Arrays__c based upon an opportunity ID?
2- How do I query a list of values in my (external_ID__c) based upon an opportunity ID?
Thanks for your help! I have read half a dozen+ posts on similar topics and am missing something. Examples of some Past try's that failed:
Select external_ID__c,FROM Custom_Arrays__c WHERE Opportunity='00...'
Select Id (Select ID, Custom_Arrays__c from Custom_Arrays__c) from Opportunity where id ='00...'
List FROM Custom_Arrays__c WHERE Opportunity='00...'
Select Id, external_ID__c, (Select external_ID__c FROM Custom_Arrays__c) WHERE Opportunity__c='00...'
Thanks again!
Only you know how did you name the lookup field (foreign key) from arrays to Opportunity. You'll need to check in setup, next to where external_ID__c is. Since it's a custom field (gets __c at the end), my guess is you went with default.
Try
SELECT Id, Name, External_Id__c
FROM Customer_Arrays__c
WHERE Opportunity__c = '006...'
Thank you eyescream, that got me almost all the way there. Turns out I also needed a __r for the parent child relationship.
Here is a snip out of my final code that works - I think it covers everything:
SELECT Field1__c, Opportunity__r.Id, Opportunity__r.Opportunity__c,
FROM Customer_Arrays__c
WHERE Opportunity__r.Id = '006...'.
Thank you so very much!!!

How to query for User Display Name using LisData.svc SharePoint Online

As you know when using the listdata.svc people picker fields return the userID, not the display name (createdby, modifiedby). I have been looking for a way to query the userprofile svc but have found nothing helpful.
What i am looking to do, is simply convert this ID to their respected display name. I am new to using this listsvc and this was never and issue using empty data views and XSL. If anyone has an example of grabbing list data, and showing the createdby, modifiedby, or a custom people picker field and showing their name not id that would be very helpful.
Thanks in advance
This is a default behavior, for a user field, only Id property is getting returned in the result. To return all the properties of user field $expand query options needs to be applied to the query, for example:
/_vti_bin/ListData.svc/Documents?$expand=CreatedBy,ModifiedBy
In that case the projected field values for CreatedByand ModifiedBy fields (from User Information List) are returned along with the result.
To return a specific user field properties, the $select query option could be specified. For example, the following query returns DisplayName (Title property) of CreatedBy and ModifiedBy fields:
/_vti_bin/ListData.svc/Documents?$select=CreatedBy/Title,ModifiedBy/Title&$expand=CreatedBy,ModifiedBy

How to get account and contact of a particular case using soql query in salesforce?

I want to show accounts and contacts data of a particular case in a form. how can i query the same using soql query in salesforce.
I have a custom object named Work_Order__c which is having a master-detail relationship with CASE object.
I am trying to write a below mentioned query, but the inner query is giving error.
select Id,Case__r.CaseNumber,Case__r.Description,Name,
Status__c,Priority__c,Description__c,City__c,Street__c,Zip__c,
(select Case__r.Account.Name, Case__r.Contact.Name from Work_Orders__r)
from Work_Order__c where Id = 'a024B0000025L6G'
The inner query is giving you an error because Work_Orders__r isn't a table. It is syntactic-sugar that gives you the list of all Work_Orders that are associated with a Case.
What you probably want is something like this:
SELECT Id,Name,Status__c,Priority__c,Description__c,City__c, Street__c,Zip__c,
Case__r.CaseNumber, Case__r.Description,
Case__r.Contact.FirstName,Case__r.Contact.LastName,Case__r.Contact.<Other_Contact_Fields>,
Case__r.Account.Name, Case__r.Account.<Other_Account_Fields>
FROM Work_Order__c
WHERE Id = 'a024B0000025L6G';
My other recommendations is to avoid hard coding your Id.

How to query all task which are having relatedto(whatId) as Account or Contact

I am using an soql query to get tasks. My requirement is to get all tasks which are related account or contact object. Also few other fields inside Account or contact object whichever the object related. Is there a simple way instead of writing multiple queries.
Please provide more specific information next time. Generally speaking you can refer to a parent object by reference name followed with a dot. Here is an example
Select Account.Name, AccountId From Task Where Account.Name = 'John'
Here Account is the name of the reference (from task) and AccountId is the referencing field.
Your question is a little unclear. Are you looking for all TASKS related to any ACCOUNT or CONTACT or related to specific ACCOUNTS or CONTACTS?
If the former, try
SELECT Id, Subject,
FROM TASK
WHERE
What.Type = 'Account' OR
Who.Type = 'Contact'
if the latter, use the IN :list syntax already suggested by Moti. The What.Type is useful, as opposed to AccountId!=null, because it will not return TASKS associated with, for example, OPPORTUNITIES (if you want that behavior, use AccountId!=null and maybe drop the Who.Type if you associate all CONTACTS with OPPORTUNITIES, as it would be redundant).
In either case, your issue will be pulling specific data from CONTACT whos, as polymorphic fields only allow access to a limited number of fields. Can't seem to find that list right now. I don't believe old SOQL supports the kind of the syntax to do that in one query--that's why SOQL polymorphism made such a bang--though I could be wrong.
Now, if you have SOQL TYPEOF available to you, you should be able to do something more interesting like:
SELECT Id, Subject,
TYPEOF What
WHEN Account THEN AccountNumber
END,
TYPEOF Who
WHEN Contact THEN FirstName
END
FROM Task
WHERE
What.Type = 'Account' OR
Who.Type = 'Contact'
How about
select {column list] from task where parentid in (select id from account where ...) or parentid in (select id from contact where ...)
Alternatively, if you're inside Apex and already have the contact or account ids in a list (we'll use idList), you can use:
select {column list] from task where parentid in :idList

SOQL query to traverse several levels on Task

I'm trying to write some apex code using this query and not getting anywhere:
List<Task> tasks = [SELECT id, whatid, who.account.parent.name FROM task WHERE who.account.parent.name LIKE 'Procter%'];
I'm not surprised this doesn't work, but can't seem to find documentation anywhere that explains how I would go about this. Does anyone have any idea? I'm trying to get all tasks linked to a contact linked to an account with a parent account of "procter and gamble"...
Looks like the options to "go up" in the mixed fields (the ones where Lookup goes to multiple objects like WhatId going to Account or Opportunity) are very limited. I was able to write "WHERE what.name LIKE 'Procter%' but not "WHERE what.parent.name LIKE 'Procter%'".
By the way I think it should be WhatId and not the WhoId (check out the Validation Rule editor for Tasks, try to insert fields "Contact/Lead ID" and "Opportunity/Account ID"). You will also see that you can't "go up" (or in case of this editor - "go right") on these fields while for some other fields you can explore the relation like for "CreatedBy.UserRole.Name".
Can you try this subquery instead?
[SELECT id, whatid FROM task WHERE whatid IN (SELECT Id FROM Account WHERE Parent.Name LIKE 'United%')]
WhatId and WhoID are polymorphic fields, so these fields do not support traversing multiple levels.
I had a similar requirement for hierarchal traversing, in my case i had to select the lead information associated with a task. What I had to do was first query for a list of tasks, then query for a list of leads based off those tasks, then use a wrapper class to combine the two lists into a custom object and display the object accordingly using visualforce. The wrapper class was certainly my answer to the equation since it seems you are in fact unable to query directly using the Who.Id.
Hope this helps!
The AccountID field on Tasks is populated by SF automatically for Contacts. Obviously, it is blank for Leads. So, if you want to get Account data you can just do something like this:
SELECT ID, Who.FirstName, Who.LastName, Account.Parent.Name FROM Task WHERE WhoID = '00Q12SDFUUALDLKJF'
Obviously, Account.Parent.Name is blank for Leads.

Resources