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
Jaynandan Prasad 8Jaynandan Prasad 8 

Trigger Conflict for CaseTeamRole

I have the following trigger that automate the case obj.  sync from one Org to another via salesforce to salesforce connection.
trigger OrgSync on Case (after insert, after update) {

PartnerNetworkConnection conn = [select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection  where ConnectionStatus = 'Accepted'];
                   
        List<PartnerNetworkRecordConnection> recordConnectionToInsert  = new List<PartnerNetworkRecordConnection>  ();
               
        for (Case cc : Trigger.new){
            PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();

           newrecord.ConnectionId = conn.Id;
           newrecord.LocalRecordId = cc.id;  
            newrecord.SendClosedTasks = true;
            newrecord.SendOpenTasks = true;
            newrecord.SendEmails = true;
            recordConnectionToInsert.add(newrecord);
        }
        if (recordConnectionToInsert.size() > 0){
            System.debug('>>> Sharing ' + recordConnectionToInsert.size() + ' records');
            insert recordConnectionToInsert;
        }


}

I am getting the following error when try to save a case record in the sorce org.
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger trCase caused an unexpected exception, contact your administrator: trCase: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject: Class.trCaseHandler.AddEmailSenderToCaseTeam: line 203, column 1

Upon inspection I see that its conflicting with handler class of  another trigger. Here is the code snippet of the methoid where the conflict is happening in the handler class. Am I missing something ?
public void AddEmailSenderToCaseTeam( case[] newCases )
    {
        CaseTeamMember[] team = new CaseTeamMember[]{};
        
        CaseTeamRole createRole = [SELECT Id FROM CaseTeamRole WHERE Name = 'Created By' LIMIT 1];
        
        MAP <String, Id> emailParentMap = new MAP <String, Id>{};
        for( case c: newCases )
        {
            emailParentMap.put( c.SuppliedEmail, null );
        }
        
        //check if case supplied email is in users
        User[] emailUsers = [select Id, Email from User where Email =: emailParentMap.keySet() order by Email, LastLoginDate desc];
        for( User u: emailUsers )
        {
            Id x = emailParentMap.get( u.Email );
            if( x == null )
                emailParentMap.put( u.Email, u.Id );
        }
        
        for( case c: newCases )
        {
            Id x = emailParentMap.get( c.SuppliedEmail );
            if( x != null )
            {
                team.add(new CaseTeamMember(ParentId = c.Id, MemberId = x,TeamRoleId = createRole.Id) );
            }
            else
            {
                String msg = 'Unable to add email-to-case sender ' + c.SuppliedEmail + ' to case team. No matching user found.';
                if(m_isExecuting)
                    c.addError( msg );
                ErrorMsgs.add(msg + ' [Case ID ' + c.ID + ']');
            }
        }
        insert team;
	}





 
viruSviruS
Please Check   trCaseHandler  class  line number 203 .. where some soql executing but no record exsist there ...