• Daniel Wretman
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
Hi

I have got stuck in a process where cases should be opened on new case comments but only on some criteria, listed below:

1. Open if comment is from a customer
2. Do not open if comment is posted by a support engineer
3. Do not open if the comment is made by a flow 

I seem not to be able to filter out the different user types and the case is opened regardless of who the user is. I have tried using the field 

HasCommentsUnreadByOwner

but this does not take in consideration which type of user made the comment. How can I get a process builder to look at the user type for this?
Hi

I am setting up a trigger and triggerHandler to send a post callout request, but I have issues with the code coverage. I do have the mocked http and do have a calloutClass and with it a calloutClassTest. this is working and give me the code coverage I need. My problem is with the handler class, it is initiated by a trigger so I can't call the true callout (named OPSImSendRequest) class. I have instead put a if statement on the callout to check if it is a test, if so I skip that part but doing that messes up my code coverage.

I am a bit lost on this, my code below:

public class OPSImSendRequest {

    public static HttpRequest sendRequest(map<string,string> data){ //was public static void,HttpRequest
            
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://alert.xxx.com/integrations/generic/20131114/alert/$YOUR_API_KEY_HERE/$ROUTING_KEY_HERE'); //not set to proper values yet.
         req.setMethod('POST');
        String body = JSON.serialize(data);
        req.setBody(body);
         req.setHeader('Content-Type','application/json;charset=UTF-8');
      
        HttpResponse res = new Http().send(req);           
        return req;

    }
}


@isTest
public class CalloutClassTest {
    @isTest
    public static void testPostCallout() {
        
    Test.setMock(HttpCalloutMock.class, new MockOPSImSendRequest());
    Map<String, String> data = new Map<String, String>();

    data.put('id','Id');
    data.put('salesforce_id','salesforce_id');
    data.put('event_type','event_type');
    data.put('acknowledge_by','acknowledge_by');
    data.put('timestamp','timeStamp');

    test.startTest();
    HttpRequest response = OPSImSendRequest.sendRequest(data);
    test.stopTest();
           
    }
    
}

@isTest
global class MockOPSImSendRequest implements HttpCalloutMock{
    
    global HTTPResponse respond (HTTPRequest request){  
       
        HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
        response.setStatus('OK');
        response.setStatusCode(200);
        return response;
        
    }
}

trigger opsIMEvents on Case (after insert, after update) {
    
    if(trigger.isUpdate && triggerIterationController.isFirstTime){
        
        for(case c : trigger.new){           
            if(c.Status == 'CLOSED' && c.Record_type__c =='Incident_Cases' && c.Origin_Event_case__c != null){
                opsIMEventsTriggerHandler.caseClosedIncident(c.id, c.CaseNumber, c.LastModifiedById, c.Last_Status_Change__c, c.Origin_Event_case__c);
                triggerIterationController.isFirstTime = false;

            }
public class opsIMEventsTriggerHandler {

     @future(callout=true)
     public static void caseRoutedIncident(Id incidentId, String incidentCaseNumber, String newCaseQueue, DateTime lastStatusChange, Id originEventId){

        String Id = originEventId;
        String salesforce_id=(String)incidentId;         
        String event_type='case_routed';                       
        String sf_case_no=incidentCaseNumber;                   
        String routed_to=newCaseQueue;
        String timeStamp=string.valueOfGMT(lastStatusChange);   
          
        Map<String, String> data = new Map<String, String>();
        
        data.put('id',id);
        data.put('salesforce_id',salesforce_id);
        data.put('event_type',event_type);
        data.put('sf_case_no',sf_case_no);
        data.put('routed_to',routed_to);
        data.put('timestamp',timeStamp);
        
         if (!Test.isRunningTest()){
             System.debug('is not a test: ');
             OPSImSendRequest.sendRequest(data);
        }else{
             System.debug('this seem to be a test on RoutedIncident');
             System.debug('routed incident, data map to send to victorops: '+data);
        }
         
    }
}
Hi all
I have been working on the first ever http callout for me, so it is based on the stuff in the trail head. But I hit some sort of snag I can't get around, hope one of you guys can help out. It is all very basic for now, will add assertions etc when the basics compile fine.

Everything except one line compile fine, so the issue is in my test class where I test the mock callout, I get the following compilation error: "Method does not exist or incorrect signature: void sendRequest() from the type OPSImSendRequest". This is from the "testPostCallout"  and the row is: "HttpResponse response = OPSImSendRequest.sendRequest();"

This is my code:

trigger opsIMEvents on Case (before insert) {
    
    if(trigger.isAfter){
        
        for(case c : trigger.new){
            if(c.Status == 'RESOLVED'){
            
                opsIMEventsTriggerHandler.caseEventResolved(c.OPS_IM_record_Id__c, c.Id, c.resolved_by__c, c.Last_Status_Change__c);
                
            }
     }

public class opsIMEventsTriggerHandler {                    
                                                                
     @future(callout=true)
    
    public static void caseEventResolved(Id eventVCId,Id eventSFId, Id resolvedBy, DateTime lastStatusChange){

        String event_type='event_resolved';                     
        String id=eventVCId;                                    
        String salesforce_id=eventSFId;                            
        String resolve_by=resolvedBy;                            
        String timeStamp=string.valueOfGMT(lastStatusChange);            
         
        Map<String, String> data = new Map<String, String>();
        
        data.put('id',id);
        data.put('salesforce_id',salesforce_id);
        data.put('event_type',event_type);       
        data.put('resolve_by',resolve_by);
        data.put('timestamp',timeStamp);
        
         OPSImSendRequest.sendRequest(data);

    }
}

public class OPSImSendRequest {
    
    public static void sendRequest (map<string,string> data){
        
        Http http = new Http();
        HttpRequest req = new HttpRequest();
         
         req.setEndpoint('https://alert.xxx.com/integrations/generic/20131114/alert/$YOUR_API_KEY_HERE/$ROUTING_KEY_HERE');  //I know, this is not a valid end point...
         req.setMethod('POST');
        String body = JSON.serialize(data);
         System.debug(body);
         req.setBody(body);
         req.setHeader('Content-Type','application/json;charset=UTF-8');
        HTTPResponse res = http.send(req);
         System.debug(res.getBody());
    }
}

@isTest
global class MockOPSImSendRequest implements HttpCalloutMock{
    
    global HTTPResponse respond (HTTPRequest request){  
        
        HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
        response.setStatusCode(200);
        return response;
        
    }
}

@isTest
    public static void testPostCallout() {
        
    Test.setMock(HttpCalloutMock.class, new MockOPSImSendRequest());
    
//    test.startTest();
    HttpResponse response = OPSImSendRequest.sendRequest();
//    test.stopTest();
           
        
    }
}


 
Hi

I have got stuck in a process where cases should be opened on new case comments but only on some criteria, listed below:

1. Open if comment is from a customer
2. Do not open if comment is posted by a support engineer
3. Do not open if the comment is made by a flow 

I seem not to be able to filter out the different user types and the case is opened regardless of who the user is. I have tried using the field 

HasCommentsUnreadByOwner

but this does not take in consideration which type of user made the comment. How can I get a process builder to look at the user type for this?
Hi

I am setting up a trigger and triggerHandler to send a post callout request, but I have issues with the code coverage. I do have the mocked http and do have a calloutClass and with it a calloutClassTest. this is working and give me the code coverage I need. My problem is with the handler class, it is initiated by a trigger so I can't call the true callout (named OPSImSendRequest) class. I have instead put a if statement on the callout to check if it is a test, if so I skip that part but doing that messes up my code coverage.

I am a bit lost on this, my code below:

public class OPSImSendRequest {

    public static HttpRequest sendRequest(map<string,string> data){ //was public static void,HttpRequest
            
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://alert.xxx.com/integrations/generic/20131114/alert/$YOUR_API_KEY_HERE/$ROUTING_KEY_HERE'); //not set to proper values yet.
         req.setMethod('POST');
        String body = JSON.serialize(data);
        req.setBody(body);
         req.setHeader('Content-Type','application/json;charset=UTF-8');
      
        HttpResponse res = new Http().send(req);           
        return req;

    }
}


@isTest
public class CalloutClassTest {
    @isTest
    public static void testPostCallout() {
        
    Test.setMock(HttpCalloutMock.class, new MockOPSImSendRequest());
    Map<String, String> data = new Map<String, String>();

    data.put('id','Id');
    data.put('salesforce_id','salesforce_id');
    data.put('event_type','event_type');
    data.put('acknowledge_by','acknowledge_by');
    data.put('timestamp','timeStamp');

    test.startTest();
    HttpRequest response = OPSImSendRequest.sendRequest(data);
    test.stopTest();
           
    }
    
}

@isTest
global class MockOPSImSendRequest implements HttpCalloutMock{
    
    global HTTPResponse respond (HTTPRequest request){  
       
        HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
        response.setStatus('OK');
        response.setStatusCode(200);
        return response;
        
    }
}

trigger opsIMEvents on Case (after insert, after update) {
    
    if(trigger.isUpdate && triggerIterationController.isFirstTime){
        
        for(case c : trigger.new){           
            if(c.Status == 'CLOSED' && c.Record_type__c =='Incident_Cases' && c.Origin_Event_case__c != null){
                opsIMEventsTriggerHandler.caseClosedIncident(c.id, c.CaseNumber, c.LastModifiedById, c.Last_Status_Change__c, c.Origin_Event_case__c);
                triggerIterationController.isFirstTime = false;

            }
public class opsIMEventsTriggerHandler {

     @future(callout=true)
     public static void caseRoutedIncident(Id incidentId, String incidentCaseNumber, String newCaseQueue, DateTime lastStatusChange, Id originEventId){

        String Id = originEventId;
        String salesforce_id=(String)incidentId;         
        String event_type='case_routed';                       
        String sf_case_no=incidentCaseNumber;                   
        String routed_to=newCaseQueue;
        String timeStamp=string.valueOfGMT(lastStatusChange);   
          
        Map<String, String> data = new Map<String, String>();
        
        data.put('id',id);
        data.put('salesforce_id',salesforce_id);
        data.put('event_type',event_type);
        data.put('sf_case_no',sf_case_no);
        data.put('routed_to',routed_to);
        data.put('timestamp',timeStamp);
        
         if (!Test.isRunningTest()){
             System.debug('is not a test: ');
             OPSImSendRequest.sendRequest(data);
        }else{
             System.debug('this seem to be a test on RoutedIncident');
             System.debug('routed incident, data map to send to victorops: '+data);
        }
         
    }
}
Hi all
I have been working on the first ever http callout for me, so it is based on the stuff in the trail head. But I hit some sort of snag I can't get around, hope one of you guys can help out. It is all very basic for now, will add assertions etc when the basics compile fine.

Everything except one line compile fine, so the issue is in my test class where I test the mock callout, I get the following compilation error: "Method does not exist or incorrect signature: void sendRequest() from the type OPSImSendRequest". This is from the "testPostCallout"  and the row is: "HttpResponse response = OPSImSendRequest.sendRequest();"

This is my code:

trigger opsIMEvents on Case (before insert) {
    
    if(trigger.isAfter){
        
        for(case c : trigger.new){
            if(c.Status == 'RESOLVED'){
            
                opsIMEventsTriggerHandler.caseEventResolved(c.OPS_IM_record_Id__c, c.Id, c.resolved_by__c, c.Last_Status_Change__c);
                
            }
     }

public class opsIMEventsTriggerHandler {                    
                                                                
     @future(callout=true)
    
    public static void caseEventResolved(Id eventVCId,Id eventSFId, Id resolvedBy, DateTime lastStatusChange){

        String event_type='event_resolved';                     
        String id=eventVCId;                                    
        String salesforce_id=eventSFId;                            
        String resolve_by=resolvedBy;                            
        String timeStamp=string.valueOfGMT(lastStatusChange);            
         
        Map<String, String> data = new Map<String, String>();
        
        data.put('id',id);
        data.put('salesforce_id',salesforce_id);
        data.put('event_type',event_type);       
        data.put('resolve_by',resolve_by);
        data.put('timestamp',timeStamp);
        
         OPSImSendRequest.sendRequest(data);

    }
}

public class OPSImSendRequest {
    
    public static void sendRequest (map<string,string> data){
        
        Http http = new Http();
        HttpRequest req = new HttpRequest();
         
         req.setEndpoint('https://alert.xxx.com/integrations/generic/20131114/alert/$YOUR_API_KEY_HERE/$ROUTING_KEY_HERE');  //I know, this is not a valid end point...
         req.setMethod('POST');
        String body = JSON.serialize(data);
         System.debug(body);
         req.setBody(body);
         req.setHeader('Content-Type','application/json;charset=UTF-8');
        HTTPResponse res = http.send(req);
         System.debug(res.getBody());
    }
}

@isTest
global class MockOPSImSendRequest implements HttpCalloutMock{
    
    global HTTPResponse respond (HTTPRequest request){  
        
        HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
        response.setStatusCode(200);
        return response;
        
    }
}

@isTest
    public static void testPostCallout() {
        
    Test.setMock(HttpCalloutMock.class, new MockOPSImSendRequest());
    
//    test.startTest();
    HttpResponse response = OPSImSendRequest.sendRequest();
//    test.stopTest();
           
        
    }
}