3.2 Writing Assistant

This article provides a step-by-step guide to configuring Writing Assistance inside Salesforce as an iFrame. You will learn how to create an Apex class and a Visualforce page to embed the Writing Assistance functionality within Salesforce.

IN THIS ARTICLE
Creating the writing Assistant iFrame
Creating a New Apex Class: WritingAssistancePageController
Additional Optional Parameters
Creating a New Visualforce Page: WritingAssistancePage
Testing and activation

Creating the Writing Assistance iFrame


The Writing Assistance tool allows users to access AI-driven writing support within Salesforce. To integrate this functionality, we need to configure an Apex class and a Visualforce page.


Creating a New Apex Class: WritingAssistancePageController


Follow these steps to create the Apex class required for Writing Assistance:

Step 1: Navigate to Apex Classes

  • Go to Setup.
  • Search for Apex Classes in the Quick Find box.
  • Click New With Class Name WritingAssistencePageController.

Step 2: Copy and Paste the Following Code

public class WritingAssistancePageController {
    public String externalUrl { get; private set; }

    public WritingAssistancePageController(ApexPages.StandardController controller) {
        String publicationId = ApexPages.currentPage().getParameters().get('atspubid');
        String vacancyId = ApexPages.currentPage().getParameters().get('vacancyid');
        String brand = ApexPages.currentPage().getParameters().get('selectedbrand');
        String userId = UserInfo.getUserId();
        
        if (String.isBlank(publicationId)) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Publication ID is required.'));
            return;
        }
        if (String.isBlank(vacancyId)) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Vacancy ID is required.'));
            return;
        }

        Jobrock__Company_Name__c customSetting = Jobrock__Company_Name__c.getInstance();
        String companyCode = customSetting != null ? customSetting.Jobrock__Company_Code__c : null;

        if (String.isBlank(companyCode)) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Company Code is not configured.'));
            return;
        }

        externalUrl = JobrockUrl() + vacancyId +
                      '/writingAssistance?mcode=viewPub&atspubid=' + publicationId +
                      '&companycode=' + companyCode +
                      '&externaluserid=' + userId + '&logintype=SF';

        Jobrock__Jobrock_Configuration__c configureObj = Jobrock__Jobrock_Configuration__c.getValues('EnableMultibrand');
        if (configureObj != null && configureObj.Jobrock__Is_Configured__c == true) {
            externalUrl = externalUrl + '&isMultibrand=1';
        }

        if (!String.isBlank(brand)) {
            externalUrl = externalUrl + '&selectedBrand=' + brand;
        }
    }

    public string JobrockUrl() {
        Jobrock__Jobrock_Configuration__c configureObj = Jobrock__Jobrock_Configuration__c.getValues('Production');
        Boolean isConfigured = configureObj != null ? configureObj.Jobrock__Is_Configured__c : false;
        return isConfigured ? 'https://hub.jobrock.com/dashboard/' : 'https://hub-test.jobrock.com/dashboard/';
    }
}

Step 3: Save the Apex Class

Click Save to store the new Apex class.



Additional Optional Parameters

Below are additional optional parameters that can be configured if required:


Param Possible Values Remarks
activeView WA / QA / PR

This parameter will decide the default active tab in the vacancy assistance flow


WA: Writing assistance tab

QA: Question & Answer tab

PR: Persona tab

q_generate true/false

You can control if you would like to restrict regeneration of Q&A. To disable the “regenerate” button, value should be “false”


If parameter is not passed then it will be default “true”

p_generate true/false

You can control if you would like to restrict regeneration of Persona. To disable the “regenerate” button, value should be “false”


If parameter is not passed then it will be default “true”

fieldsToEmpty Comma separated list of jobrock publication description fields. E.g title, jobDescription It will allow you to forcefully emptied the specified fields every time when you open writing assistance. You will have to generate them from AI every time.

Creating a New Visualforce Page: WritingAssistancePage


Step 1: Navigate to Visualforce Pages

  • Go to Setup.
  • Search for Visualforce Pages in the Quick Find box.
  • Click New And Visualforce Page Name is WritingAssistencePage

Step 2: Copy and Paste the Following Code

<apex:page standardController="Job_description__c" extensions="WritingAssistancePageController" showHeader="false">
    <iframe src="{!externalUrl}" width="100%" height="600px" frameborder="0"></iframe>
</apex:page>

Step 3: Save the Visualforce Page

  • Click Save to store the new Visualforce page.

Testing and Activation


Step 1: Verify the Apex Class

  • Ensure that the Apex class is saved without errors.

Step 2: Preview the Visualforce Page

  • Open the Visualforce page and confirm that the Writing Assistance iFrame loads correctly.

Step 3: Activate the Visualforce Page

  • Deploy the Visualforce page to the relevant Salesforce environment.

This configuration enables seamless integration of Writing Assistance within Salesforce, enhancing the writing experience for users.