Append images to a Rich Text field using a Batch (Developer-Oriented)
The SharinPixToRichTextAutomation class includes the method appendToRichText, which can be used to populate images within records in batch.
The variables available in the Params inner class are as follows:
Variable API Name |
Description |
Is Field Value Mandatory? |
---|---|---|
recordId |
The record ID. | Yes |
richTextFieldApiName |
The API name of target Rich Text field. |
Yes |
imageUrlFieldApiName |
The API name of the image URL field. Some available values are: sharinpix__ImageURLFull__c, sharinpix__ImageURLOriginal__c, sharinpix__ImageURLThumbnail__c, sharinpix__ImageURLMini__c. You can also create a custom image URL field on the SharinPix Image object. |
Yes |
imageIds | The list of public IDs of images to be included in the Rich Text field. If no value is provided for this field, all images available on the record's album will be included in the Rich Text field. |
No |
replaceContent |
When value is set to true, the existing content of target Rich Text Area will be replaced. |
No |
imageCaptionText | The API name of the field containing the text to be displayed alongside the image. |
No |
columns |
The number of columns to be included in the Rich Text field. The default column value is 1 and the accepted value ranges from 1 to 10 columns. |
No |
The example below demonstrates how the appendToRichText method can be used in a Batch to generate images on multiple Account records:
public class myBatch implements Database.Batchable<sObject>, Database.Stateful {
public list<Account> acclist;
public myBatch(list<Account> acclist) {
this.acclist = acclist;
}
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('select id from Account where Id IN :acclist');
}
public void execute(Database.BatchableContext bc, List<Account> scope){
sharinpix.SharinPixToRichTextAutomation.Params params = new sharinpix.SharinPixToRichTextAutomation.Params();
List<sharinpix.SharinPixToRichTextAutomation.Params> paramsList = new List<sharinpix.SharinPixToRichTextAutomation.Params>();
for(Account acc : scope) {
params.recordId = acc.Id;
params.imageUrlFieldApiName = 'sharinpix__ImageURLThumbnail__c';
params.columns = 4;
params.replaceContent = true;
params.richTextFieldApiName = 'MyRichTextField__c';
paramsList.add(params);
}
sharinpix.SharinPixToRichTextAutomation.appendToRichText(paramsList);
}
public void finish(Database.BatchableContext bc){}
}
When running the batch, the number of records to be passed in the Database.executeBatch method should be limited to one: Database.executeBatch(new myBatch(acclist), 1);
0 Comments
Add your comment