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
CageMMACageMMA 

Error in Trigger Help..CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY???

Hi:

   The error I am recieving is:

The following errors were encountered while processing an incoming email:

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY : OriginalCaseOwnerUpdate: data changed by trigger for field Original Case Owner: id value of incorrect type: 00GQ0000001919RMAQ

 

trigger OriginalCaseOwnerUpdate on Case(before update) {

Set<Id> ownerIds = new Set<Id>();

for (Case a : Trigger.new)
  ownerIds.add(a.OwnerId);

Map<Id, User> owners = new Map<Id, User>([Select Id from User Where Id in :ownerIds]);



List<QueueSobject> qna = [SELECT Queue.Id, Queue.Name FROM QueueSobject 
                    Where sObjectType='Case' AND (NOT Queue.Name Like 'CIQ%')];

List<Case> cc=[Select id,Ownerid from case where id IN :ownerIds];

RecordType rt=[SELECT Id FROM RecordType where sobjectType='Case' and Name='Client Services - CIQ'];
Integer i=0;
for (Case a : Trigger.new){
for(i=0; i==cc.size();i++){
System.Debug('cc' + cc.size());
If(a.Recordtypeid==rt.Id){  
    if( a.Ownerid!= qna[i].id && a.Original_Case_Owner__c==null){
            if(a.Original_Case_Owner__c!= a.OwnerId){
                a.Original_Case_Owner__c =a.ownerid;
            }
    }  
}

 So basically the concept is we have a original case owner custom field there and it should update once with a user name not a queue. If the user changes it to a queue or another user and if the original case owner is filled in previously it should not update it...

What is wrong with the code.

thanks

Z

Navatar_DbSupNavatar_DbSup

Hi,

 

List<Case> cc=[Select id,Ownerid from case where id IN :ownerIds];

 

In this line you are using 'id' field to look into 'ownerIds' rather than 'Ownerid'.

 

So your new query will be:

 

List<Case> cc=[Select id,Ownerid from case where Ownerid IN :ownerIds];

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.