• prathyusha nalabolu
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    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 , My entire application works on Opportunity history data (all batches) , There are cases like opportunites close dates changed in current month or previous month and much like this, evaluating previous one year data. I can create oppoturinity but I need its history in previous periods as well for traversing various of my If and else conditions, This seems next to impossible, I cannot use seeAllData=true, as it is a package and when installed on other system may fail. What can be the hack here?
 
Any help would be appreciated!!!