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

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.

Related

How to apply distinct on google datastore using objectify?

I am trying to fetch some entities with distinct values on a property. Say, I have an entity called messages. And it has some properties say personId, typeId, convId, createdTime, etc. I want fetch messages of personId p1 with distinct convIds. How can I do that.
I already referred to
Executing DISTINCT query with objectify for app engine
and some others. And tried something like this.
ofy().load().type(messages.class).limit( 10 ).filter("personId ==", "p1").order("-createdTime").project("convId").distinct(true).list();
I am sure that there are some entities with this combination. But it is fetching no entities.
Please help me with this.
Unfortunately, your query isn't valid. For projection queries you need distinct to be on the values that you are sorting by (i.e. -createdTime). To use distinct you'll need to order by convId.
https://cloud.google.com/datastore/docs/concepts/queries#restrictions_on_queries has more details.

group by rows to get the distinct row using filter in admin-on-rest

Thanks in advance, I wanted to know is it possible to get distinct rows from db using the filter in admin-on-rest.example, for example, I want to show a list of distinct offers running but in my database, I have the duplicate offer, is it possible using filter component in admin on rest.

Displaying multi-subquery, dynamic field, dynamic object SOQL query results on a VF page

I want to pass a SOQL query to a page, or have the users enter it on the page themselves, process it, and then display results in a table.
Biggest problem is displaying the results, as VF dynamic binding only seems to be working one level deep, after that it gives null pointer exceptions (seems to be some bug in SF).
I have a dynamic main object with multiple related lists coming from the query, for example: user may be pulling a list of Accounts, with all related Contacts, and all related Opportunities. Here is an example query:
select id, name, BillingState, (select id, name, title from Contacts), (select id, amount from Opportunities) from Account where name like '%Corp%'
Another time, the query might be on a completely different parent object, like:
select id, name, accountId, (select id, Cost from OpportunityLineItems), (select id, name from Attachments) from Opportunitiy limit 20
It's not a problem parsing the field and object names from the query, but using dynamic binding for displaying those results in a table on a VF page is a nightmare, and is not working for me. Any ideas? or maybe you have seen VF code for this specific situation somewhere?
As a side note, below is the error i keep running into on the VF page when trying to use dynamic binding
Error: java.lang.NullPointerException
Error: null
In these situations I always rely on an object relational mapper pattern, or referred to simply as a wrapper class. For the trickier fields, what you wind up displaying are single level, class member abstractions rather than fields directly from the result of a SOQL statement. One benefit of this is that you can simply do a few SOQL calls, prepare the data in any way that will best support your page and then render it smoothly. The additional work of having this abstraction class pays off very well in the end - imo.
Here's a related post that shows exactly how to do this in Apex. In your case, you would extend on this example to add the values of multiple SObjects to one instance of this "ORM-style" class and then populate a list of instances of it from within Apex. This list of custom object instances becomes perfect food for Visualforce to consume.

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.

Salesforce SOQL Queries and Tags

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

Resources