You need to sign in to do that
Don't have an account?
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY...need help urgent...
M getting the following error...so code coverage is less than 75%...not able to deploy...Thanks in advance for help...
error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Minutescase: 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
@isTest(SeeAllData=true)
private class testMyTaskTrigger {
public static testMethod void testTTrigger(){
Account acc = new Account();
acc.name = 'Test';
insert acc;
Contact con = new Contact();
con.LastName = 'Test Contact';
insert con;
Task t = new Task();
t.OwnerId = UserInfo.getUserId();
t.Subject='Donni';
t.Status='Not Started';
t.Priority='Normal';
t.Minutes_on_tasks__c = 2000;
t.status = 'Completed';
insert t;
Task tas = new Task();
tas.OwnerId = UserInfo.getUserId();
tas.Subject='Donni';
tas.Status='Not Started';
tas.Priority='Normal';
tas.Minutes_on_tasks__c = 2000;
tas.status = 'Completed';
tas.whoid = con.id;
Sales_Resources__c sr = new Sales_Resources__c ();
sr.Name = 'Test Sales Resources';
insert sr;
Task p = [select id from task where Ownerid = '00500000006scDCAAY' limit 1];
try{
delete p;
}
Catch(Exception e)
{
system.debug('Error:'+e);
}
Test.startTest();
insert tas;
try{
delete t;
}
Catch(Exception e)
{
system.debug('Error:'+e);
}
Test.stopTest();
}
}
same error in this test class also... Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, EB_Case_Owner_Trigger: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Minutescase
@isTest(SeeAllData=true)
private class EB_Case_Owner_Trigger_Test_Class {
static testMethod void myUnitTest() {
// TO DO: implement unit test
EB_SB_Builder__c ebsb = new EB_SB_Builder__c ();
Case accs1 = new Case();
insert ebsb;
Datetime dt = Datetime.now();
Case accs = new Case(RecordTypeId='0120000000098Po',Event_Survey_Builder__c = ebsb.Id, Origin= 'Email', Subject='Testing Task', Minutesoncase__c =10, Reason='508 compliance', Product_Type__c = 'Event Tool');
//Case accs = new Case(ContactId = '003P000000Cu7pU',RecordTypeId='0120000000095Nn',Event_Survey_Builder__c = ebsb.Id, Origin= 'Email', Subject='Testing Task', Minutesoncase__c =10, Reason='508 compliance', Product_Type__c = 'Event Tool' , AccountId='001P000000GF1fq');
insert accs;
}
}
hey try this.. let me know if it doesnt work....
All Answers
AccountId field is missing while inserting an Contact.
Account acc = new Account();
acc.name = 'Test';
insert acc;
Contact con = new Contact();
con.LastName = 'Test Contact';
con.AccountId = acc.Id; // AccountId of the contact
insert con;
Thanks,
Devendra
Still giving the same error.... error is with
code in green...
Task t = new Task();
t.OwnerId = UserInfo.getUserId();
t.Subject='Donni';
t.Status='Not Started';
t.Priority='Normal';
t.Minutes_on_tasks__c = 2000;
t.status = 'Completed';
insert t;
Hi,
There is a trigger code which executes after insert of a Task.
The query inside a trigger returning more than 100K records. You need to make changes into a trigger code. For example you can use filter conditions inside a query etc.
Thanks,
Devendra
here is the trigger code:
trigger Minutescase on Task (after insert, after update, before delete, after delete) {
public set<Id> srids = new Set<Id>();
public list<Sales_Resources__c> timeupdate = new List<Sales_Resources__c>();
aggregateResult[] results = [Select SUM(Minutes_on_tasks__c)summ From Task where status = 'Completed'];
Decimal decimalRevenue = 0 ;
if(results.size() > 0)
{
String str = '' + results[0].get('summ') ;
decimalRevenue = Decimal.ValueOf(str) ;
System.debug('decimalRevenue ::::: ' + decimalRevenue) ;
}
if(Trigger.isInsert || Trigger.isUnDelete || Trigger.isUpdate){
for(Task t: Trigger.new){
if(t.WhoId<>null && t.Minutes_on_tasks__c <> null && t.IsClosed==True)
{
srids.add(t.WhoId);
}
}
}
if(Trigger.isDelete){
for(Task t: Trigger.old){
if(t.WhoId<>null && t.Minutes_on_tasks__c <> null && t.IsClosed==True)
{
srids.add(t.WhoId);
}
}
}
timeupdate = ([Select c.Id,c.Total_Time_Spent_Hrs__c,(Select Id, Minutes_on_tasks__c From Tasks where IsClosed = True AND id in: srids)From Sales_Resources__c c]);
for(Sales_Resources__c sc : timeupdate)
{
sc.Total_Time_Spent_Hrs__c = decimalRevenue;
}
update timeupdate;
}
Also, you may want to consider removing the "SeeAllData=true" bit, if possible. It's best to create all your test data within the test itself.
Is there any particular reason for querying all the Sales Resources records from the database and updating the total time spent ?
Are you supposed to update all the sales resources records, if there is an event on single task record?
i don't require all the records of sales_resources...
requirement is...Sum of value of Minute_ON_Case of all the closed tasks should be on Sales_resources__c's field Total_time_Spents_hrs...
Now i changed the code as below...
errors are:
EB_Case_Owner_Trigger_Test_Class.myUnitTest() Class 55 1 Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, EB_Case_Owner_Trigger: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Minutescase: execution of ... New_Task_test.myUnitTest() Class 35 1 Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Minutescase: 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 ab...
trigger Minutescase on Task (after insert, after update, before delete, after delete) {
public set<Id> srids = new Set<Id>();
public list<Sales_Resources__c> ttt = new List<Sales_Resources__c>();
aggregateResult[] results = [Select SUM(Minutes_on_tasks__c)summ From Task where status = 'Completed'];
Decimal decimalRevenue = 0 ;
if(results.size() > 0)
try{
{
String str = '' + results[0].get('summ') ;
decimalRevenue = Decimal.ValueOf(str) ;
System.debug('decimalRevenue ::::: ' + decimalRevenue) ;
}
}catch(System.Exception ae){
system.debug ('you screwed up! ' + ae.getStackTraceString());
}
if(Trigger.isInsert || Trigger.isUnDelete || Trigger.isUpdate){
for(Task t: Trigger.new){
if(t.WhatId<>null && t.Minutes_on_tasks__c <> null && t.IsClosed==True)
{
srids.add(t.WhatId);
}
}
}
if(Trigger.isDelete){
for(Task t: Trigger.old){
if(t.WhatId<>null && t.Minutes_on_tasks__c <> null && t.IsClosed==True)
{
srids.add(t.WhatId);
}
}
}
// timeupdate = ([Select c.Id,c.Total_Time_Spent_Hrs__c,(Select Id, Minutes_on_tasks__c From Tasks where IsClosed = True)From Sales_Resources__c c Where id in: srids]);
for(Sales_Resources__c sc : [Select Id, Total_Time_Spent_Hrs__c From Sales_Resources__c where id != null and id in: srids])
{
sc.Total_Time_Spent_Hrs__c = decimalRevenue;
ttt.add(sc);
}
update ttt;
}
hey try this.. let me know if it doesnt work....
Hi Naidu,
thanks a ton..it is working fine...
can u have a look at test class also...
it is covering only 60%
@isTest(SeeAllData=true)
private class MinutecaseTrigger {
public static testMethod void testTTrigger(){
Account acc = new Account();
acc.name = 'Test';
insert acc;
Contact con = new Contact();
con.LastName = 'Test Contact';
con.AccountId = acc.Id;
insert con;
// Task t = new Task();
//t.OwnerId = UserInfo.getUserId();
// t.Subject='Donni';
// t.Status='Not Started';
// t.Priority='Normal';
// t.Minutes_on_tasks__c = 2000;
// t.status = 'Completed';
// insert t;
Task tas = new Task();
tas.OwnerId = UserInfo.getUserId();
tas.Subject='Donni';
tas.Status='Not Started';
tas.Priority='Normal';
tas.Minutes_on_tasks__c = 2000;
tas.status = 'Completed';
tas.whoid = con.id;
Sales_Resources__c sr = new Sales_Resources__c ();
sr.Name = 'Test Sales Resources';
insert sr;
Task p = [select id from task where Ownerid = '00500000006scDCAAY' limit 1];
try{
delete p;
}
Catch(Exception e)
{
system.debug('Error:'+e);
}
Test.startTest();
// insert tas;
try{
delete tas;
}
Catch(Exception e)
{
system.debug('Error:'+e);
}
Test.stopTest();
}
}
try this...
But now the issue is while deploying still overall code coverage is 71%...any idea....?
I guess you might need to update other test classes to get the overall coverage to 75 and above....
Thanks for replying...
can u help me to cover the following code...only orange part m not able to cover...
trigger..
trigger SetOpportunityOwnerName on Opportunity (before insert, before update){
Map<Id,String> userMap = new Map<Id, String>();
for (User u : [Select Id, Name From User]) {
userMap.put(u.Id, u.Name);
}
for (Opportunity a : Trigger.New)
{
if((a.StageName == 'Closed Won'|| a.StageName == 'Closed Won - AR Settlement') && !a.New_Type__c.contains('MYD') )
{
a.Owner_Name__c = userMap.get(a.OwnerId);
}
}
}
test class
@isTest private class Test_SetOpportunityOwnerNameTrigger {
static testMethod void myUnitTest() {
Opportunity opp = new Opportunity(Name = 'TestName',StageName = 'FooName',CloseDate = date.today(),True_Product__c = 'Biz Dev');
insert opp;
system.assertequals(opp.Owner.Name, opp.Owner_Name__c);
}
}