Monday 5 June 2017

Test Class for Live Chat Visitor, Live Chat Transcript and Live Chat Transcript Event.

Trigger

trigger LiveChatTranscriptEventTrigger on LiveChatTranscriptEvent (before delete) {
    /**
     * trigger runs
     *    
     */    
      ClsTriggerFactory.createHandler(LiveChatTranscriptEvent.sObjectType);

}

Apex Class


@name ClsTriggerLiveChatTranscriptEventHandler

public without sharing class ClsTriggerLiveChatTranscriptEventHandler extends ClsTriggerVirtual {
   /**
    * @see IntHelper.beforeTrigger
    */
    public override void beforeTrigger(ClsWrappers.TriggerContext trgCtx) {      
        if (trgCtx.IsInsert){
       
        }
        if(trgCtx.isUpdate){
       
        }
        if(trgCtx.isDelete){
            blockDelete(trgCtx);      
        }
    }
   
   
   /**
    * @see IntHelper.afterTrigger
    */
    public override void afterTrigger(ClsWrappers.TriggerContext trgCtx) {
       
    }
    /**
* Block Usere to Delete LiveChatTranscriptEvent record if his profile not in Validation_Override__c.Exclude__c
*/
    @TestVisible
    private void blockDelete(ClsWrappers.TriggerContext trgCtx) {
        Validation_Override__c mc = Validation_Override__c.getInstance(UserInfo.getProfileId());
        system.debug('mc= '+mc.Exclude__c);
        if (!mc.Exclude__c){
            for(sobject so : trgCtx.oldList){
                LiveChatTranscriptEvent liveEvent = (LiveChatTranscriptEvent)so;
                liveEvent.addError('Live Chat Transcript Event can not be deleted');
            }
        }
    }
}

Test Class

@isTest(seeAllData = false)
public class ClsTriLiveChatTransEvtHandlr_Test{
    static testMethod void getevent(){
        /*
            insert Live Chat Visitor
        */
        LiveChatVisitor lcv = new LiveChatVisitor();
        try{
            insert lcv;
        }catch(Exception e){}
        /*
            insert Live Chat Transcript
        */
        LiveChatTranscript lct = new LiveChatTranscript();
        lct.LiveChatVisitorid = lcv.id;
        try{
            insert lct;
        }catch(Exception e){}
        system.debug('lct' + lct);
                /*
            insert Live Chat Transcript Event
        */
        LiveChatTranscriptEvent le = new LiveChatTranscriptEvent();
        le.LiveChatTranscriptId = lct.id;
        le.type = 'ChatRequest';
        le.time = system.now();
        try{
            insert le;
        }
        catch(Exception e){}
        try{
            delete le;
        }
        catch(Exception e){}
     }
}

6 comments:

  1. This is a great article thanks for sharing this informative information. I will visit your blog regularly for some latest post. I will visit your blog regularly for Some latest post. free online chat rooms

    ReplyDelete
  2. I enjoy every one of the post, My spouse and i liked, I might like additional data using this type of, since it can be pretty nice., Regards created for supplying. live chat support service provider

    ReplyDelete
  3. We believe in customer satisfaction. Our Leather Jackets are delicately and uniquely tailored, and the comfort of our customers is always prioritizing. We guarantee the quality of our product and take full responsibility to satisfy our customer’s needs. Guess Bags For Women

    ReplyDelete
  4. We guarantee to bring you the grand quality material and leather that includes Sheepskin, Lambskin, Faux leather, Suede leather, and Distressed Leather. Mens Biker Jacket

    ReplyDelete
  5. It is the easiest element in the world, but overall the notion is quite sound. freechat

    ReplyDelete

Batch Apex

1. What are transaction limits in apex? Total number of SOQL queries issued1 - 100 Total number of records retrieved by SOQL queries - 50...