You can retrieve Images from the SharePoint Folder and use it in the Document Generation as per your requirement.
To do this, first you need to integrate your Salesforce Org with SharePoint using Collaboration Butler. For more information on how to set up and configure Collaboration Butler is found here.
Once the Collaboration Butler is Setup, you can access the SharePoint folders and their contents in Salesforce Org.
To retrieve SharePoint Images from that folder and make use of them to display as pictures in your document, refer to the below example.
Example: #
Let’s say you have all Opportunities in the SharePoint folder with their name as folder name. Each folder has image files related to the opportunity.
To retrieve the files based on the opportunity and display as pictures in the document, you have to follow below steps.
- Create a KEYVALUE Data Source to set Image names and their Download URLs data to it.
- Create Doc Config with this document template.
- Add KEYVALUE Data Source to the Doc Config. Add fields “FileName” and “FileURL” to this KEYVALUE Data Source.
- Click on New Child for this KEYVALUE Data Source and Add Dynamic Data Source as follows.
- Create Config Types as follows.
- Save the Doc Config to server.
- Create Fields Library URL, Path, KEYVALUE DataSource to send the SharePoint Site URL, path and key value data source dynamically to the apex class you are going to generate in next steps.
- Go to Actionable Object and Create a Page Layout copying the Existing Page Layout “Run Class”.
- Create a separate section for the above fields
- Create Record type with Master Record type as Run Class and map the above page layout to this record type.
- Go to Doc Config record and create an Actionable record with above RecordType as follows
Library URL should be your site URL
Example: https://……sharepoint.com/sites/COLLABORATIONTEST/Shared Documents
Path should be folder directory where your opportunities are present and it should start with ‘/’
Example: /Customers/Opportunities
- Crate below apex class to retrieve images and their download URLs from SharePoint folder.
global class Actionable_getFilesFromSharePointFolder implements cadmus_core.AbstractBeforeActionable { global void execute(cadmus_core__Actionable__c actionable, Id docConfig, Id objectId, Map<String, Object> inputMap, cadmus_core.ConvertController.ConvertDataModel cdm) { WorkOrder wo = [Select Id,WorkOrderNumber from WorkOrder Where Id=:objectId]; List<String> filenameslist = new List<String>(); cadmus_una.CollabMSGraphClient.GetDriveResponse gdr = cadmus_una.CollabMSGraphClient.getSiteDrive(UserInfo.getUserId(),actionable.library_Url__c); cadmus_una.CollabMSGraphClient.GetDriveContentResponse response = cadmus_una.CollabMSGraphClient.getDriveItemsByPath(UserInfo.getUserId(), gdr.data.id, actionable.path__c+'/'+wo.WorkOrderNumber); for (cadmus_una.MsGraphContentResponse.Value value : response.data.value) { filenameslist.add(value.name); } List<Map<String, String>> myMapsList = new List<Map<String, String>>(); system.debug('filenameslist'+filenameslist); for(String str : filenameslist){ if(str.toLowerCase().contains('.jpg') || str.toLowerCase().contains('.jpeg') || str.toLowerCase().contains('.png')){ Map<String,String> fileMap = new Map<String,String>(); cadmus_una.CollabMSGraphClient.GetDriveResponse di=cadmus_una.CollabMSGraphClient.getDriveItemByPath(UserInfo.getUserId(), gdr.data.id, '/'+actionable.path__c+'/'+wo.WorkOrderNumber+'/'+str); if(di.isError()) { System.debug(LoggingLevel.ERROR, di.error); } else { fileMap.put('FileName',str); fileMap.put('FileURL',di.data.downloadUrl); } myMapsList.add(fileMap); } } system.debug('myMapsList'+myMapsList); cadmus_core__Data_Source__c dss = new cadmus_core__Data_Source__c(); dss = [SELECT Id, Name, cadmus_core__CustomerDataSourceId__c,cadmus_core__Image_Name__c From cadmus_core__Data_Source__c where Id=:actionable.KEYVALUE_Data_Source__c]; inputMap.put(dss.Id, myMapsList); } }
- Go to Opportunity, edit the page and drag the PDF Convert Component. Paste the Doc Config Id in DocConfigs To retrieve field and Save the page.
- Generate the Document and you can see all the images in the table.