4

I have a trigger where I have to Insert a new Record in the "CaseTeamMember" object whenever a new "Case" is created. For this I have to query the "CaseTeamRole = CSO" .

In my developer console when I give the query only as below then I get the CSO record.

Select Id,Name from CaseTeamRole

enter image description here

But when I try to fetch the Id of only the "CSO record then it is not fetching. I have tried queries in multiple ways as below :

1) Select Id,Name from CaseTeamRole where Name LIKE 'CS%' (Before this query used to get the CSO record. Now after sandbox refresh this is also failing)

2) Select Id,Name from CaseTeamRole where Name = 'CSO'

3) Select Id,Name from CaseTeamRole where Name LIKE 'C%'

enter image description here

If I give any other record then those are getting fetched .

enter image description here

This is not allowing me to even create a case now due to SOQL not fecthing any record in trigger :(

Please help me in understanding what might be the issue.

Edit Trigger

Trigger CaseTrigger on Case (After Insert) 
{
    If(Trigger.isAfter)
    {
        If(Trigger.isInsert)
        {
            For(Case C : Trigger.New)
            {
                IF((C.Record_Type_Name__c == 'Delivery Escalation' || C.Record_Type_Name__c.startsWith('CSP')) && (C.CreatedDate == C.LastModifiedDate))
                {
                    CaseTriggerHelper.CreateNewCaseTeamMember(Trigger.New);
                }
            }
        }
    }
}

Class:

Public Class CaseTriggerHelper
{
    Public Static Void CreateNewCaseTeamMember(List<Case> CaseIds)
    {  
        List<CaseTeamMember> CTMList = New List <CaseTeamMember>(); 

        CaseTeamRole CTR = [Select Id,Name from CaseTeamRole where Name LIKE 'CS%'];
        system.debug('---CTR---'+CTR);

        Try
        {
            For(Case C : CaseIds)
            {
                CaseTeamMember CTM = New CaseTeamMember();

                CTM.ParentId = C.Id;
                CTM.MemberId = C.CreatedById;
                CTM.TeamRoleId = CTR.Id;
                CTMList.Add(CTM);
            }
            Insert CTMList;
        }
        Catch(Exception e){
            } 
    }
}

UPDATE

Should I pass a list of cases in my trigger handler in this way?

Trigger CaseTrigger on Case (After Insert) { 
  Set<ID> ids = Trigger.newMap.keySet(); 
  If(Trigger.isAfter && Trigger.isInsert) { 
    For(Case C : Trigger.New) { 
       List<Case> C = [SELECT Id FROM Case 
                          WHERE ((Record_Type_Name__c == 'Delivery Escalation' || 
                                  Record_Type_Name__c.startsWith('CSP')) &&
                                 (CreatedDate == LastModifiedDate))];  
       CaseTriggerHelper.CreateNewCaseTeamMember(C); 
    } 
  } 
 }

Thanks! Ruchi

16
  • did you try OF, BU as filter. Were you able to get records for these?
    – Ashwani
    Jan 21, 2016 at 11:53
  • Yes I am able to get records for them.
    – Ruchi
    Jan 21, 2016 at 11:54
  • are you sure that user, that fire trigger, have “Customize Application” AND “Manage Users” permission?
    – kurunve
    Jan 21, 2016 at 11:55
  • I am a "System Admin" there and the query Select Id,Name from CaseTeamRole where Name LIKE 'CS%' was working before the sandbox refresh.
    – Ruchi
    Jan 21, 2016 at 11:57
  • and those case team role still exists, right? no trailing space etc? just like operator stopped working?
    – kurunve
    Jan 21, 2016 at 11:58

2 Answers 2

4

I observed the same issue in our full sandbox after a refresh. I believe it is a bug, though it is not yet on Salesforce's known issues list.

If you change your query to Select Id,Name from CaseTeamRole where Name != 'CSO', your query will probably return all results except the record where the Name is CSO.

If you change your query to Select Id,Name from CaseTeamRole where Name like '%s%', your query will probably return two records: CSO and Global Sales Manager.

It looks to me that the results only return if > 1 row is in the result set.

The workaround that could work for you is to query for all CaseTeamRole records and then loop through each result looking for Name = 'CSO'. For example:

for (CaseTeamRole ctr: [select id, name from CaseTeamRole])
{
 if(ctr.Name == 'CSO')
 {..do stuff.. }
}

If you happened to open a case with Salesforce, would be curious to know if they confirmed whether it is a bug or not.

2
  • I did the same thing later to resolve this issue. Did not found any other way. I had not opened any case with salesforce.
    – Ruchi
    Feb 29, 2016 at 6:32
  • I came across this issue myself recently. On a hunch, I cleared the value of the field and re-entered it and the problem went away. I had experience in the past where someone pasted a value into the name field and quite possibly included a non-breaking space or something similar. Thus causing it to not to match on SOQL filters. I know it seems farfetched, I wouldn't have belived this solved it if I didn't see it myself. In my opinion, this is a bug. Dec 6, 2016 at 19:19
0
  1. double click on the cso field and copy the value and now search with this value, this will find the results.

this happens sometime because of some hidden different encoding characters.

1
  • I tried your approach but did not help :(
    – Ruchi
    Jan 21, 2016 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .