2022 Developer Survey is open! Take survey.

New answers tagged

0 votes

Select maximum of 2 columns

You could create a formula field on the Contract that would return the max of the two dates, then use that in your report. IF(start_date>end_date, start_date, end_date)
user avatar
  • 645
0 votes
Accepted

Select maximum of 2 columns

No. This is valid in SQL, but not SOQL. You can take the individual max of each field, but you must compare those values on the client.
user avatar
  • 430k
1 vote

SOQL queries Where Clause given Error UNEXPECTED Token

In SOQL and SOSL, we cannot compare 2 fields to one another, so Name = CBProgramInformation__r is invalid syntax. Beyond that, both instances you have of CBProgramInformation__r are incorrect. The __r ...
user avatar
  • 46.8k
2 votes

Speed up REST SOQL Query

Few ways to speed up querying lots of records in batch api. Split the SOQL into batches If the predicate of your SOQL is temporal and if you know the range, you can split the range into multiple ...
user avatar
  • 1,479
1 vote

Speed up REST SOQL Query

You may want to utilize built-in compression modules. https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_rest_compression.htm
user avatar
2 votes
Accepted

rest api SOQL Query max records

The batchSize limit (200-2000) will be applied to a REST API query. Note that this is a "suggestion" to the server; it may alter the batch size if there are many fields or large fields that ...
user avatar
  • 430k
1 vote

Related Territory object field not fetched with the fields of User Territory Association object. (child to parent relationship query)

Confirmed this query works: SELECT Territory2Id, UserId, RoleInTerritory2, IsActive FROM UserTerritory2Association WHERE User.Name = 'ABC' AND Territory2.Name = 'ABC' // (can use User or Territory2) ...
user avatar
  • 11
1 vote

rest api SOQL Query max records

Does this still have the same limitation of no more than 50,000 records overall. No. The 50,000 SOQL row limit applies to Apex transactions. It does not apply to queries executed via the REST API.
user avatar
  • 86.1k
0 votes

SOQL query Contacts x Campaigns by filter with Events on the Contacts

You can't do this in single SOQL statement. You will need to write Apex with at least two queries and some collections (Maps, Sets and/or Lists) to build the additional queries and to relate the ...
user avatar
  • 6,320
1 vote

No profiling information for SOQL operations (Apex Class in Profile)

Here is the issue. Per @sfdcfox. We had action.setSTorable() as part of the call out to the apex method. It's unclear to me the mechanism that was causing this to fail, but the primary reason is that ...
user avatar
  • 1,258
0 votes

SOQL query Contacts x Campaigns by filter with Events on the Contacts

You are using a Relationship Query already to select the related Event records. You can do the same to get to the related Campaign records however there is one important caveat - the Contact <-> ...
user avatar
2 votes

Dynamic SOQL, LIKE and Apostrophes

If you are using : to embed the value into the SOQL query, then it handles the escaping of special characters already. If you build an actual string query and call it using Database.query then you ...
user avatar
  • 645
0 votes

How to obtain child records for a given parent record and vice versa?

Getting the object name from an Id is easy. Getting the parent and child records is harder (and may be impossible). The Id class provides the getSObjectType() method, which gives you an SObjectType ...
user avatar
  • 46.8k
1 vote
Accepted

Is there a SOQL query to get contacts without Case, Account and Chat transcript?

you need to write query like below. `select id, name, email, phone, account.name from contact where id not in (select contactid from case) and accountid = null AND id not in (select contactid from ...
user avatar
0 votes

How to retrieve the IDs of existing custom managed content types

You can use: SELECT Id, ContentKey FROM ManagedContent
user avatar
  • 1
2 votes

When I would change a formula, then when the value from that formula will change?

Formula fields do not have their values stored, they are calculated on-demand. Every time you query a record in Apex or view a record in a web browser, the formula fields are re-calculated. So there ...
user avatar
  • 46.8k
-2 votes

How to query child to parent

we can understand it by an example. We have Account and Contact Object and we know that the relationship between them is lookup relationship. Note : This relationship has one property called ...
user avatar
4 votes
Accepted

Question around SOQL query on a Task and why I can't use whoid as a where clause

From what you are doing in your query, I am guessing you are trying to narrow down the query to only include Tasks where the Who is a Lead. Instead of trying to compare the Id prefix, you need to use ...
user avatar
  • 26.7k
0 votes

Question around SOQL query on a Task and why I can't use whoid as a where clause

As per salesforce documentation for SOQL. The LIKE operator is supported for string fields only. You have to query without whoid like filter and then filter using for loop. List<Task> ...
user avatar
  • 1,048
0 votes
Accepted

Help with a SOQL query on ContentDocument object

You can just add some brackets to join logical conditions, like so: select id, title from contentdocument where (not title like '%seo%') and (filetype = 'pdf')
user avatar
  • 1,566
3 votes

Eror SOQL Didn't understand relationship 'Contact' in FROM part of query call

When doing a sub query (the SOQL version of an Inner Join), the FROM clause must reference the relationship name you are querying from. This relationship name is defined on the lookup field on the ...
user avatar
  • 1,210
0 votes

Rest API - Which has higher priority in a SOQL query, LIMIT clause OR Sforce-Query-Options: batchSize?

batchSize only affects the number of records returned per API call. To get the rest, follow the nextRecordsUrl parameter. Note that batchSize is only a hint. Actual batch size may be smaller depending ...
user avatar
  • 430k
0 votes
Accepted

Tracking number of contact attempts based on Tasks under Contact

No, it is not possible to have a formula field execute a query. Further, what you're trying to do (count the number of records related to a parent) is also not possible with a formula field alone. The ...
user avatar
  • 46.8k
1 vote

What does explicit clause mean in SOQL

The FeedItem status field doesn't support the filter option. You can use the following code as a workaround: List<FeedItem> feedItems = new List<FeedItem>(); for(FeedItem fi : [SELECT Id, ...
user avatar
  • 320
1 vote

SOQL for related objects in Salesforce

If you're using System.debug to check the map values, you should be aware that child and parent relationships aren't printed out. The values are there, you just need to access them as normal: // ...
user avatar
  • 430k
3 votes
Accepted

Is there a way to get Contacts with no cases using SOQL?

SELECT Id FROM Contact WHERE Id NOT IN (SELECT ContactId FROM Case) LIMIT 10 Thanks
user avatar
  • 416
0 votes

Inline query has too many rows for direct assignment, use FOR loop

One also can provoke this error in a line of code that has no queries at all. For instance, in a Batchable and Schedulable class MyBatch, our Schedulable.execute() method sets a batch size of 200. ...
user avatar
0 votes
Accepted

Cross Object SOQL Query

Relationships between the object are as below ObjectB - No Parent ObjectA - Parent ObjectB ObjectC - Parent OjbectA As per salesforce soql limitations. In each specified relationship, only one ...
user avatar
  • 1,048
1 vote

How to get the Apex Character Limit via Api/SOQL

That bit of limit is not exposed as an API at the moment. If you really want to get it, you could screen scrape that page. We have implemented screen-scrapping in few places (like to get list of ...
user avatar
  • 1,479
4 votes
Accepted

I can't see deployed field after deployment via change sets (but I can see that field in setup)

This is because when you deploy the field through change set its field level security is not configured automatically unless you add the profile to the change set. Checkout the official documentation ...
user avatar
1 vote
Accepted

SOQL Queries using the Rest API results are close to half that of the Salesforce reports

I ended up finding the answer. It was a setting difference. In the report, I was looking at both Tasks and Events and in the query I am only look at events. I removed Tasks from the report and they ...
user avatar
  • 21
1 vote

SOQL: How to get the biggest value from a field and compare to a another on query?

SOQL, even though looks similar to traditional RDBMS SQL, it lacks many capabilities. Using fields on both of side expressions is one such feature SOQL doesn't support. For ex., you cannot do this ...
user avatar
  • 1,479
0 votes

SOQL How to select WHERE = 2 months ago

The last Last_N_Months would also give the last day of the previous month. Suppose I want to process previous Nov/21 data from today then the below query would also give me data of 31st October/21 ...
user avatar
1 vote
Accepted

How to get the range of Fiscal years from FiscalYearSettings based on Current FIscal Year Dynamically?

This SOQL query will provide you last two fiscal years, current fiscal year and one future fiscal year. [SELECT Id, PeriodId, StartDate, EndDate, Name FROM FiscalYearSettings WHERE StartDate >= ...
user avatar
  • 1,048
0 votes

Filter Case_Created__c, Datetime format issue, Python SOQL

As per error message description, case custom field Case_Created__c is of type DateTime so where condition must be formatted as YYYY-MM-DDThh:mm:ssZ (optional timezone) SELECT CaseNumber, AccountId, .....
user avatar
  • 3,230
1 vote

Help me writing SOQL query

This isn't something that SOQL can do on its own. You'll either need to use Apex to add this "if 1 is blank, use 2" logic, or use a formula field. The formula field approach, placed on the ...
user avatar
  • 46.8k
0 votes

How to Query Child records of the lookup record in a single query

You can only go 1 level deep when querying child records. You can also go 5 levels up when querying fields from lookup relations. But you cannot go up then down, so you need to split those queries up ...
user avatar
  • 2,552
2 votes
Accepted

How to include relationship query In WHERE clause?

You will use ANTI JOINS and is well documented in the official docs here. For Only Accounts with Contacts SELECT Id, Name, (SELECT Email FROM Contacts) FROM Account WHERE Id IN (SELECT AccountId ...
user avatar
2 votes
Accepted

Order Query Results aside from ASC and DESC

About the only options you have left here are to do the ordering yourself in the presentation layer (i.e. through javascript) do the ordering yourself in Apex using a wrapper class and implementing ...
user avatar
  • 46.8k
4 votes
Accepted

The equivalent of "distinct" in SOQL does not work

When you use GROUP BY, every field that you give in the SELECT clause needs to either: Be used in an Aggregate Function (COUNT(), MAX(), MIN(), AVG(), etc...) Appear in the GROUP BY clause Since you ...
user avatar
  • 46.8k
0 votes

How can I show the Result with the trigger that I created?

You are querying Account as a single sObject (Account acc = [SELECT Id FROM Account]; ) instead of a list of sObjects, which can lead to either a List has more than 1 row for assignment to SObject or ...
user avatar
1 vote

SOQL to get records between past 2 months and next 2 months from today

You can't use the LAST/NEXT_N_MONTHS for this, because they work on months, not days. This document describes all your possible options. Unfortunately, the best you can really do is use LAST_N_DAYS ...
user avatar
  • 430k
1 vote

How to query Deployment Details in Deployment Status? Is it even possible?

You can query an object called DeployRequest but using the tooling api. sfdx force:data:soql:query --query "SELECT Id, Status, StartDate, CompletedDate FROM DeployRequest WHERE Status = '...
user avatar
1 vote
Accepted

How to query related Contact from Account by Id in "after insert, before update" trigger?

There are several issues with this code (you should never1 have queries inside of a loop), but the fundamental problem you're running into is one of how relationships work. The immediate error that ...
user avatar
  • 46.8k
0 votes

How to query related Contact from Account by Id in "after insert, before update" trigger?

This block of code successfully returns the correct Contact because both the Account and Contact share a custom field, Lead_Number__c. The AccountId on the Contact object is not yet assigned when the ...
user avatar
  • 5

Top 50 recent answers are included