Generic Compliance Verification UI with Visualforce

Visualforce is an older user interface technology that has now been superseded by Lightning Components. The following information is provided if you are working with a pre-existing code base that is still using Visualforce.

A generic Visualforce Controller, ComplianceController, has been created with a verify action method that calls the service. Note that at no time have we yet referred to a specific Custom Object or Domain class, ensuring that this controller and service are generic and able to handle objects of different types. The following code shows how the generic ComplianceService.verify method is being called from the ComplianceController.verify method:

public PageReference verify() { 
  try { 
    // Pass the record to the compliance service 
    ComplianceService.verify( 
      new Set<Id> { standardController.getId() }); 
    // Passed! 
    ApexPages.addMessage( 
      new ApexPages.Message( 
         ApexPages.Severity.Info, 'Compliance passed')); 
  } 
  catch (Exception e) { 
    // Report message as normal via apex:pageMessages 
    ApexPages.addMessages(e); 
    // Display additional compliance failure messages? 
    if(e instanceofComplianceService.ComplianceException) 
    { 
      ComplianceService.ComplianceExceptionce 
        (ComplianceService.ComplianceException) e; 
      for(ComplianceService.VerifyResultverifyResult :
ce.failures) {
ApexPages.addMessage(new ApexPages.Message(
ApexPages.Severity.Error,
String.format('{0} ({1})',
new List<String> {
verifyResult.failureReason,
verifyResult.complianceCode }))); } } } return null; }

A Visualforce page for each object is then created to bind this generic controller to Custom Buttons on the Driver and Car detail pages. This is the only specific reference made to objects that implement the ComplianceService.ICompliant interface and is only needed in order to create the Custom Buttons in Salesforce Classic. The following page for the Driver object defines a button that uses the generic ComplianceController.verify method:

<apex:pagestandardController="Driver__c" 
   extensions="ComplianceController" action="{!verify}"> 
  <apex:pageMessages/> 
  <apex:form> 
    <apex:commandButton value="Cancel" action="{!cancel}"/> 
  </apex:form> 
</apex:page> 

Now that we have seen how the compliance framework can be referenced throughout the rest of the application code, in the next section, we will summarize this implementation and understand the benefits this approach has had on how the user experience is delivered.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.40.32