function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jerry NiemeyerJerry Niemeyer 

I can't get challenge to complete for Automate Post-Workshop Tasks with Invocable Apex

I am trying to complete "Automate Your Business Processes:  Build an Automated Workshop Management System: Automate Post-Workshop Tasks with Invocable Apex " and when I click "verify step" I get -
Challenge Not yet complete... here's what's wrong: 
Couldn't find the "Thanks" badge in the instructor's Chatter feed after completing a Campaign.

I have rebuilt the flow and the APEX and I can't get it to complete, but the "Thanks" badge IS in the insturctor's feed when I change the campaign to complete, so everything seems to work, I just cant get it to "verify"
SandhyaSandhya (Salesforce Developers) 
Hi,

Try to compare your work with screenshots in the module and make sure the spellings of the name are correct.Please post the screenshots of your work so that I can help you further.

Thanks and Regards
Sandhya
Jerry NiemeyerJerry Niemeyer
I was able to complete the challenge, I made 2 changes and am not sure which one helped.  I had mispelled the word "awseome" in the text for the automated chatter post - I would not have thought the challenge would have verified the text in the post - but maybe so.  I also changed the label for the APEX code inside the sample snippet we were given, it did not match the label shown in instructions for a later step.  But it completed after those changes.  Thanks.
ArunBalaji KArunBalaji K
global without sharing class GiveWorkThanksAction {

    @InvocableMethod(label='Give a Thanks Badge')
    global static void giveWorkBadgeActionsBatch(List<GiveWorkThanksRequest> requests) {
        for(GiveWorkThanksRequest request: requests){
            giveWorkBadgeAction(request);
        }
    }

    public static void giveWorkBadgeAction(GiveWorkThanksRequest request) {
        WorkThanks newWorkThanks = new WorkThanks();

                newWorkThanks.GiverId = request.giverId;
                newWorkThanks.Message = request.thanksMessage;
                newWorkThanks.OwnerId = request.giverId;

        insert newWorkThanks;


        WorkBadge newWorkBadge = new WorkBadge();

                // newWorkBadge.DefinitionId should be set to the ID for the Competitor Badge within this Org
                WorkBadgeDefinition workBadgeDef = [SELECT Id,Name FROM WorkBadgeDefinition WHERE Name = :request.badgeName Limit 1];

                newWorkBadge.DefinitionId = workBadgeDef.Id;
                newWorkBadge.RecipientId = request.receiverId;
                newWorkBadge.SourceId = newWorkThanks.Id ;
                //newWorkBadge.GiverId = request.giverId;

        insert newWorkBadge;

        WorkThanksShare newWorkThanksShare = new WorkThanksShare();

                newWorkThanksShare.ParentId = newWorkThanks.Id ;
                newWorkThanksShare.UserOrGroupId = request.receiverId;

                newWorkThanksShare.AccessLevel = 'Edit';
                insert newWorkThanksShare;

        FeedItem post = new FeedItem();

                post.ParentId = request.receiverId;
                post.CreatedById = request.giverId;
                post.Body = request.thanksMessage;
                post.RelatedRecordId = newWorkThanks.Id ;
                post.Type = 'RypplePost';

        insert post;

    }

    global class GiveWorkThanksRequest {
        @InvocableVariable(label='Giver Id' required=true)
        global Id giverId;

        @InvocableVariable(label='Receiver Id' required=true)
        global Id receiverId;

        @InvocableVariable(label='Thanks Message' required=true)
        global String thanksMessage;

        @InvocableVariable(label='Badge Name' required=true)
        global String badgeName;
    }
}

User-added image

I cant even save this file anyone plz help me ...
Diego PonceDiego Ponce
I am stuck in the same step. I have copied the apex code mentioned in trailhead and have the same errors.
KARRIE CHENGKARRIE CHENG
If you've copied the apex code from the trailhead, you need to make one minor (but important) change:

On line 27, instead of 
insert newWorkThanksShare;

you need to have
upsert newWorkThanksShare;

This is because WorkThanksShare objects cannot be inserted (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_workthanksshare.htm).
Manish SrivastavaManish Srivastava
Hi , I am also struck in same process. Although i have copied the same code from trailhead but i get 20 errors, hence unable to save. Plz help. I tried updating on line-27 (upsert), please help. Unable to finish the trailhead. Thanks in advance.

global without sharing class GiveWorkThanksAction {
    @InvocableMethod(label='Give a Thanks Badge')
    global static void giveWorkBadgeActionsBatch(List<GiveWorkThanksRequest> requests) {
        for(GiveWorkThanksRequest request: requests){
            giveWorkBadgeAction(request);
        }
    }
    public static void giveWorkBadgeAction(GiveWorkThanksRequest request) {
        WorkThanks newWorkThanks = new WorkThanks();
                newWorkThanks.GiverId = request.giverId;
                newWorkThanks.Message = request.thanksMessage;
                newWorkThanks.OwnerId = request.giverId;
        insert newWorkThanks;

        WorkBadge newWorkBadge = new WorkBadge();
                // newWorkBadge.DefinitionId should be set to the ID for the Competitor Badge within this Org
                WorkBadgeDefinition workBadgeDef = [SELECT Id,Name FROM WorkBadgeDefinition WHERE Name = :request.badgeName Limit 1];
                newWorkBadge.DefinitionId = workBadgeDef.Id;
                newWorkBadge.RecipientId = request.receiverId;
                newWorkBadge.SourceId = newWorkThanks.Id ;
                //newWorkBadge.GiverId = request.giverId;
        insert newWorkBadge;
        WorkThanksShare newWorkThanksShare = new WorkThanksShare();
                newWorkThanksShare.ParentId = newWorkThanks.Id ;
                newWorkThanksShare.UserOrGroupId = request.receiverId;
                newWorkThanksShare.AccessLevel = 'Edit';
                upsert newWorkThanksShare;
        FeedItem post = new FeedItem();
                post.ParentId = request.receiverId;
                post.CreatedById = request.giverId;
                post.Body = request.thanksMessage;
                post.RelatedRecordId = newWorkThanks.Id ;
                post.Type = 'RypplePost';
        insert post;
    }
    global class GiveWorkThanksRequest {
        @InvocableVariable(label='Giver Id' required=true)
        global Id giverId;
        @InvocableVariable(label='Receiver Id' required=true)
        global Id receiverId;
        @InvocableVariable(label='Thanks Message' required=true)
        global String thanksMessage;