I am trying to get the list of last 10 accounts viewed. The code seems to be working in sandbox and workbench but when I try deploying it in production, I get the error: No such column 'LastViewedDate' on entity 'Account'.  SELECT Id, Name, LastModifiedDate                             FROM account                             WHERE LastModifiedDate !=null ORDER BY LastViewedDate DESC limit 10  &lt;apiVersion&gt;31.0&lt;/apiVersion&gt;   Attached the error messags
123622
How how do I query recent account views and group by LastViewedDate    SELECT Id, Name                 FROM Account                ORDER BY Name DESC limit 10 FOR VIEW   I used to have it like this, but my test case is keep failing  SELECT SELECT Id, Name, LastModifiedDate                         FROM account                         WHERE LastModifiedDate !=null ORDER BY LastViewedDate DESC limit 10  static testmethod void testOppExt_TestMethod(){        Opportunity testOpp = new Opportunity(Name = 'TestOpp', StageName='Test', CloseDate = Date.today());       insert testOpp;        Account testAcc = new Account(Name = 'Test Account');       insert testAcc;        Contact con = new Contact(LastName='Test',AccountId=testAcc.id);       insert con;        Test.startTest();       OppExt testCon = new OppExt();       Contact conn = testCon.contact;       Account  Accn = testCon.acc;       Test.stopTest();     }   Error Message   Component Errors API Name Type Line Column Error Message 0 0 , Details: Average test coverage across all Apex Classes and Triggers is 0%, at least 75% test coverage is required. 0 0 SiteRegisterControllerTest.null(), Details: line -1, column -1: Previous load of class failed: oppext null 0 0 SiteLoginControllerTest.null(), Details: line -1, column -1: Previous load of class failed: oppext null 0 0 SiteRegisterController.null(), Details: line -1, column -1: Previous load of class failed: oppext null 0 0 testnewOpportunityController.null(), Details: line -1, column -1: Previous load of class failed: oppext null 0 0 SiteLoginController.null(), Details: line -1, column -1: Previous load of class failed: oppext null 0 0 testOppExt.null(), Details: line -1, column -1: Previous load of class failed: oppext null 0 0 OppExt.null(), Details: line 32, column 17: No such column 'LastViewedDate' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. null
122826
I have an issue whereby users can't see the 'Modified By' or 'Created By' columns on my SharePoint site (the columns are blank).  This issue affects all users, even those with full control.  I've found a quick fix by going into Central Administration > Application Management > Policy for Web Application, then ensuring the users have the following permissions:  Manage Lists  View Items  Edit Items  View Items  View Pages  Open  Manage Personal Views  This however makes the site extremely slow for all users.  Does anyone know how to fix this please?
80179
i have created a trigger which creates an opprtunity when the accounte is created and i have a custom field No of contact on account which displays the count of related contact for a particular account whenever it is updated.  I have tested seperated that the opportnity is created but for the second part ,it displays a big error when i try to save a record.  I am not getting any error while saving a record.Can someone help      trigger insertOpp on Account(After insert,after update,before update) { List&lt;Opportunity&gt; opplist=new List&lt;Opportunity&gt;(); for(Account acc:Trigger.new){  Opportunity op=new Opportunity(); op.Name='Cook'; op.accountid=acc.id; op.CloseDate=System.today(); op.StageName='Qualification'; opplist.add(op); }  insert opplist;     if(trigger.isupdate) {         Integer no_of_contact;         String accID;      for(Account c:Trigger.new )     {         accid = c.id;      }      account acclist = new account();     acclist = [select No_of_Contacts__c from account where id = :accid ];     no_of_contact = [SELECT count() FROM Contact WHERE AccountId = :accid];     acclist.No_of_Contacts__c = no_of_contact;     //update acclist;  }  }   ERROR:       Review all error messages below to correct your data. Apex trigger   insertOpp caused an unexpected exception, contact your administrator:   insertOpp: execution of AfterUpdate caused by: System.DmlException:   Update failed. First exception on row 0 with id 00128000002r8gKAAQ;   first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, insertOpp: maximum   trigger depth exceeded Account trigger event AfterUpdate for   [00128000002r8gK] Account trigger event AfterUpdate for   [00128000002r8gK]
3176
I look today on a few fresh question, and the view count was 0. Even after I refreshed the page a few time. This is definitely a bug, since the question isn't mine.  Also I don't think the all page was cached, since that the DateTime mark was change every reload.  But maybe the SQL result is cached.
96093
We are submitting our application for Security review so we have to check FLS/CURD so we have a query like below.  Account ac  = [SELECT id, Name From Account limit 1];   so do we need to check isAccessible() for Id field here? I know we have to check for Name field but not sure do we really need to check same for Id field?
86495
This is one of those times when I tried to add something and realized that I've got it applied to all displays. This time it was a vocabulary filter, so I clicked cancel and it didn't register so I clicked back to site.  After that I tried to edit and it returned     The website encountered an unexpected error. Please try again later.   The log shows this:     Exception: No entity type for field vid on view VIEW in   Drupal\views\Plugin\views\HandlerBase->getEntityType() (line 712 of   /PATH/core/modules/views/src/Plugin/views/HandlerBase.php).   I checked the active config and couldn't find anything with a vid. Clearing cache and reimporting the view config didn't fix it. So, is there a way?
85111
I am trying to display the user name of the accounts that have logged in during the past month using the last command.  At the moment I have this  last | awk '{print $1, $4 ,$5 ,$6}' | grep -B 10 Jul | sort -u -t' ' -k1,1   As the users who have logged in most recently are displayed higher in the list, I am trying to grep for the month, then display that line and the lines above it and delete duplicate usernames. But it doesn't seem to be working. Any ideas?
94031
I have a query in a before-update trigger that looks like following:  [SELECT Id,(SELECT Id,Active_opp__c              FROM Opportunities              ORDER BY Days_from_Last_Stage__c ASC)   FROM Account WHERE Id IN: conAccMap.values()]   I have checked this in query plan and it looks like :    Is there a chance that the inner query will cause selective query error since I dont have a WHERE Clause on an indexed field in the inner query?
4736
I have been asked by a client to implement some views for reporting purposes, the views will be accessed via PowerBI, Excel and SSRS. The designated user will only have access to the view and no underlying tables must be available to the user.  The problem I have encountered in that the SQL within the view touches 3 different schemas (All within the same database):   Pupil Provider  Security   The view is:  CREATE VIEW dbo.vTestPermissions AS SELECT a.Column1,        b.Column1,        c.Column1 FROM Pupil.Table1 a JOIN Provider.Table2 b ON a.Column1 = b.Column1 JOIN Security.Table3 c ON a.Column1 = c.Column1   The owners of the Tables/View are as follows:   Pupil.Table1 - Owner Pupil Provider.Table2 - Owner Provider Security.Table3 - Owner Security vTestPermissions - Owner dbo   When I select from the view I get an error:     The SELECT permission was denied on the object 'table3', database   'TEST', schema 'Security'   I have tried giving SELECT permission with and without the GRANT option to the schema, and the tables, but that makes the underlying tables available to the user.  Any help on this will be greatly appreciated.
68495
I am getting this error:     SObject row was retrieved via SOQL without querying the requested   field: Contact.Account   Controller:  public class WrapperAccountCtrl {      public List&lt;Account&gt; acclist{get;set;}     public List&lt;Contact&gt; conlist{get;set;}      public List&lt;MyWrapper&gt; wap{get;set;}      public WrapperAccountCtrl()      {         acclist=[Select id,name from Account];          conlist=[Select id,name,AccountID  from contact where AccountID IN:acclist];          system.debug('Size----'+conlist.size());           wap=new List&lt;MyWrapper&gt;();           for(integer i=0;i&lt;acclist.size();i++)          {              wap.add(new MyWrapper(conlist,acclist[i]));          }     }      public class MyWrapper     {          public Account accn{get;set;}          public List&lt;Contact&gt;conrec{get;set;}          public MyWrapper(List&lt;Contact&gt; con,Account acc)         {             accn=acc;             conrec=con;             }     } }   VF Page:  &lt;apex:page controller="WrapperAccountCtrl" sidebar="false"&gt;       &lt;apex:form &gt;          &lt;apex:pageBlock &gt;              &lt;apex:pageBlockTable value="{!conlist}" var="c"&gt;                  &lt;apex:column value="{!c.account.Name}"/&gt;              &lt;/apex:pageBlockTable&gt;          &lt;/apex:pageBlock&gt;      &lt;/apex:form&gt;  &lt;/apex:page&gt;
105367
I'm trying to develop my first test class in our sandbox instance. When running the below test, I am getting no records return from the first query to build accountsList. The test succeeds, but I have 0% code coverage. The trigger works as expected when ran.  My Test Class:  @isTest private class test_deleteAccountSharesOnUpdate {  static testMethod void updateAccounts()  {     Set&lt;String&gt; accountIds = new Set&lt;String&gt;();      List&lt;Account&gt; accountsList =      [         SELECT Id, Is_Script_Update__c, Description FROM Account     ];      Integer i = 0;     for (Account acct : accountsList)     {         if(i &gt; 199)         {             break;         }          acct.Is_Script_Update__c = True;         acct.Description = 'Testing at ' + System.now();          accountIds.add(acct.Id);          i++;     }      test.startTest();      update accountsList;      test.stopTest();      List&lt;Account&gt; updatedAccts =      [         SELECT Id, Is_Script_Update__c, Description         FROM Account          WHERE Id IN : accountIds     ];      for(Account acct : updatedAccts)     {         System.assertEquals         (             'Testing at',             acct.Description.substring(0,10)         );     } }   }  Trigger I'm trying to test:  trigger deleteAccountSharesOnUpdate on Account (after update)  {    Set&lt;String&gt; accountIds = new Set&lt;String&gt;();  // Gather the account Ids being updated for (Account acct : trigger.new) {     // Only remove shares for accounts being updated by data loader.     // Loader script will insert new shares after this job.     if(acct.Is_Script_Update__c)     {         String terrCode = acct.Territory_Code_String__c;          if(terrCode != null &amp;&amp; terrCode.length() == 5)         {                accountIds.add(acct.id);         }     } }  if(accountIds.size() &gt; 0) {     // Remove the shares associated with these accounts     delete      [         select id          from AccountShare          where RowCause = 'TerritoryManual' AND          AccountId IN : accountIds     ];      // Reset flag that indicates this update is from a data loader.     // Data loader will set this checkbox as true on update.     // This prevents the trigger on UI update.     //     List&lt;Account&gt; accountsList =      [         SELECT Id, Is_Script_Update__c          FROM Account          WHERE Id IN: accountIds     ];      for (Account acct : accountsList)     {         acct.Is_Script_Update__c = False;     }      update accountsList; }   }  Degub log shows no rows returned for the first query:  14:47:14.461 (3461430000)|SOQL_EXECUTE_BEGIN|[8]|Aggregations:0|select Id,       Is_Script_Update__c, Description from Account 14:47:14.483 (3483545000)|SOQL_EXECUTE_END|[8]|Rows:0  Any help is greatly appreciated!
11945
While trying to pull changes from a scratch org (sfdx force:source:pull, tried with and without -f), I'm getting this error:     Entity of type 'ListView' named 'Note_Relation__c.My_Notes' cannot be found.   I do have a custom object Note_Relation__c, and it exists both locally and in the scratch org.  However, it's not an object that is normally accessed directly.  It has no tab, and should have no list views.  Nonetheless, I've checked the object's list view (via prefix, e.g., /a0D in both Classic and LEX view), and I can find no list views at all.  I've also tried adding an entry to .forceignore:  force-app/main/default/objects/Note_Relation__c/listViews/My_Notes.listView   This has no effect either.  At this point, I'm stuck with a bunch of config changes in a scratch org that I cannot pull.  I can find no references to this error message with scratch orgs.  Has anyone seen this issue?  Edit to clarify: I tried the .forceignore line based on what I think the file name should be; I have no force-app/main/default/objects/Note_Relation__c/listViews directory locally.  Edit 2: Workaround:  I found a workaround that doesn't make sense to me, but it works.  I'm not adding it as an answer yet because I'm not sure what's happening.  The workaround is to add the following line to .forceignore  Note_Relation__c.My_Notes   Even though this isn't a DX filepath, it's the name from the error message, and it seems to work.
34701
In MySQL 5.0 why does the following error occur when trying to create a view with a subquery in the FROM clause?     ERROR 1349 (HY000): View's SELECT contains a subquery in the FROM clause   If this is a limitation of the MySQL engine, then why haven't they implemented this feature yet?  Also, what are some good workarounds for this limitation?  Are there any workarounds that work for any subquery in the FROM clause or are there some queries that can not be expressed without using a subquery in the FROM clause?    An example query (was buried in a comment):  SELECT temp.UserName  FROM (SELECT u1.name as UserName, COUNT(m1.UserFromId) as SentCount        FROM Message m1, User u1        WHERE u1.uid = m1.UserFromId        Group BY u1.name HAVING SentCount &gt; 3 ) as temp
62150
I need to be able to detect that the trigger execution is happening because of a workflow field update. There is a suggestion in the cookbook:  But this solution is not properly bulkified. If my batch of records is split up (200, 100, 50 whatever the server decides) the 2nd to nth batches are not processed correctly because the flag has already been set. The second part of the problem is: This is part of a managed package. I have no control of the customer's workflow rules, supporting and configuring a flag/last changed field on a record is not realistic, our company doesn't have the support resources to be walking each customer through the configuration. Has anyone been able to solve this problem for large batches of records? Edit (In Response to Calebs Answer) Separate trigger batches do not run in separate contexts trigger AccountTriggerContext on Account (before insert) {     System.debug('counter='+TriggerContextCounter.getCounter()); }  . global without sharing class TriggerContextCounter {      private static Integer counter = 0;          public static Integer getCounter() {         Integer value = counter;         counter++;         return value;     }      private static testMethod void testTriggerContexts() {         List&lt;Account&gt; accounts = new List&lt;Account&gt;();         for(Integer i = 0; i &lt; 250; i++) {             accounts.add(new Account(Name='testTriggerContexts: ' + i));         }         insert accounts;     } }  Unit test debug messages  USER_DEBUG|[2]|DEBUG|counter=0 USER_DEBUG|[2]|DEBUG|counter=1  Both counters should have been 0 if the batches were running in separate contexts Edit Further explanation of background for @Ralph This is a generalized explanation, but when certain conditions are met, some date fields on other objects are updated. The trigger runs and updates the dates. If a workflow rule causes a field update on the object, the same trigger is run again and the dates on the other objects are updated for a second time. And because this is an increment operation the dates on the other objects are off by a factor of 2.
108265
I need to set up some views that will pull some data from a custom table I created.  Some views will need to pull content the regular way and from my custom table (where I may query for a particular nid, etc.).  How do I do this, or where is a good place to research?
56719
I would like to gather statistics on the highest run queries in my database.   For that I need to know how I can track queries so I can create views or materialized views to cache the results of the highest run queries since I have a big DB.
41171
So I have the following query that I am running through Batch Apex. I get the error:  System.LimitException: Too many query rows: 50001  I am receiving this because COUNT_DISTINCT() is subject to the same governor limits as other SOQL Queries. Basically I cannot think of a solution here, which is why I am posting this. The goal of the query is to see how many unique accounts an SDR is in contact with over a given time period. In this case, it is over a 120 day period. Would love some advice on how to achieve this.  String Contacts_Reached_TR_120_Query = 'SELECT Ownerid SDR_ID, COUNT_DISTINCT( whoid ) result FROM Task Where ActivityDate = LAST_N_DAYS:120 AND OwnerId in :ListOfIDs GROUP BY Ownerid';  DynamicBatchApexAR batch3_TR120      =   new DynamicBatchApexAR('SDR_ID', 'result', 'Contacts_Reached_TR_120__c', Contacts_Reached_TR_120_Query, SDR_IDs);   Then here is the batch class  global class DynamicBatchApexAR implements Database.Batchable&lt;AggregateResult&gt; {  public String sObjectIdKey; public String sObjectResultKey; public String sObjectFieldToUpdate; public String query; public List&lt;Id&gt; ListOfIDs;   global DynamicBatchApexAR(String arIdKey, String arResultKey, String fieldToUpdate, String soqlQuery, List&lt;Id&gt; whereInClause )  {       sObjectIdKey            = arIdKey;     sObjectResultKey        = arResultKey;     sObjectFieldToUpdate    = fieldToUpdate;     query                   = soqlQuery;     ListOfIDs               = whereInClause; }  global DynamicBatchApexAR(String arIdKey, String arResultKey, String fieldToUpdate, String soqlQuery )  {       sObjectIdKey            = arIdKey;     sObjectResultKey        = arResultKey;     sObjectFieldToUpdate    = fieldToUpdate;     query                   = soqlQuery; }  global Iterable&lt;AggregateResult&gt; start(Database.BatchableContext BC)  {     return ListOfIDs == null ? new BulkIterable(query) : new BulkIterable(query, ListOfIDs); }  global void execute(Database.BatchableContext BC, List&lt;sObject&gt; scope)  {     DynamicSObjectUpdater sObjectUpdater = new DynamicSObjectUpdater();      for(sObject sObj: scope)     {          AggregateResult ar      = (AggregateResult)sObj;         ID sObjectId            = (ID)ar.get(sObjectIdKey);         Decimal arResult        = (Decimal)ar.get(sObjectResultKey);         Map&lt;String, Object&gt; sObjectFieldsToUpdate = new Map&lt;String, Object&gt;{             sObjectFieldToUpdate =&gt; arResult         };          sObjectUpdater.getUpdateSObject(sObjectId, sObjectFieldsToUpdate);     }      sObjectUpdater.updateSObjects();   } global void finish(Database.BatchableContext BC)  {  }   }  Here is the iterable    global with sharing class BulkIterable implements Iterable&lt;AggregateResult&gt; {         String query;         List&lt;Id&gt;   ListOfIDs;      global BulkIterable(String soql, List&lt;Id&gt; WhereInClause)     {         query = soql;         ListOfIDs = WhereInClause;     }      global BulkIterable(String soql)     {         query = soql;     }      global Iterator&lt;AggregateResult&gt; Iterator(){         return ListOfIDs == null ? new BulkIterator(query) :  new BulkIterator(query, ListOfIDs);     }  }   Here is the iterator      global class BulkIterator implements Iterator&lt;AggregateResult&gt; {        AggregateResult[] results { get;set; }       Integer index { get;set; }   List&lt;Id&gt; ListOfIDs;      global BulkIterator(String query, List&lt;Id&gt; WhereInClause)      {     index = 0;     ListOfIDs = WhereInClause;     results = Database.query(query);        }    global BulkIterator(String query) {     index = 0;     results = Database.query(query);      }    global Boolean hasNext(){     return results != null &amp;&amp; !results.isEmpty() &amp;&amp; index &lt; results.size();    }        global AggregateResult next() {      return results[index++];   }      }   Is the error because I am running too many batches?