You need to sign in to do that
Don't have an account?
JBabu
Limitation of formula field in SOQL?
Hi,
I am writing a SOQL query which has formula field in the WHERE clause.
Is there any limitation on number of records which are retrieved?
Please let me know the details.
Thanks,
Babu.
Hi,
I would possibly get 50K records at maximum in my formula field filtered query.
Does this still require index?
If so how do I do that in SOQL query?
Also please let me know if there is any link to check these kind of limitations.
Thanks,
Babu.
Salesforce.com now has the ability to generate custom indexes for formula fields that meet a certain criteria. If you are concerned that the performance of the query will suffer and/or be blocked because of non-selectivity, you may be able to request a custom index.
Your application's performance will be directly related to the performance of the formula field. They cannot index cross-object formulas, either, so you will need to take that into consideration.
Ultimately, there's not enough information from your post to determine if the formula will perform well or not.
My formula would be
recent_mod__c = if( (now()-lastmodifieddate) <= 15*24*60, 'true','false')
I would write soql query like example:
"select id from lead where recent_mod__c ='true' "
this would return records which are modifed with in last 15 mins.
Main reason I have used this method instead of using :
List<Opportunity> Optylist = new List<Opportunity>();
Optylist = [select name from Opportunity where SystemModstamp > :Datetime.now().addMinutes(-15)];
because I want to run the query through eclipse/workbench/force.com explorer.
For the above formula, does it use index? Is it ok if the number of records fetched are more than 1000? Please let me me know..
Thanks,
Babu.
Do you mean to use ORDER BY LastModifiedDate DESC LIMIT 50000? I want to know the records which are modified with in last 15 mins.
I tried both queries:
(1)
select name from Opportunity where SystemModstamp > Datetime.now().addMinutes(-15) ORDER BY LastModifiedDate DESC LIMIT 50000
Error Message:
MALFORMED_QUERY:
Opportunity where SystemModstamp > Datetime.now().addMinutes(-15)
ERROR at Row:1:Column:52
unexpected token: 'Datetime.now'
(2)
select name from Opportunity where SystemModstamp > :Datetime.now().addMinutes(-15) ORDER BY LastModifiedDate DESC LIMIT 50000
Error Message:
MALFORMED_QUERY:
Opportunity where SystemModstamp > :Datetime.now().addMinutes(-15)
^
ERROR at Row:1:Column:52
unexpected token: ':' (Bind variables only allowed in Apex code)
SELECT Name FROM Opportunity WHERE recent_mod__c = 'true' ORDER BY LastModifiedDate DESC LIMIT 50000
This should allow the system to use indexes (if my understanding of SOQL optimization is correct).
Can you please let me know why do we need to add ORDER BY LastModifiedDate DESC LIMIT 50000? As the query
SELECT Name FROM Opportunity WHERE recent_mod__c = 'true'
gives the desired result (records which are modified with in last 15 mins)
Does adding ORDER BY LastModifiedDate DESC LIMIT 50000 makes it to use index?
Doesn't adding theis ORDER BY clause makes the query run slower?
Please advice.
Thanks,
Babu.