Salesforce SOQL Queries and Tags - salesforce

I'm just getting started with the Salesforce Web Services API and I'm surprised that there isn't an obvious way to do a query for all e.g. Account objects that contain certain tags.
What would you say is the best way to find all objects that contain certain tags?
I imagine it involves a join on Account.id and AccountTag.id or something similar, but despite some real research, I'm not sure how best to solve this problem.
Thanks in advance!
Update: I guess I could do a select from AccountTag and then get the account objects based on ItemId, but the ideal would be to do a query on Account, with Tags being only one part of the criteria.

You can use the SOQL-R style queries to do this, e.g. this will fetch the account Id and account Name for all the accounts with the internet tag.
select item.id, item.name from accountTag where name='internet'
in this case the item relationship is to the account that was tagged, so you can select any field from the account object through the item relationship path.
See the SOQL-R docs for more info

Related

Is there a way to select all Objects in Salesforce that start with a value?

I can select all apex triggers by using
select id, name from ApexTrigger
and classes by using
select id, name from ApexClasses
but is there a way to select all objects ?
I have tried
select id, name from Objects but doesnt seem to work ?
SOQL queries run on exactly one object.
If you need to perform a full-text search across multiple objects, what you need is SOSL, the Salesforce Object Search Language. Note however that SOSL is quite different from SOQL. See the linked developer guide for more information.

firebase firestore nosql design for chat app with groups

I am trying to think of a way to design the firestore db in a way that is efficient.
The main issue I am having with is how I should define "groups". Lets say a user is invited to a group chat and so the client needs to retrieve the data for that group chat, should I have a "groups" collection and then find the correct group document? OR, should I have a "groups" property in the user document that has a id to reference the group to retrieve?
In SQL, having a reference in a user's groups table would be the obvious answer, but I am not sure about firestore. I don't want to look through the entire collection of groups just to find the group that the user was newly invited in. Any tips? Also, my front end is in React and I am considering using the onSnapshot method to subscribe to the collection (that seems to be the best way to have real time updates).
What i believe is best for you is this :
First have a collection, suppose you make groups, and inside that every docuent has all the group unique ids,
And inside that for every group, i.e document, you can have a collection which holds all the chats for that group and group related info , like group type, etc etc
Hope it helps. feel free for doubts

Join User and LoginHistory in SalesForce?

I am unable to get the user information from LoginHistory object.
I tried using this
SELECT User.FirstName FROM LoginHistory
but not it says
INVALID_FIELD:
SELECT User.FirstName FROM LoginHistory
^
ERROR at Row:1:Column:8
Didn't understand relationship 'User' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
System.debug(JSON.serializePretty(LoginHistory.UserId.getDescribe())); shows "null" as the "relationshipName". Not all relations allow going "up" this way, you can check my answer https://salesforce.stackexchange.com/a/23507/799 for some examples.
You'll need to make-do with two separate queries. There's equally no way to reverse it because the related list doesn't have name either. This won't work:
SELECT FirstName,
(SELECT Id FROM LoginHistories LIMIT 10)
FROM User
LIMIT 10
Maybe there's an idea you can upvote? Maybe you'll have more luck with Event Monitoring. Haven't used it personally but my understanding is it can track login, logout, exporting a report... Might be easier to query.

Cakephp - Choose your preferred country for ecommerce

I'm developing an ecommerce website. Now, at the homepage, i want to put the preferred country. When the customer choose their preferred country, the list of product shown to them was from that prefered country only.
My database (products table has id, name, description, color, SKU and country_id)
Anyone has idea about this. I already check for global variable. But its like declaring in core.php or bootstrap.php. I want it to declare at my homepage when customer choose the country.
Please somebody help me. Thanks in advance ;p
I think "Magic Find Types" is a good place to start. You get this functionality automatically from your product Model class.
http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#magic-find-types
Inside your controller, all you probably need to do is type something like this. It also has optional arguments for sorting and result set limiting. Of course, how you retrieve the preferred country is dependent on your application (browser cookie, logged in user profile etc).
$this->Product->findAllByCountryId($countryId)
If your user selects a country, store it in a session or cookie. If you want to be really efficient, you could have users select their preferred country on sign-up and store that in their profile record in the database, and set a configuration variable when they log in.

Compare two views in salesforce

I am looking for a way to compare two views in salesforce. I want to create a visual force page that lets a user select two views associated with the Account object and show all the accounts that appear on both views.
I am struggling pretty hard here, I can't figure out how to get the results from the views, but I am hoping there is a way to get all accounts that match the filters for each view.
Here is my SOQL query:
Select Id, Name, Owner.Name FROM Account WHERE
Id IN ( SELECT AccountId FROM Opportunity WHERE RecordTypeId = :RecordType1ID AND StageName IN :StageOneList )
AND Id IN ( SELECT AccountId FROM Opportunity WHERE RecordTypeId = :RecordType2ID AND StageName IN :StageTwoList )
This is the basis of the VF page I have made so far. It is possible to filter the Account with Account Owner and a drop down list from province. The idea is, many people in the organization have already created views with the accounts filtered as they need it. Instead of including every possible account field as a filter, I would like a drop down list of the active users views associated with Account, and then they can select Opportunity 1 and Opportunity 2 and have a list of Accounts matching.
I assume you mean views as in the available views in the dropdown box on a standard tab for an object? If so I don't believe you can query the results from them directly although you can query the Account object using a SOQL statement where you provide the filter.
My suggestion would be either create a set VF page that has 2 drop downs to switch the SOQL query that is used to return the list of accounts being displayed (would mean you have a set of predetermined views and updates to them require code updates) or give more details of your use case and we may be able to provide other suggestions.
It sounds like you just need to compare the results of the filters here. My suggestion would be that you're really trying to do something that should be done with reports, not with views.
Put two enhancedList components on the page.

Resources