Is there a possible way to search the name of a lookup fields using the search.query using apex in salesforce? - apex

I had a lookup field on my object and I want to search the name of the lookup using search.query in apex, how can I do this?. In my debug, I am returning nothing. Below is my sample code.
String query = 'FIND \'Sonny McNeil\' IN ALL FIELDS RETURNING ASPHPP__ASPayment_Source__c (Id, Name,ASPHPP__PPContact__r.Name), Contact';
System.debug('query '+query);
List<List<sObject>> searchRecords = Search.Query(query);
System.debug('searchRecords '+searchRecords);
return searchRecords.get(0);

I've found a solution to my problem, it's not possible to use SOQL to search such certain name of a lookup field, all I do is use a sample SQL and add some LIKE condition on my sql and query it to the database and return

Related

jcr sql-2 get node name

i am working on aem 6.3 and would like to get page name
SELECT * FROM [cq:Page] WHERE ISDESCENDANTNODE("/content/Product/Silhouettes/Accessories/Bands/Headband")
If I need to retrieve name of the nodes using sql-2 , how do I achieve it?
You can specify column constraints like title, node name, etc this way -
SELECT nodeSet.name, nodeset.title
FROM [cq:Page] AS nodeSet
WHERE ISDESCENDANTNODE("/content/Product/Silhouettes/Accessories/Bands/Headband")
Note: the query tool in AEM(Tools -> Query) will not list the query results according to the columns you've mentioned, it will only list the node paths.
You can look at using /etc/importers/bulkeditor.html or AEM fiddle tool to visualize the query results based on column constraints.
If you want to achieve this programmatically, you can use the same query as you've mentioned in your question and use javax.jcr.query.* and javax.jcr.Node.* API's to retrieve just about any property from the query result. This article here should help you achieve this programatically.
Use the ResourceResolver API to execute and obtain the query results:
final Iterator<Resource> pagesIterator = resolver.findResources('<your_query_here>', javax.jcr.query.Query.JCR_SQL2);
while (pagesIterator.hasNext()) {
final Resource pageResource = pagesIterator.next();
LOG.info(pageResource.getName());
}
However, please note that if you are using any version higher then CQ 5.6, you should use instead the Page API.
In this case, the listChildren(Filter<Page> filter, boolean deep) method will do the job.
The PageFilter parameter may be used if you want to filter through pages of some kind. So if no extra criteria for your page finding algorithm, your may pass null or a new empty object.
The boolean parameter: if false it returns only direct child pages, and if true would list all the descendant pages of the given page.
Therefore, the equivalent solution of the SQL Query which would provide you the same end results would be:
Iterator<Page> rootPageIterator = rootPage.listChildren(null, true);

Where can I find the 'project name' in the openERP database?

I have access to the database using postgreSQL. There are over 300 tables to look through, and I can't seem to find where to get the project name for a query I want to run. In 'project_task' there is a 'task_name' field. In 'project_phase' there is a 'phase_name' field. But in 'project_project' there doesn't seem to be a 'project_name' field. Seems a bit odd.
project_project does not have a name field. Instead it uses inheritance at the ORM level to get a name from account_analytic_account.
Using SQL, your query will need to join project_project to account_analytic_account using analytic_account_id and get the name field off that table.

Linq To Entities - How to create a query where the table name is a parameter

Dynamic queries are not dynamic enough. I have seen solutions like this but still I have to indicate which table to use as the basis:
var query = db.Customers.Where("...").OrderBy("...").Select("...");
I want to create a simple query tool where the user will select from available tables using a drop-down list. As the result, I want to show first few records. Therefore, I need to change the table too! That is, I need something like this:
string selectedTable = "Customers";
var [tableName] = SomeTypecastingOperations(selectedTable);
var query = db.[tableName].Where("...").OrderBy("...").Select("...");
Is EF dynamic enough to handle this?
Linq-to-entities doesn't support that. You can achieve that with Entity SQL or some ugly code which will have conditional logic for every set you want to query (like a big switch for table names).

How to search the input keyword with all the fields of a table

Hi am developing my first grails application now i want to put search method in my application.. Is it possible to match the single entered keyword with all the fields of the table.Like when i use findById it will search only on id or if i use findByName it will search only on name or findByDescription find only on description..
Is it possible to use findall or findBy* to match with all the fields like id, name, description..
If you are using a RDBMS, you can issue a query on the following lines:
SELECT .... FROM .... WHERE name like '%value%' OR description like '%value%' OR id like '%value%'
But this is going to be very inefficient. You can instead use a full text search API lucene/ solr and index entire content as part of one field and issue queries on that.

Writing a query with ORMLite

How can I write a query with ormlite instead of using .create or any other thing like that? Can you please show me how for this simple example :
SELECT name FROM client
EDIT since I can't answer myself :
I guess I had to search a little more , anyway I found how to do it with the QueryBuilder like this :
newDao.query(newDao.queryBuilder().where.eq("name",valueofname)
If someone knows how to write the full query that would be great , otherwise , I'll stick with this solution
How can I write a query with ormlite instead of using .create or any other thing like that?
Goodness, there are tons of documentation about how to do this on the ORMLite site. Here's the section on the query builder.
I'm not sure what you mean by "full query" but your example will work with some tweaks:
List<...> results = newDao.queryBuilder().where().eq("name",valueofname).query();
It does not make sense to just return the name since the Dao hierarchy is designed to return the specific Client object. If you just want the name the you can specify the name column only to return:
... clientDao.queryBuilder().selectColumns("name").where()...
That will return a list of Client objects with just the name field (and the id field if it exists) extracted from the database.
If you just want the name strings then you can use the RawResults feature.