function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
renurenu 

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, execution of AfterInsert

I'm trying to write test cases for my APEX code.I searched  the Apex documentation and  the Apex discussion board but did not find solution. I am getting two errors. I tried  but unfortunately not getting the required output. Let me know where i am getting error.  I had written the same code in the trigger without using Apex class it was working perfect. But since i need to deploy the trigger i started writing Apex class which gives me these errors.
Thanks in advance for the solution.
 
 
This is what i am trying to accomplish.
 
When ever a new custom object(Client)  is created or updated i need to update few fields accordingly.
 
 
And the errors are at line 35 and 54
 
Errrors
1)  System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ClientUpdates: execution of AfterInsert
caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null)
2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)
Class.ClientApex.afterinsertupdate: line 69, column 1
Trigger.ClientUpdates: line 19, column 1
 
2)  System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ClientUpdates: execution of AfterInsert
caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null)
2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)
Class.ClientApex.afterinsertupdate: line 69, column 1
Trigger.ClientUpdates: line 19, column 1
 
 


Message Edited by renu on 07-09-2008 02:20 PM
werewolfwerewolf
Is your code doing some massive select statement with no where clause or something?
renurenu
Thanks for your time to help me with this. I tried a lot and got the required output.
gptheprincegptheprince

Hello Guys

I am having a similar issue, trying to test a very simple Trigger.

Basically my trigger will kick in when a new contact is inserted, and what it will do is to update the account name associated to the contact.

I created a Class, a Trigger and a TestClass that I am using to test that all works fine:

Class:

// This class updates the Organization Name for every New Contact created

public class UpdateOrganizationNameClass {

   public static void UpdateOrganizationName(Contact[] cont){

      Contact c = [select account.name from contact where id = :cont[0].id];
      c.account.name='test organization';
      update c.account;
   }
}

Trigger:

trigger NewContactUpdateOrganizationName on Contact (after insert) {

UpdateOrganizationNameClass.UpdateOrganizationName(Trigger.new);

}

Test Class:

// This is a TEST class created to test the UpdateOrganizationNameClass code

public class UpdateOrganizationNameClassTEST {

   static testMethod void testUpdateOrganizationName(){
         
          Contact c = new Contact (lastname = 'Test Contact', firstname = 'Test Contact', start_date__c = System.today());
          insert c;
   }
}

But this is the error message I get:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, NewContactUpdateOrganizationName: execution of AfterInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Class.UpdateOrganizationNameClass.UpdateOrganizationName: line 8, column 7
Trigger.NewContactUpdateOrganizationName: line 3, column 1

Would you be able to tell me what am I doing wrong?

Thanks

Giorgio

werewolfwerewolf
Yeah, I can tell you what the problem is.  Your test method is making a new contact that has no null account.  Then in your trigger (in your method really) you're selecting out the account from the contact and trying to do something to it, which of course you can't because it's null.
gptheprincegptheprince
Fantastic, it worked :-) Thanks a lot
 
100% code coverage! Now i have to figure out how to Deploy it. Hope that part is easier
 
werewolfwerewolf
Well you don't want to deploy that code as is.  Even if your test is passing, the trigger will still crash if it sees a null account on the contact.  You need to fix that, and make another test to test that case.  Your test failure was a proper test failure, even if it was kind of an accidental test case.
gptheprincegptheprince

In this case however, Account name should never be null in real life, as it is a  Mandatory SF field, so if I entered a contact thru the UI, as I would always do (I am not planning to have any complex triggers), that field would always be there.

But in general, yes, it is best to make sure this works o matter what. I will have to practice a little more on these tests before I move to the next stage

 

 

APEX 123APEX 123

I am getting the error like this on the test case can any body help me to reslove it

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, quoteUpdateopportunity: execution of AfterInsert

caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []

Trigger.quoteUpdateopportunity: line 10, column 1: []

 

This is my trigger wrote on quote

 

trigger quoteUpdateopportunity on quote__c( after insert) {
    List<opportunity> oppToUpdate = new List<opportunity>();

    for(quote__c quo : trigger.new){
        if (quo.Quote_Number__c!= Null )
            oppToUpdate.add(new opportunity(id= quo.Opportunity_Name__c, StageName = 'offer'));
    }

    if (oppToUpdate != null && !oppToUpdate.isEmpty())
        update(oppToUpdate);
}

this is the test class i wrote 

 

@isTest
private class quoteupdateopportunity{
    static testMethod void testquoteupdateopportunity(){
    quote__c qo=new quote__c(Author_Email_New__c='manoj.jena@kvpcorp.com');
       insert qo;
       
  opportunity op= new opportunity(name='test 002');
  insert op;
  
op= [SELECT stageName FROM opportunity Where Id = :op.Id];
System.assertEquals ('offer',op.stagename); 
   }   
   }

 

Help me to find out get riid of this error

 

Bob.390672021994282E12Bob.390672021994282E12
I have the same issue. Tried multiple different things to fix. I have another trigger on the parent to set the child as submitted after update. The I have the below thats bombing with the same above error message. Any thoughts?

trigger ADRUserTrigger on ADRUser__c ( after update){

     for (ADRUser__c a : Trigger.New) {
   if (a.Status__c == 'Submit'
   && a.ApproveReject__c <>'Approved'
    && a.ApproveReject__c <>'Rejected'){

***Note i have a workflow rule to change accept rejected to approved rejected. I thought that this may correct the issue but it doesnt.


        Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
       
        req1.setComments('Request has been Submitted ');
        req1.setObjectId(a.id);

        req1.setNextApproverIds(new Id[] {a.User__c});
   
        Approval.ProcessResult result = Approval.process(req1);
   
   
  }

}
}
mahipal reddymahipal reddy
Hi ,
Try @isTest(SeeAllData=true).
Today I got the same error and after little research found that seeAllData Fix this issue.
Kirti ChhatwaniKirti Chhatwani
I know this is very old post,
But really want to help the new ones who will refer this post, 
In this case the setup Objects like User, ObjectPermissions, PermissionSet, PermissionSetAssignment, UserRole, etc. are inserted or updated or deleted in the same transaction when DML is performed on non-setup objects or custom or standard objects.
So, to avoid it we need to use on the DML operation in the code  - System.runAs(User){ }
here is the reference - salesforce help for setup and non-setup objects DML operations together (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_tools_runas.htm#:~:text=The%20system%20method%20runAs%20enables,runAs%20only%20in%20test%20methods.)