• anu jain
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
Hi All,
I have written the trigger for changing the case owner field from livechattranscript object  case owner field.If one chat request came and agent accept that chat and after that agent assign that request to new agent.If we assign the same case to another agent.when request came to another agent and agent accept that chat then transcript case owner field is changing to "who accept the Chat" but when case is linked to that chat then case owner field is not changing to current agent name .Please anyone suggest how we can write the trigger for that .I have written the trigger but its not working.
when chat request is coming then its not associating case to that chat.
My code below.

trigger LiveChatTranscriptTrigger on LiveChatTranscript (after insert) {

    if(Trigger.isInsert && Trigger.isAfter){        
        Set<String> caseIds = new Set<String>();
        for ( LiveChatTranscript transcript : Trigger.new ) {
            if ( !String.isBlank( transcript.caseId ) ) {
                caseIds.add( transcript.caseId );
                system.debug(caseIds);
            }
            
        }
        System.debug('CaseIds' +caseIds);
        if ( caseIds.size() > 0 ) {
            List<Case> cases = new List<Case>([SELECT id from Case WHERE Id IN :caseIds ORDER BY createdDate ASC ]);            
            Map<String, Case> CasesIdsMap = new Map<String, Case>();
            System.debug('2');
            for ( Case cs : cases ) {
                CasesIdsMap.put( cs.id, cs );
            }
            System.debug( 'CasesIdsMap=' + CasesIdsMap );
            List<case> caseToUpdate = new List<case>();
            
            for ( LiveChatTranscript transcript : Trigger.new ) {
             System.debug('3');
                if ( !String.isBlank( transcript.caseId ) ) {
                    Case cs = CasesIdsMap.get( transcript.caseId );
                    if ( cs != null ) {
                        caseToUpdate .add( new case(
                        ownerId=transcript.ownerId,
                            id = transcript.caseid
                            //caseId = cs.id
                            
                        ));
                    }
                    
                }
                
            }
            if ( caseToUpdate .size() > 0 ) {
                System.debug( 'caseToUpdate : ' +caseToUpdate );
                 update caseToUpdate ;
            }
            
        }
    }
    
}
And Trigger is not genering the log also
Hi All 
We have configured live agent in my org,
We have observed the case owner field is not changing after case is transfer  to other agent .How we can change  case owner field to current user  name(who accept the chat).

Thanks,
Shivangni