Skip to main content

Hi there, 

I'm building an Apex batch for sending emails with link to surveys to the Contact in a Case. 

Is also required to relate the survey to the Case. 

To get that, in the batch class, I inserted the participants in the SurveyInvitation and after that, I inserted SurveySubject to relate the survey to the Case.

            SurveyInvitation invite = new SurveyInvitation();            invite.Name = param.CRM_Encuesta__c; // survey invitation name            invite.ParticipantId = c.ContactId;            invite.CommunityId = surveyCommunityId;            invite.OptionsAllowGuestUserResponse = false;            invite.SurveyId = surveyId;            invite.OwnerId = c.OwnerId;            invite.CRM_Case__c = c.Id;            invitations.add(invite);...            insert invitations;            // add Subjects to the invitations            List<SurveySubject> subjects = new List<SurveySubject>();            for (SurveyInvitation invite : invitations) {                SurveySubject subject = new SurveySubject();                subject.ParentId = invite.Id;                subject.SubjectId = invite.CRM_Case__c;                subject.Name = invite.Name;                subjects.add(subject);            }

However, nothing is sent to the contact's email.

I was told that I must use Surveys.sendSurveyInvitationEmail() method for sending the emails. However, using it, I see SurveyInvitation records it generates, but I have no way to relate them with SurveySubject records to associate them to respective Cases.

Any idea on how to solve it? Thanks in advance! 

 

@* Salesforce Developers *

 

 

#Salesforce Developer

1 Antwort
  1. 24. Mai 2025, 15:26

    Hi @Ernesto S Melgin

     

    To associate survey invitations with cases, you can use Flows to automatically create SurveySubject records that link each SurveyInvitation to its corresponding Case. This ensures survey responses are accurately connected and traceable within the related case records.

    Useful references:

    https://automationchampion.com/2022/04/20/send-salesforce-survey-without-code-2/

     

    https://help.salesforce.com/s/articleView?id=000391879&type=1

     

    https://help.salesforce.com/s/articleView?id=release-notes.rn_cases_surveys.htm&release=222&type=5

     

     

    Thanks!

0/9000