You need to sign in to do that
Don't have an account?
Interpretation problems in custom costructor SELECT query
Hello all,
could someone be so kind to explain me the following?
CONTEXT:
CUSTOM CONSTRUCTOR --> CUSTOM VISUALFORCE PAGE --> LIGHTNING APP
In the custom constructor I use the following SOQL query:
public class Account_Controller { public Account account; public Account getAccount() { account = [SELECT Id, Name, Last_Update__c FROM Account WHERE (OwnerId = :UserInfo.getUserID()) AND (Last_Update__c = LAST_N_DAYS:150) ORDER BY Last_Update__c DESC LIMIT 1]; } //BUTTON ACTIONS public PageReference OK() { account.Last_Update__c = Date.today(); upsert(account); } }
Code is not complete, but just enough to make you get what I'm doing. In the custom page, when clicking an "OK" button upsert(account) is called, I stay on my custom page and the field Last_Update__c is modified to today's date. Everything works fine, but then I would expect that next time I open my Lightning up I get a different account as a result, seen that condition
Last_Update__c = LAST_N_DAYS:150 shouldn't be met anymore.
So, why I always get the account I just modified and not a new one wit no updates for more than 150 days? What I am missing/doing wrong?
20000 points to the best answer :)
Seriously, thanks in advance for your help on this. Cheers, A
account = [SELECT Id, Name, Last_Update__c FROM Account WHERE (OwnerId = :UserInfo.getUserID()) AND (Last_Update__c = LAST_N_DAYS:150) ORDER BY Last_Update__c LIMIT 1];
By this way the last updated record will last in the above list, and you update the first record which will be different every time.
Check if it works as you expect.
All Answers
account = [SELECT Id, Name, Last_Update__c FROM Account WHERE (OwnerId = :UserInfo.getUserID()) AND (Last_Update__c = LAST_N_DAYS:150) ORDER BY Last_Update__c LIMIT 1];
By this way the last updated record will last in the above list, and you update the first record which will be different every time.
Check if it works as you expect.