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
Manish SrivastavaManish Srivastava 

GiveWorkThanksAction

Unable to save the file for apex code : GiveWorkThanksAction.

Need quick help. Thanks in advance.
Raj VakatiRaj Vakati
Refer this link 


Make sure you enable the work.com 


https://help.salesforce.com/articleView?id=networks_recog_badges_workcom.htm&type=5



https://success.salesforce.com/answers?id=9063A000000t0ccQAA
Manish SrivastavaManish Srivastava
Hi Thanks for replying but i am pasting the below apex code ut still not working. i can see errors.

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;