WX Translations | Create and deploy Apex classes

Role: HR Administrator

Note Creating and deploying Apex classes is a one time activity for your org. When you have completed these steps as part of initial setup, you do not need to repeat them.

Create Apex classes

These steps are required if you are using translations for WX Process names. If you are only using translations for WX Service names, go straight to WX Translations | Create and deploy Apex classes.

Creating and deploying Apex classes is an advanced procedure that should be carried out by a system administrator. For additional guidance, see the Salesforce help article: Salesforce: Manage Apex Classes.

The following steps must be performed in a Sandbox org connected to your production org. Two Apex classes will be created, one for identifying the static resource and holding the translation keys, and one to test the class.

Create the first class

  1. Go to Setup, and in Quick Find enter Apex Classes. Open the Custom Code > Apex Classes page.

  2. Select New.

    Note

    You need to create two Apex Classes:

    • One to identify the Static Resource holding the translation keys
    • One test class

    You can create new Apex Classes in Sandbox and Development orgs, not in Production orgs. To insert the Apex Classes in a Production org, create them in the associated Sandbox and then deploy to the Production org. Create the Apex Classes and then follow the instructions given below, following creation of the Apex Classes.

    Sage People displays the Apex Class Edit page.

  3. On the Apex Class tab, copy and paste this text:

    Copy
    global class ApexClassName implements fHCM2.WXPackage {
    global List<String> getTranslationKeys() {
    String staticResourceName = 'Custom_Label_Translation_Keys';
    List<String> labelNames = new List<String>();
    try {
    StaticResource sr = [SELECT body, name, NamespacePrefix FROM StaticResource WHERE Name =: staticResourceName LIMIT 1];
    fHCM2.TranslationHelper.addLabels(labelNames, sr);
    } catch (Exception ex) {System.debug('Failed to get translations for '+ staticResourceName +': ' + ex);
    }
    return labelNames;
    }
    }

    Replace these items in the text you copied above:

    • Replace ApexClassName with a meaningful name for the Apex class of up to 40 characters, with no spaces.

      For example: MyCompanyName_WXPackage

    • Replace Custom_Label_Translation_Keys with the name of the static resource file you created.

  4. Select Save.

    Sage People displays the Apex Class Detail page for the new Apex Class.

  5. Next, check that the class is using the same version of the Salesforce.com API as your production org:

    Navigate to the Version Setting tab and review the version number for the Salesforce.com API.

    Screenshot: check the API version for the class

  6. Check that the version number matches the API version in your production org. To check:

    1. In the Production org, navigate to Setup > Integrations > API

    2. Under Enterprise WSDL, select Generate Enterprise WSDL

      Screenshot: generate a WSDL file

    3. On the next page, select Generate.

    4. An XML file is displayed in the browser. In the first line of the file, there will be an API Version number. Ensure the version matches the version of the Apex class in the Sandbox org. If they are different, navigate back to your Sandbox and from the picklist on Version Settings, select the appropriate version to match the production org. If the sandbox does not have the version that production is on available, a refresh of the sandbox will be needed.

Create a test class

  1. Repeat the process to create a test class, entering the following code on the Apex Class tab:

    Copy
    @isTest
    public class ApexTestClass {
    public static testmethod void testTranslations() {
    ApexClassName p = new ApexClassName();
    System.assert(p.getTranslationKeys().size() > 0);
    }
    }

    Replace these items in the text you copied above:

    • Replace ApexTestClass with a meaningful name for the test class of up to 40 characters, with no spaces.

      For example: MyCompanyName_WXPackageTest

    • Replace ApexClassName with the name of the Apex Class you used for the main Apex Class you created in the previous step.

  2. Select Save.

    Sage People displays the Apex Class Detail page for the new Apex Test Class.

Tip You can complete the rest of the translation procedure to test that translations are working in the Sandbox org before deploying the class to your production org.

Deploy Apex classes to your production org

The production org must have the Sandbox defined as a connected org to enable it to receive the Change Set containing the Apex Classes. To check:

  1. Navigate to Environments>Deploy>Deployment Settings. If you see a splash screen, select Continue.

    If the Sandbox is allowed to upload changes to your production org, you will see an entry in the Upload Authorisation Direction column indicating whether changes are allowed from the Sandbox org:

    Screenshot: upload authorisation direction

  2. If upload changes are not authorised, select Edit next to the Sandbox.

  3. Select the Allow Inbound Changes checkbox.

    Screenshot: allow inbound changes

  4. Select Save.

When you are ready to deploy the Apex Classes into your production org, in the associated Sandbox org:

  1. Go to Outbound Change Sets:

    in Salesforce Lightning Experience, go to Setup > Platform Tools > Environments > Change Sets > Outbound Change Sets

    in Salesforce Classic interface, go to Setup > App Setup > Deploy > Outbound Change Sets

  2. If a splash page is displayed, select Continue.
  3. On the Outbound Change Sets page, in the Change Sets list, select New.

    Sage People displays the New Change Set page.

  4. Enter a Name for the change set, for example WXPackage Apex Class, and an optional Description.
  5. Select Save.

    Sage People displays the Change Set page for your new Change Set.

  6. In the Change Set Components section, select Add.
  7. In Component Type select the picklist and choose Apex Class
  8. In the displayed list select the ApexClassName and the ApexTestClass you created earlier.
  9. Select Add To Change Set.

    Sage People adds the Apex Classes to the Change Set Components section of the Change Set page.

  10. In the Change Set Detail section, select Upload.
  11. Select the target Production org and select Upload.
  12. When upload completes, log in to the Production org.
  13. Go to Inbound Change Sets: 

    in Salesforce Lightning Experience, go to Setup > Platform Tools > Environments > Change Sets > Inbound Change Sets

    in Salesforce Classic interface, go to Setup > App Setup > Deploy > Inbound Change Sets

  14. If a splash page is displayed, select Continue.
  15. In the change sets awaiting deployment list, select the Change Set you created earlier.
  16. Select Deploy.

Register the Apex classes

Perform the following steps in the Production org to register the Apex Classes:

  1. Open the Developer Console and go to Debug > Open Execute Anonymous Window.

  2. In an empty window, enter:

    Copy
    fHCM2.WXPackages.Register('ApexClassName', null, true);
    fHCM2.WXPackages.SaveRegistered();

    Where:

    • ApexClassName is as entered when creating the Apex Class.
    • null is:

      • The namespace of your org. Production and Sandbox orgs do not have a namespace; enter null with no enclosing quote marks.

      • If you are working with a Developer org, enter the org namespace enclosed in quote marks, for example 'org_namespace'.

    • true is:

      • true to overwrite existing settings.

      • false to add these settings to an existing setup.

  3. Select Execute, and close the Developer Console.

Next: WX Translations | Apply your translations