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
Gabriel ArgenalGabriel Argenal 

SAML JitHandler needs to dynamically pass custom error message to VF error page?

In the SAML configurations, we have a simple custom VF Page that displays a static error message. There is now a need for the JIT handler to dynamically pass a custom error message to the VF Page in order to display one of a few different error message based on the reason for the error. Does anyone know if this is possible and have an example of how this can be completed?
Arun Kumar 1141Arun Kumar 1141

Yes, it is possible to pass a custom error message from the JIT (Just-In-Time) handler to a Visualforce (VF) page in order to display different error messages based on the reason for the error. Here's an example of how you can achieve this:

VF - Page
<apex:page>
  <apex:outputText value="Welcome to the VF Page!" />
  <br/>
  <apex:outputText value="Error Message: " />
  <apex:outputText value="Default error message" id="errorMessage"/>
</apex:page>


Handler

// Construct the custom error message based on the reason
String errorMessage = '';
if (reason == 'reason1') {
  errorMessage = 'Error message for reason 1.';
} else if (reason == 'reason2') {
  errorMessage = 'Error message for reason 2.';
} else {
  errorMessage = 'Default error message.';
}

// Redirect to the VF page with the custom error message
String redirectUrl = '/apex/YourVFPageName?id=yourRecordId&errorMessage=' + EncodingUtil.urlEncode(errorMessage, 'UTF-8');
System.PageReference pageRef = new System.PageReference(redirectUrl);
pageRef.setRedirect(true);
return pageRef;




public class YourVFPageController {
  public String errorMessage { get; set; }

  public YourVFPageController() {
    errorMessage = ApexPages.currentPage().getParameters().get('errorMessage');
  }
}


<apex:page controller="YourVFPageController">
  <apex:outputText value="Welcome to the VF Page!" />
  <br/>
  <apex:outputText value="Error Message: " />
  <apex:outputText value="{!errorMessage}" id="errorMessage"/>
</apex:page>