Loading
Omnistudio Document Generation
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Retrieve Images During Server-Side Omnistudio Document Generation With Sample Custom Class

          Retrieve Images During Server-Side Omnistudio Document Generation With Sample Custom Class

          To retrieve images during server-side document generation, create an Apex class in your org that exposes the getImageContentBlob() method. During Server Side document generation, Salesforce calls this method to retrieve Base64-encoded image data. In your document generation request, pass image token data for each image token. Set the IMG_ token’s src value to a lookup key that matches a key in the imageContentMap returned by getImageContentBlob(). Salesforce uses this mapping to resolve and insert the image during document generation.

          Required Editions

          Available in: Lightning Experience
          Available in: Professional, Enterprise, Unlimited, and Developer Editions

          Token data example

          For images retrieved via Apex, use this token format:

          "IMG_imageToken": {
            "width": 120,
            "height": 160,
            "src": "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg"
          }
          

          In the getImageContentBlob() method, the Apex class converts the image to Base64 format and adds it to the imageContentMap using the same src value as the key:

          imageContentMap.put(
            'https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg',
            base64ImageContent
          );
          

          When the src value in the image token matches the key in imageContentMap, Salesforce successfully resolves the image and includes it in the generated document.

          How the mapping works

          In the getImageContentBlob() method, add an entry to imageContentMap where the key matches the src value from the token data and the value contains the Base64-encoded image content.

          When the src value in the image token matches a key in imageContentMap, Salesforce resolves the image and includes it in the generated document. You can use a record ID or any unique string as the key, as long as it maps to the corresponding Base64-encoded image content.

          Apex class example

          Here is an example of a custom Apex class that retrieves images during server-side document generation. The class implements invokeMethod from the OpenInterface interface and exposes the getImageContentBlob() method, which Salesforce calls at runtime to retrieve Base64-encoded image data. The src value passed in the image token acts as a lookup key. This value must match a key defined in the imageContentMap returned by the getImageContentBlob() method. The class implements invokeMethod via the OpenInterface class. For more information about this class and its methods, see OpenInterface Interface in the Developer Guide.

          global class ImageBlobGenerator implements ind_docgen_api.OpenInterface {
              public Boolean invokeMethod(String methodName, Map<String, Object> request, Map<String, Object> outMap) {
                  Boolean success = false;
                  if (methodName == 'getImageContentBlob') {
                      success = getImageContentBlob(request, outMap);
                  }
                  return true;
              }
          
          
              global Boolean getImageContentBlob(Map <String, Object> inputMap, Map <String, Object> outMap) {
                  Map<String, String> imageContentMap = new Map<String, String>();
                  imageContentMap.put('https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg', 'aHR0cHM6Ly9jZG4ucGl4YWJheS5jb20vcGhvdG8vMjAxNS8wNC8yMy8yMi8wMC90cmVlLTczNjg4NV8xMjgwLmpwZw==' );
                  outMap.put('imageContentMap', imageContentMap);
                  outMap.put('isSuccess', true);
                  return true;
              }
          }
          
           
          Loading
          Salesforce Help | Article