Sunday, 6 December 2020

How to hide NEW button on top of a related list in lightning (Salesforce)


How to hide the NEW button on top of any Related List (RL) component

                            


Salesforce Survey getting "Page Not Found: /aura error message when sending a Survey to participants outside your company."

If you see an error like "Page Not Found: /aura" error message for community-based external survey invitations:


You probably are missing the required Survey Objects permission for your community guest user.


To Fix this :

  1. From Setup, enter Survey in the Quick Find box, then select Survey Settings.
  2. Check which community is selected as the default community to create public survey invitations.
  3. Enter Communities in the Quick Find box, then select All Communities.
  4. Open Experience Builder of the default community.
  5. From Experience Builder, click Settings icon, and select General.
  6. Click the profile name under Guest User Profile.
  7. Click Edit.
  8. In the Standard Object Permissions section, give guest users the following permissions:
    1. OBJECT2.PERMISSIONS
      Survey    Read
      Survey Invitations    Read
      Survey Responses    Read AND Create
  9. Click Save.



How to populate values in "Survey Invitations and Response" RL in Salesforce Survey


Not seeing values populated in "Survey Invitations and Response" RL you added to your Case, Opportunity or any other supported Objetc?


Do not worry, go through this simple article below to under

Firstly I would like to make it clear that there are two types of RL -

  • 'Survey Invitation' RL
  • 'Survey Invitation and Response' RL

The first 'Survey Invitation' RL populates only Survey Invitation relation details on any Object when Survey Invitation object has a lookup created (either standard or custom ) on that object.


However 'Survey Invitation and Response' RL is a bit different and as mentioned in the Salesforce Survey document -  "To populate the survey invitation fields and the survey response fields, the survey invitation records, and the survey response records must be associated with the SurveySubject object records."


So this displays Survey invitation related details if there is a related record created between Survey Invitation and Survey Subject records.

Similarly, it displays Survey Response related details if there is a related record created between Survey Response and Survey Subject records.



To understand this better see this example:


Let say you added your RL to Case Object following the steps mentioned in the Salesforce Survey document 

But You see no data populated in the "Survey Invitations and Response" RL 




Now use the below code to generate Survey Invitations and then created Survey Invitation and response related record with Survey Subject.


public
class CreateEntriesInSurveyInvitationRespRL {
// Utility to create SurveyInvitation and SurveySubject record
public static void addEntry(String associatedRecordId, String surveyId, String participantId) {
String invitationId = createSurveyInvitation(surveyId, participantId);

createSurveySubject(invitationId, associatedRecordId);
}

// Create an unauthenticated invitation by setting the surveyId and participantId
private static String createSurveyInvitation(String surveyId, String participantId) {
SurveyInvitation surveyInv = new SurveyInvitation();
surveyInv.Name = 'SurveyInvitationForCase'; // add your survey invitation name here
surveyInv.ParticipantId = participantId;
surveyInv.CommunityId = '0DBRM0000004n4y'; //add your community id here
surveyInv.OptionsAllowGuestUserResponse = true;
surveyInv.SurveyId = surveyId;

// Insert the SurveyInvitation Record
insert surveyInv;

return surveyInv.Id;
}

// Associate the above invitation to the required record (eg: Case, Opportunity...)
private static void createSurveySubject(String invitationId, String associatedRecordId) {
SurveySubject subj = new SurveySubject();
subj.Name = 'Sur_Subject_for_invitation';
subj.ParentId = invitationId; // similary you can use survey response id to associate survey subject to a response record.
subj.SubjectId = associatedRecordId;

// Insert the SurveySubject Record
insert subj;
}
}



//Use this trigger to create a survey subject record associated to
//the Survey Response record
trigger SurveyResponseForCaseTrigger on SurveyResponse (after insert) {
System.debug('Inside Survey response trigger ');
for(SurveyResponse sr: Trigger.New)
{
SurveySubject subj = new SurveySubject();
subj.Name = 'Sur_Subject_for_response';
subj.ParentId = sr.id; //Associating survey response id
//Get the associatedRecordId recordId (like Case, Opportunity etc) using the SurveyInvitation Id and
//assigning it to SubjectId, assuming we inserted SurveySubject record for the associated invitation
//using the previous code
List<SurveySubject> SurSubj=[select subjectid from SurveySubject where parentid = :sr.invitationId];
for(SurveySubject sub:SurSubj){
String ids=String.valueOf(sub.subjectid).substring(0,3);
if('500'.equals(ids)){
subj.SubjectId =sub.subjectid;
// Insert the SurveySubject Record
insert subj;
break;
}
}






You will now see all invitation and response data created.




Note- You can implement the same thing using a process as well.
You will need to create two processes, one on the SurveyInvitation record and the other on the SurveyResponse record, and then create corresponding Survey Subject records for them.






How to generate QR code for Survey Invitation in Salesforce Platform Survey

 Easy steps to generate QR code for Survey Invitation Link 1) Create your Survey using Salesforce Platform Survey. 2) Once done activate it....