Utils methods

Utils are available for you to avoid direct access to our rest API and an integrated usage directly from the SharinPix package in Apex from Salesforce.

Methods

  • renameAlbum

  • duplicateAlbum

  • getAlbumImages

  • getImageDetails

  • duplicateImages

  • getImageUrl

  • getImageEndpoint

  • croppedImageUrl

  • getImageExternalUrls

  • getOrgTags

  • getAlbumTagImages

  • getTagsOnImage

  • getTagNamesOnImage

  • addTag

  • removeTags

  • clearTags

  • uploadAttachment

  • uploadContentDocument

  • uploadFromUrl

  • uploadWebshot

  • generateMobileAppUrl

  • splitToken

  • getAlbumImageIds

  • deleteImage

  • deleteImages

  • updateSessionIdValidity

  • createContentDocumentFromUrl

Utils Method Example

renameAlbum

_global BooleanrenameAlbum(String oldAlbumId , String newAlbumId) _

  • Renames an album.

renameAlbum

_global BooleanrenameAlbum(String oldAlbumId , String newAlbumId , Boolean mergeAlbum) _

  • Renames an album. The**mergeAlbum **parameter is used to specify whether to merge the old and new albums or not.

Image below shows the albums before using the renameAlbum method.

After using the method renameAlbum with mergeAlbum parameter 'true', all the images from the old Album have been merged in the new Album as shown below.

duplicateAlbum

duplicateAlbum with no Tags or Tags equals to false

_global StringduplicateAlbum(String sourceAlbumId , String destinationAlbumId) _

  • Copies all images from a source album to a destination album.

The code below shows the code without tags.

Image below shows the source record where the album an image with the tag "object".

The image below shows the destination record where the image from the source record has been populated without the tags because in the code snippet we have not mentioned if "Tags" is true or false.

DuplicateAlbum with Tags True

_global StringduplicateAlbum(String sourceAlbumId , String destinationAlbumId , Boolean includeTags) _

  • Copies all images from a source album to a destination album. This method also allows the duplication of tags along with the images.

The image below shows the code where tags is true.

Image below shows the source record where the album an image with the tag "object".

The image below shows the destination record where the image from the source record has been populated and has been assign the tag "object" when the code snippet was executed.

duplicateAlbum with Einstein Boxes (DEPRECATED)

This method has been deprecated and should not be included in new implementations as Salesforce retired Einstein Vision on July 31, 2023.

global String duplicateAlbum(String sourceAlbumId, String destinationAlbumId, Map <String,Object> params)

  • Copies all images from a source album to a destination album if einstein_boxes equals to true. This method also allows the duplication of labels along with the images.

For destination records, the tags will only appear if we mentioned **true **in the code snippet.

getAlbumImages

_global List getAlbumImages(String albumId) _Gets all images from an album.Below code shows how to get the details from an image (e.g: brightness, color, contrast, created_at,...) sharinpix.Utils u = new sharinpix.Utils(); list<object> lstobj = u.getAlbumImages('0018a00001rL2sXAAS');getImageDetails_global Map <String, Object> getImageDetails(String imageId) _Gets image details. sharinpix.Utils u = new sharinpix.Utils(); Map<String, object> response = u.getImageDetails('66d6d11a-6399-4713-be28-ebcbdc148c3b'); System.debug(response);duplicateImageToAlbumglobal stringduplicateImageToAlbum(string imageId , string albumId , map<string, object> options)Duplicates an image to a specified album. The **options parameter can be used to enable tag and image sync while duplicating the image._ ** An example on how to call this method has been given at the end of this article._ sharinpix.Utils u = new sharinpix.Utils(); string response = u.duplicateImageToAlbum('64fae218-12b8-47ee-ad5a-e0d733e5eade','0018F00000SyyvJQAR',new map<string, object>{'tags' => true, 'sync' => true}); System.debug(response);duplicateImagesduplicateImages with no Tags or Tags equals to falseglobal List duplicateImages(List imageIds , String destinationAlbumId)Duplicates one or more images to another album. sharinpix.Utils u = new sharinpix.Utils(); List<object> response = u.duplicateImages(new list<String>{'66d6d11a-6399-4713-be28-ebcbdc148c3b'}, '0018F00000SyyvJQAR'); System.debug(response);duplicateImages with Tags Trueglobal List duplicateImages(List imageIds , String destinationAlbumId, Map<String, Object> options)Duplicates one or more images to another album. This method also allows the duplication of tags along with the images. sharinpix.Utils u = new sharinpix.Utils(); List<object> response = u.duplicateImages(new list<String>{'66d6d11a-6399-4713-be28-ebcbdc148c3b'}, '0018F00000SyyvJQAR', new Map<String, Object> {'tags' => true}); System.debug(response);Tip:The SharinPix package also include the **Image **class which includes useful methods for image management such as a method to move images. For more information about the Image class, please refer to the article below:Image methodsgetImageUrl_global StringgetImageUrl(String imageId , Map<String, Object> sharinpix , List transformations) _Gets the URL of a transformed image. sharinpix.Utils u = new sharinpix.Utils(); String imgURL = u.getImageUrl('66d6d11a-6399-4713-be28-ebcbdc148c3b', new Map<String, object>{'download' => false},new List<Object>{new map<String,object>{'crop' => 'fit', 'width' => 500}}); System.debug(imgURL);_Get the original url of an image (This url is a direct expiring url to the storage) &#xNAN;_ sharinpix.Utils u = new sharinpix.Utils(); String imgURL = u.getImageUrl('2ae9c19c-3ad3-4844-bacc-71c2cd3313a8', new Map<String, object>{'original' => true},new List<Object>{}); System.debug(imgURL);getImageEndpointglobal String getImageEndpoint (String imageId , Map<String, Object> sharinpix , List transformations)Get endpoint of transformed image sharinpix.Utils u = new sharinpix.Utils(); String imgURL = u.getImageEndpoint('2ae9c19c-3ad3-4844-bacc-71c2cd3313a8', new Map<String, object>{'original' => true},new List<Object>{}); System.debug(imgURL);croppedImageUrl_global StringcroppedImageUrl(String imageId , String cropStyle , Integer width , Integer height) _Crops or resizes images. sharinpix.Utils u = new sharinpix.Utils(); string getUrl = u.croppedImageUrl('bab2179a-9e8d-4ad9-a42c-d7bc45eccdf5','fill',100,100); System.debug(getUrl);getImageExternalUrl_global Map <String, Object> getImageExternalUrl(Map<String, Object> imageTransformation) _Applies transformations on an image and get an external URL. sharinpix.Utils u = new sharinpix.Utils(); Map<String,Object> image = new Map<String,Object>{'image_id' => '66d6d11a-6399-4713-be28-ebcbdc148c3b','crop' => 'fit','height' => 100,'width' => 100}; Map<String, Object> imageObj = u.getImageExternalUrl(image); System.debug(imageObj);getImageExternalUrls_global List getImageExternalUrls(List<Map<String, Object>> imageTransformations) _Applies transformations on images and get external images URLs. sharinpix.Utils u = new sharinpix.Utils(); list<Map<String,Object>> getImgExtUrl = new list<Map<String,Object>>{ new Map<String,Object>{ 'image_id' => '66d6d11a-6399-4713-be28-ebcbdc148c3b', 'transformations' => new Map<string, object> { 'crop' => 'fit', 'height' => 100, 'width' => 100 } } }; List<object> lstObj = u.getImageExternalUrls(getImgExtUrl); Map<String, Object> fieldsToValue = (Map<String, Object>) JSON.deserializeUntyped(JSON.serialize(lstObj[0])); System.debug(fieldsToValue.get('url'));getOrgTags_global List getOrgTags() _Retrieves all tags present in your Organization. sharinpix.Utils u = new sharinpix.Utils(); list <object> lstobj = u.getOrgTags(); System.debug(lstobj);getAlbumTagImages_global List getAlbumTagImages(String albumId) _Retrieves the list of images having tags from an album. sharinpix.Utils u = new sharinpix.Utils(); list <Object> lstObj =u.getAlbumTagImages('0018a00001rL2scAAC'); System.debug(lstObj);getAlbumTagImages_global List getAlbumTagImages(String albumId , String tagName) _Retrieves all tagged images having a specific tag name from an album. sharinpix.Utils u = new sharinpix.Utils(); list <Object> lstObj = u.getAlbumTagImages('0018a00001rL2scAAC','Plan'); System.debug(lstObj);getTagsOnImage_global List getTagsOnImage(String imageId) _Retrieves all tags applied to an image. sharinpix.Utils u = new sharinpix.Utils(); list <object> lstobj = u.getTagsOnImage('bab2179a-9e8d-4ad9-a42c-d7bc45eccdf5'); System.debug(lstobj);getTagNamesOnImage_global List getTagNamesOnImage(String imageId) _Retrieves all tag names available on an image. sharinpix.Utils u = new sharinpix.Utils(); list <String> lstobj = u.getTagNamesOnImage('bab2179a-9e8d-4ad9-a42c-d7bc45eccdf5'); System.debug(lstobj);addTag_global ObjectaddTag(String imageId, String tagName) _Adds a tag on an image. sharinpix.Utils u = new sharinpix.Utils(); u.addTag('bab2179a-9e8d-4ad9-a42c-d7bc45eccdf5','testInsertTags');removeTags_global Boolean _(String imageId , String[] tags)Removes tags from a tagged image. sharinpix.Utils u = new sharinpix.Utils(); Boolean tagRemoved = false; tagRemoved = u.removeTags('66d6d11a-6399-4713-be28-ebcbdc148c3b',new list<String>{'Plan'});clearTags_global BooleanclearTags(String imageId) _Clears all tags applied to an image. sharinpix.Utils u = new sharinpix.Utils(); u.clearTags('bab2179a-9e8d-4ad9-a42c-d7bc45eccdf5');uploadAttachment_global ObjectuploadAttachment(Id attachmentId , String albumId) _Uploads Salesforce attachments to SharinPix albums. sharinpix.Utils u = new sharinpix.Utils(); object result =u.uploadAttachment('00P8a00000HCfOWAA1','0018a00001rL2scAAC'); System.debug(result);uploadAttachment_global ObjectuploadAttachment(Id attachmentId , String albumId , Map<String, Object> userMetadatas) _Uploads Salesforce attachments to SharinPix albums. sharinpix.Utils u = new sharinpix.Utils(); object result =u.uploadAttachment('00P8a00000HCfOWAA1','0018a00001rL2scAAC',null); System.debug(result);uploadAttachmentglobal Object uploadAttachment(Id attachmentId , String albumId , Map<String, Object> userMetadatas , List tags)Uploads Attachments to SharinPix albums with tags. Using this method, you can also provide a list of tags to be applied to every image. sharinpix.Utils u = new sharinpix.Utils(); object result =u.uploadAttachment('0698a00000HCfOWAA1','0018a00001rL2scAAC',null,new List<String>{ 'tagA', 'tagB' }); System.debug(result);uploadContentDocument_global ObjectuploadContentDocument(Id contentDocumentId , String albumId) _Uploads Salesforce ContentDocuments to SharinPix albums. sharinpix.Utils u = new sharinpix.Utils(); object result =u.uploadContentDocument('0698a00000HCfOWAA1','0018a00001rL2scAAC'); System.debug(result);uploadContentDocument_global ObjectuploadContentDocument(Id contentDocumentId , String albumId , Map<String, Object> userMetadatas) _Uploads Salesforce ContentDocuments to SharinPix albums. sharinpix.Utils u = new sharinpix.Utils(); object result =u.uploadContentDocument('0698a00000HCfOWAA1','0018a00001rL2scAAC',null); System.debug(result);uploadContentDocumentglobal ObjectuploadContentDocument(Id contentDocumentId , String albumId , Map<String, Object> userMetadatas , List tags)Uploads Salesforce ContentDocuments to SharinPix albums. Using this method, you can also provide a title and description within the userMetadatas parameter **** and **** a list of tags within the tags parameter to be applied to every image. sharinpix.Utils u = new sharinpix.Utils(); object result =u.uploadContentDocument('0698a00000HCfOWAA1', '0018a00001rL2scAAC', new Map<String, Object> { 'sp_title' => 'sample title', 'sp_description' => 'sample description' }, new List<String> { 'tagA', 'tagB' }); System.debug(result);uploadFromUrlglobal ObjectuploadFromUrl(String imageUrl , String albumId , String filename)Uploads an image to SharinPix using an URL. sharinpix.Utils u = new sharinpix.Utils(); string url ='https://picsum.photos/1200/1000'; object result = u.uploadFromUrl(url,'0018a00001rL2scAAC','image.jpg'); System.debug(result);uploadFromUrlglobal ObjectuploadFromUrl(String imageUrl , String albumId , String filename , map<string, object> metadatas)Uploads an image to SharinPix using an URL. Using this method, you can also provide specific metadata as title, description and contentDocumentId within the userMetadatas parameter to be applied to the image. sharinpix.Utils u = new sharinpix.Utils(); string url ='https://picsum.photos/1200/1000'; object result = u.uploadFromUrl(url,'0018a00001rL2scAAC','test1', new Map<string, string> { 'contentDocumentId' => '0698a00000HCfOWAA1', 'sp_title' => 'sample title', 'sp_description' => 'sample description' }); System.debug(result);uploadWebshot_global ObjectuploadWebshot(String url , String albumId) _Captures screenshot from website URL and uploads to SharinPix. sharinpix.Utils u = new sharinpix.Utils(); string url ='https://www.google.com'; object getUploadWebShot = u.uploadWebshot(url,'0018a00001rL2scAAC'); System.debug(getUploadWebShot);uploadWebshot_global ObjectuploadWebshot(String url , String albumId , Map<string, object> options) _Captures screenshot from website URL and uploads to SharinPix. Using this method you can also provide a list of tags to be applied on every image. For e.g : &#xNAN;sharinpix.Utils.uploadWebshot('https:/test/maps/test', '00324000004GUxhAAG', new Map<string, object>{ 'tags' => new List {'mapTag'}}); sharinpix.Utils u = new sharinpix.Utils(); object response = u.uploadWebshot('https://www.google.com/','5008a00001uwxsNAAQ',new Map<String,object> {'tags'=> 'test'}); System.debug(response);generateMobileAppUrl_global StringgenerateMobileAppUrl(String albumId , Map<String, Object> options) _Generates the SharinPix URL used to launch the mobile application. sharinpix.Utils u = new sharinpix.Utils(); Map <String, object> opt = new Map<String,Object>{ 'name'=> 'TestName', 'linkExpiration' => 500 }; string appurl = u.generateMobileAppUrl('61a65f12-eccd-4b42-bd7d-2de4a8699b80',opt); System.debug(appurl);generateMobileAppUrl_global StringgenerateMobileAppUrl(String albumId , String name , Map<String, Object> options , Integer linkExpiration) _Generates the SharinPix URL used to launch the mobile application. sharinpix.Utils u = new sharinpix.Utils(); Map<String, object> options = new map<String,object>{ 'name' => 'TestName', 'linkExpiration' => 500 }; String appurl = u.generateMobileAppUrl('61a65f12-eccd-4b42-bd7d-2de4a8699b80',options); System.debug('appurl : '+ appurl);splitToken_global static List splitToken(String token , Integer sizeLimit) _Method used to split a token. sharinpix.Utils u = new sharinpix.Utils(); string tokens = sharinpix.Client.getInstance().token( new Map<String, Object> { 'abilities' => new Map<String, Object> { '0018a00001rL2scAAC' => new Map<String, Object> { 'Access' => new Map<String, Object> { 'see' => true, 'image_list' => true, 'image_upload' => true } } } }); integer size = 255; list<String> actualList = sharinpix.Utils.splitToken(tokens,size); System.debug(actualList);getAlbumImageIdsglobal List getAlbumImageIds(Id albumId)Retrieves all image IDs found in an album. sharinpix.Utils u = new sharinpix.Utils(); list <String> lstAlbumId = u.getAlbumImageIds('a0A8a00002ho8elEAA'); System.debug(lstAlbumId);deleteImage_global List deleteImage(String imageId) _Deletes image corresponding to the given ID sharinpix.Utils u = new sharinpix.Utils(); List <String> lstImg = u.deleteImage('a7d50d26-4f01-4298-9d1b-f69db2214f07'); System.debug(lstImg);deleteImageglobal List deleteImage(String imageId , map<string, object> payload)Deletes image corresponding to the given ID taking into consideration parameters passed in payload. Available options:purgeSet to true to completely delete image from SharinPix. This action cannot be undone and image cannot be restored. Example usage: &#xNAN;(new sharinpix.Utils()).deleteImage('imageIdHere', new map<string,object>{'purge' => true}); sharinpix.Utils u = new sharinpix.Utils(); List <String> lstImg = u.deleteImage('a7d50d26-4f01-4298-9d1b-f69db2214f07', new Map<string,object> {'purge' => true}); System.debug(lstImg);deleteImages_global List deleteImages(List imageIds) _Deletes images corresponding to the given IDs sharinpix.Utils u = new sharinpix.Utils(); list <String> delImgs = u.deleteImages(new list<String> {'0e7d41a8-b1b8-440a-9734-24e5a2923075', 'fa2b5a41-e43c-4ed0-ac85-58ff5b90a4ed'}); System.debug(delImgs)deleteImagesglobal List deleteImages(List imageIds , map<string, object> payload)Deletes images corresponding to the given IDs taking into consideration parameters passed in payload. Available options:purgeSet to true to completely delete images from SharinPix. This action cannot be undone and images cannot be restored. sharinpix.Utils u = new sharinpix.Utils(); list <String> delImgs = u.deleteImages(new list<String> {'0e7d41a8-b1b8-440a-9734-24e5a2923075', 'fa2b5a41-e43c-4ed0-ac85-58ff5b90a4ed'}, new Map<string,object> {'purge' => true}); System.debug(delImgs)updateSessionIdValidityglobal ObjectupdateSessionIdValidity(String id , Boolean _valid) _Validates or invalidates a session (corresponding to the given session Id in the parameters)Updates valid to true to validate a session or false to invalidate a session. sharinpix.Utils u = new sharinpix.Utils(); u.updateSessionIdValidity('00524000000kfy0aan-open', false); createContentDocumentFromUrlYou can utilize this method to transform a public URL into a content document. It's applicable for converting SharinPix Images into content documents using SharinPix public image URLs.createContentDocumentFromUrl without the option to add custom filename_ global static Id createContentDocumentFromUrl(String url)_Download a file at a URL to Content Document String url = '[https://app.sharinpix.com/3/9a3dc1c/YXltYW4ubmdyb2suaW8vaW1hZ2VzLzI1ZWNjOTdjLTg4NDMtNDEyNS1hNjI0LTIxNTg5YTBlNDBhOS90aHVtYm5haWxzL29yaWdpbmFsLTk5Y2VjNzgwMGM5LmpwZw/laptop7.jpg](https://scpix-proxy.herokuapp.com/3/9a3dc1c/YXltYW4ubmdyb2suaW8vaW1hZ2VzLzI1ZWNjOTdjLTg4NDMtNDEyNS1hNjI0LTIxNTg5YTBlNDBhOS90aHVtYm5haWxzL29yaWdpbmFsLTk5Y2VjNzgwMGM5LmpwZw/laptop7.jpg)'; Sharinpix.Utils.createContentDocumentFromUrl(url);createContentDocumentFromUrl with option to add custom filename_ global static Id createContentDocumentFromUrl(String url, Map<String, Object> options)_Download a file at a URL to Content Document with custom filenameNote: The custom filename should be added with its extension (e.g. jpg, png, jpeg, and so on) and the key should be 'filename' as shown in the example below. String url = '[https://app.sharinpix.com/3/9a3dc1c/YXltYW4ubmdyb2suaW8vaW1hZ2VzLzI1ZWNjOTdjLTg4NDMtNDEyNS1hNjI0LTIxNTg5YTBlNDBhOS90aHVtYm5haWxzL29yaWdpbmFsLTk5Y2VjNzgwMGM5LmpwZw/laptop7.jpg](https://scpix-proxy.herokuapp.com/3/9a3dc1c/YXltYW4ubmdyb2suaW8vaW1hZ2VzLzI1ZWNjOTdjLTg4NDMtNDEyNS1hNjI0LTIxNTg5YTBlNDBhOS90aHVtYm5haWxzL29yaWdpbmFsLTk5Y2VjNzgwMGM5LmpwZw/laptop7.jpg)'; Map<String, Object> options = new Map<String, Object> {'filename' => 'filename.jpg'} Sharinpix.Utils.createContentDocumentFromUrl(url, options);Note:Before calling an external site (url from an external site), that site must be registered in the Remote Site Settings page of Salesforce. How to register new site?

Last updated