• Jesper Klang.
  • NEWBIE
  • 135 Points
  • Member since 2016
  • Salesforce Solution Consultant
  • Fluido


  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 12
    Replies
Hi Folks,

I am attempting Service Cloud super badge which was recently released. I am trying to complete challenge no 3 - Create service level and actions.

We have to set up minimum response time and resolution time. The problem I face here is I do not see the response time in minutes. 

In the challenge, it mentions 20 minutes and I am not finding a way to set minutes, every process(Time-based workflow, Entitlement hours, Escalation rules) are in hours and there is no provision to set in decimal.

Am I heading in the right direction? Please suggest.

 
Hi Guys,

I would kindly like to ask for your help. I am a beginner Apex student, but I am stuck with a trigger :(.
I created a custom field on the case SObject which should serve as a counter.
The trigger should count the string occurences in only outgoing emails and return the # value to this field.
Basically what I want is there are negative words and positive ones (counter should be like positive - negative found words)

This is how far I got:

trigger CaseEmailScore on Case (after insert, after update) {
  
    // Word criteria table,List
    List<String> positiveWords = new List<String>();
    positiveWords.add('Dear');
    positiveWords.add('Kind');
    positiveWords.add('Dreamforce');
    positiveWords.add('Kind regards,');
    positiveWords.add('Best regards,');
    
    List<String> negativeWords = new List<String>();
    negativeWords.add('wtf');
    negativeWords.add('I\'m');
    negativeWords.add('stupid');
    
    for (Case myCase : Trigger.new) {
       
    // Create list of positive emails which are within cases
    List<EmailMessage> caseEmails = [ SELECT  Id,
                                                                               HtmlBody,
                                                                               TextBody,
                                                                               FromAddress,
                                                                               ParentId
                                                               FROM   EmailMessage
                                                            WHERE  ParentId != null];
                                                               //AND  TextBody LIKE :positiveWords]; -> ERROR: TextBody and Html can not be filtered in query call    
        }
    }                                        
    
    //Counting calculations possible .countMatches()


I would really appreciate if you could help, so I can understand and continue learning :).



 
Hi,

I've tried for hours, but cannot seem to figure out how to create a test class for the Apex code below. I'm using it to present a dynamic picklist to a LWC based on values added to a Custom Metadata Type I created.

One error I'm facing when trying to call the class is "Method is not Visible". This is when I'm trying to call the class with a row first like this: 
brandedSectionColorPicklistValues bSCPV = new brandedSectionColorPicklistValues();
VisualEditor.DynamicPickListRows rows = bSCPV.getValues();
Here's the full class I'm trying to write a Test Class for:
global class brandedSectionColorPicklistValues extends VisualEditor.DynamicPickList {
    private VisualEditor.DynamicPickListRows  myValues = new VisualEditor.DynamicPickListRows();

    brandedSectionColorPicklistValues() {
        for (Brand_Color__mdt c : [SELECT MasterLabel, Background_Color__c, Font_Color__c FROM Brand_Color__mdt ORDER BY MasterLabel ASC]) {
            myValues.addRow(new VisualEditor.DataRow(c.MasterLabel, 'background-color:' + c.Background_Color__c + ';border-color:' + c.Background_Color__c + ';color:' + c.Font_Color__c + ';'));
        }
    }
    
    global override VisualEditor.DataRow getDefaultValue() {
        return myValues.get(0);
    }

    global override VisualEditor.DynamicPickListRows getValues() {
        return myValues;
    }
}
Any help is appreciated!
/Jesper
Hi!

I'm doing a challenge where I need to get my test class to at least 90%. I'm currently getting the error message 'System.SerializationException: Not Serializable: System.HttpRequest'. I've searched around but can't figure out how to solve it.

Can someone be kind and have a look at my code?
global class ProjectCalloutService {
    
    global class QueueablePMSCall implements Queueable, Database.AllowsCallouts {
        HttpRequest req = new HttpRequest();
        Opportunity opp = new Opportunity();
        
        global QueueablePMSCall(HttpRequest req, ID oppId){
            this.req = req;
            this.opp.Id = oppId;
        }
        
        global void execute(QueueableContext context) {
            Http http = new Http();
			HttpResponse res = http.send(req);
            if (res.getStatusCode() == 201) {
                opp.StageName = 'Submitted Project';
                System.debug('Successfully submitted!');
            } else {
                opp.StageName = 'Resubmit Project';
                System.debug('Failed to submit! Error message: ' + res.getStatus());
            }
            update opp;
        }
    }
    
    @InvocableMethod(label='Post Opportunity To PMS' description='Posts the triggered Opportunity to the PMS system')
	public static void postOpportunityToPMS(List<ID> Opportunity_Id){
        ID oppId = Opportunity_Id[0];
        Opportunity opp = [SELECT Name, Account.Name, CloseDate, Amount FROM Opportunity WHERE ID = :oppId]; 
        HttpRequest req = new HttpRequest();
        req.setEndpoint('callout:ProjectService');
        req.setMethod('POST');
        req.setHeader('Content-Type', 'application/json');
        req.setHeader('token', ServiceTokens__c.getValues('ProjectServiceToken').Token__c);
        req.setBody('{"opportunityId": ' + opp.Id + 
                        ', "opportunityName": ' + opp.Name + 
                        ',"accountName": ' + opp.Account.Name + 
                        ', "closeDate": ' + opp.CloseDate + 
                        ',"amount": ' + opp.Amount + '}');
        QueueablePMSCall toQueue = new QueueablePMSCall(req, opp.Id);
        ID jobID = System.enqueueJob(toQueue);
        System.debug('jobID: ' + jobID);
    }
}
Test class:
@isTest
private class ProjectCalloutServiceTest {
  	@Testsetup static void TestSetup() {
        Account acc = new Account(Name = 'Jespers Account');
        insert acc;
        Opportunity opp1 = new Opportunity(Name = 'Opp1', 
                                          AccountId = acc.id, 
                                          CloseDate = Date.today(), 
                                          Amount = 1000, 
                                          StageName = 'Closed/Won',
                                          Type = 'New Project');
        insert opp1;
        Opportunity opp2 = new Opportunity(Name = 'Opp2', 
                                          AccountId = acc.id, 
                                          CloseDate = Date.today(), 
                                          Amount = 3000, 
                                          StageName = 'Closed/Won', 
                                          Type = 'New Project');
        insert opp2;
        ServiceTokens__c servToken = new ServiceTokens__c();
        servToken.Name = 'ProjectServiceToken';
        servToken.Token__c = 'qwertyuiopnjhgft';
        insert servToken;
    }
    
  	@isTest
    static void TestSuccess() {
        ID oppId = [SELECT Name FROM Opportunity WHERE Name = 'Opp1'].Id;
        List<ID> oppList = new List<ID>();
        oppList.add(oppId);
        Test.setMock(HttpCalloutMock.class, new ProjectCalloutServiceMock());
        Test.startTest();
        ProjectCalloutService.postOpportunityToPMS(oppList);
		Test.stopTest();
        String testOpp = [SELECT StageName FROM Opportunity WHERE ID = :oppId].StageName;
        System.assertEquals('Submitted Project', testOpp);
    }
    
  	@isTest
    static void TestFail() {
        ID oppId = [SELECT Name FROM Opportunity WHERE Name = 'Opp2'].Id;
        List<ID> oppList = new List<ID>();
        oppList.add(oppId);
        Test.startTest();
        Test.setMock(HttpCalloutMock.class, new ProjectCalloutServiceMockFailure());
        ProjectCalloutService.postOpportunityToPMS(oppList);
		Test.stopTest();
        String testOpp = [SELECT StageName FROM Opportunity WHERE ID = :oppId].StageName;
        System.assertEquals('Resubmit Project', testOpp);
    }
}
First Mock:
@isTest
global class ProjectCalloutServiceMock implements HttpCalloutMock{
    global HttpResponse respond(HttpRequest req) {
        HttpResponse res = new HttpResponse();
        res.setStatusCode(201);
        res.setStatus('OK');
        return res;
    }
}
Second Mock:
@isTest
global class ProjectCalloutServiceMockFailure implements HttpCalloutMock{
    global HttpResponse respond(HttpRequest req) {
        HttpResponse res = new HttpResponse();
        res.setStatusCode(500);
        res.setStatus('This is an error message!');
        return res;
    }
}
  • Event Monitoring is Advanced | Admin
  • Transaction Security is Advanced | Admin
  • Shield Platform Encryption is Advanced | Admin

So, the Trail should logically be listed as Advanced | Admin as well instead of Beginner as is today :)

Thanks!
I need the Status of a Case to change from "Pending..." to "Notes Recieved" when there's a reply on a Post. I've tried to make this happen with Process Builder but found out that it's only possible with a Apex Trigger. That's where I need some help, and hope that someone can help me with the code.

So the Status of the Case need to change to "Notes Recieved" when:
  • Case Status contains "Pending" (we have different statuses ex "Pending Internal", "Pending Customer" etc.)
  • Someone other than the Case Owner writes a comment on a Post in the Case.
Thanks is advance!
Hi,

I've tried for hours, but cannot seem to figure out how to create a test class for the Apex code below. I'm using it to present a dynamic picklist to a LWC based on values added to a Custom Metadata Type I created.

One error I'm facing when trying to call the class is "Method is not Visible". This is when I'm trying to call the class with a row first like this: 
brandedSectionColorPicklistValues bSCPV = new brandedSectionColorPicklistValues();
VisualEditor.DynamicPickListRows rows = bSCPV.getValues();
Here's the full class I'm trying to write a Test Class for:
global class brandedSectionColorPicklistValues extends VisualEditor.DynamicPickList {
    private VisualEditor.DynamicPickListRows  myValues = new VisualEditor.DynamicPickListRows();

    brandedSectionColorPicklistValues() {
        for (Brand_Color__mdt c : [SELECT MasterLabel, Background_Color__c, Font_Color__c FROM Brand_Color__mdt ORDER BY MasterLabel ASC]) {
            myValues.addRow(new VisualEditor.DataRow(c.MasterLabel, 'background-color:' + c.Background_Color__c + ';border-color:' + c.Background_Color__c + ';color:' + c.Font_Color__c + ';'));
        }
    }
    
    global override VisualEditor.DataRow getDefaultValue() {
        return myValues.get(0);
    }

    global override VisualEditor.DynamicPickListRows getValues() {
        return myValues;
    }
}
Any help is appreciated!
/Jesper
Hi Folks,

I am attempting Service Cloud super badge which was recently released. I am trying to complete challenge no 3 - Create service level and actions.

We have to set up minimum response time and resolution time. The problem I face here is I do not see the response time in minutes. 

In the challenge, it mentions 20 minutes and I am not finding a way to set minutes, every process(Time-based workflow, Entitlement hours, Escalation rules) are in hours and there is no provision to set in decimal.

Am I heading in the right direction? Please suggest.

 
Hi!

I'm doing a challenge where I need to get my test class to at least 90%. I'm currently getting the error message 'System.SerializationException: Not Serializable: System.HttpRequest'. I've searched around but can't figure out how to solve it.

Can someone be kind and have a look at my code?
global class ProjectCalloutService {
    
    global class QueueablePMSCall implements Queueable, Database.AllowsCallouts {
        HttpRequest req = new HttpRequest();
        Opportunity opp = new Opportunity();
        
        global QueueablePMSCall(HttpRequest req, ID oppId){
            this.req = req;
            this.opp.Id = oppId;
        }
        
        global void execute(QueueableContext context) {
            Http http = new Http();
			HttpResponse res = http.send(req);
            if (res.getStatusCode() == 201) {
                opp.StageName = 'Submitted Project';
                System.debug('Successfully submitted!');
            } else {
                opp.StageName = 'Resubmit Project';
                System.debug('Failed to submit! Error message: ' + res.getStatus());
            }
            update opp;
        }
    }
    
    @InvocableMethod(label='Post Opportunity To PMS' description='Posts the triggered Opportunity to the PMS system')
	public static void postOpportunityToPMS(List<ID> Opportunity_Id){
        ID oppId = Opportunity_Id[0];
        Opportunity opp = [SELECT Name, Account.Name, CloseDate, Amount FROM Opportunity WHERE ID = :oppId]; 
        HttpRequest req = new HttpRequest();
        req.setEndpoint('callout:ProjectService');
        req.setMethod('POST');
        req.setHeader('Content-Type', 'application/json');
        req.setHeader('token', ServiceTokens__c.getValues('ProjectServiceToken').Token__c);
        req.setBody('{"opportunityId": ' + opp.Id + 
                        ', "opportunityName": ' + opp.Name + 
                        ',"accountName": ' + opp.Account.Name + 
                        ', "closeDate": ' + opp.CloseDate + 
                        ',"amount": ' + opp.Amount + '}');
        QueueablePMSCall toQueue = new QueueablePMSCall(req, opp.Id);
        ID jobID = System.enqueueJob(toQueue);
        System.debug('jobID: ' + jobID);
    }
}
Test class:
@isTest
private class ProjectCalloutServiceTest {
  	@Testsetup static void TestSetup() {
        Account acc = new Account(Name = 'Jespers Account');
        insert acc;
        Opportunity opp1 = new Opportunity(Name = 'Opp1', 
                                          AccountId = acc.id, 
                                          CloseDate = Date.today(), 
                                          Amount = 1000, 
                                          StageName = 'Closed/Won',
                                          Type = 'New Project');
        insert opp1;
        Opportunity opp2 = new Opportunity(Name = 'Opp2', 
                                          AccountId = acc.id, 
                                          CloseDate = Date.today(), 
                                          Amount = 3000, 
                                          StageName = 'Closed/Won', 
                                          Type = 'New Project');
        insert opp2;
        ServiceTokens__c servToken = new ServiceTokens__c();
        servToken.Name = 'ProjectServiceToken';
        servToken.Token__c = 'qwertyuiopnjhgft';
        insert servToken;
    }
    
  	@isTest
    static void TestSuccess() {
        ID oppId = [SELECT Name FROM Opportunity WHERE Name = 'Opp1'].Id;
        List<ID> oppList = new List<ID>();
        oppList.add(oppId);
        Test.setMock(HttpCalloutMock.class, new ProjectCalloutServiceMock());
        Test.startTest();
        ProjectCalloutService.postOpportunityToPMS(oppList);
		Test.stopTest();
        String testOpp = [SELECT StageName FROM Opportunity WHERE ID = :oppId].StageName;
        System.assertEquals('Submitted Project', testOpp);
    }
    
  	@isTest
    static void TestFail() {
        ID oppId = [SELECT Name FROM Opportunity WHERE Name = 'Opp2'].Id;
        List<ID> oppList = new List<ID>();
        oppList.add(oppId);
        Test.startTest();
        Test.setMock(HttpCalloutMock.class, new ProjectCalloutServiceMockFailure());
        ProjectCalloutService.postOpportunityToPMS(oppList);
		Test.stopTest();
        String testOpp = [SELECT StageName FROM Opportunity WHERE ID = :oppId].StageName;
        System.assertEquals('Resubmit Project', testOpp);
    }
}
First Mock:
@isTest
global class ProjectCalloutServiceMock implements HttpCalloutMock{
    global HttpResponse respond(HttpRequest req) {
        HttpResponse res = new HttpResponse();
        res.setStatusCode(201);
        res.setStatus('OK');
        return res;
    }
}
Second Mock:
@isTest
global class ProjectCalloutServiceMockFailure implements HttpCalloutMock{
    global HttpResponse respond(HttpRequest req) {
        HttpResponse res = new HttpResponse();
        res.setStatusCode(500);
        res.setStatus('This is an error message!');
        return res;
    }
}
Hi Guys,

I would kindly like to ask for your help. I am a beginner Apex student, but I am stuck with a trigger :(.
I created a custom field on the case SObject which should serve as a counter.
The trigger should count the string occurences in only outgoing emails and return the # value to this field.
Basically what I want is there are negative words and positive ones (counter should be like positive - negative found words)

This is how far I got:

trigger CaseEmailScore on Case (after insert, after update) {
  
    // Word criteria table,List
    List<String> positiveWords = new List<String>();
    positiveWords.add('Dear');
    positiveWords.add('Kind');
    positiveWords.add('Dreamforce');
    positiveWords.add('Kind regards,');
    positiveWords.add('Best regards,');
    
    List<String> negativeWords = new List<String>();
    negativeWords.add('wtf');
    negativeWords.add('I\'m');
    negativeWords.add('stupid');
    
    for (Case myCase : Trigger.new) {
       
    // Create list of positive emails which are within cases
    List<EmailMessage> caseEmails = [ SELECT  Id,
                                                                               HtmlBody,
                                                                               TextBody,
                                                                               FromAddress,
                                                                               ParentId
                                                               FROM   EmailMessage
                                                            WHERE  ParentId != null];
                                                               //AND  TextBody LIKE :positiveWords]; -> ERROR: TextBody and Html can not be filtered in query call    
        }
    }                                        
    
    //Counting calculations possible .countMatches()


I would really appreciate if you could help, so I can understand and continue learning :).



 
I need the Status of a Case to change from "Pending..." to "Notes Recieved" when there's a reply on a Post. I've tried to make this happen with Process Builder but found out that it's only possible with a Apex Trigger. That's where I need some help, and hope that someone can help me with the code.

So the Status of the Case need to change to "Notes Recieved" when:
  • Case Status contains "Pending" (we have different statuses ex "Pending Internal", "Pending Customer" etc.)
  • Someone other than the Case Owner writes a comment on a Post in the Case.
Thanks is advance!