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.

Utils Method Example

renameAlbum

global Boolean renameAlbum(String oldAlbumId, String newAlbumId

  • Renames an album.

renameAlbum

global Boolean renameAlbum(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.
sharinpix.Utils u = new sharinpix.Utils();
boolean renamed = u.renameAlbum('0018a00001rL2scAAC','0018a00001rL2sXAAS', true);
System.debug(renamed);
Click to copy

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 String duplicateAlbum(String sourceAlbumId, String destinationAlbumId)

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

The code  below shows the code without tags.

SharinPix.Utils utls =new SharinPix.Utils();
utls.duplicateAlbum('0018a00001rL2scAAC','0018a00001rL2sXAAS');
Click to copy

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 String duplicateAlbum(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.

SharinPix.Utils utls =new SharinPix.Utils();
utls.duplicateAlbum('0018a00001rL2scAAC','0018a00001rL2sXAAS',true);
Click to copy

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.
SharinPix.Utils utls = new SharinPix.Utils();
utls.duplicateAlbum('0018a00001rL2scAAC','0018a00001rL2sXAAS',new Map<String,Object>{'einstein_boxes' => true, 'tags' => true});
Click to copy

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

getAlbumImages

global List<Object> 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');
Click to copy

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);
Click to copy

duplicateImageToAlbum

global string duplicateImageToAlbum(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);
Click to copy

duplicateImages

global List<Object> duplicateImages(List<String> 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'},'866c7fce-19bd-4562-9112-0743d451c883');
System.debug(response);
Click to copy

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 methods

getImageUrl

global String getImageUrl(String imageId, Map<String, Object> sharinpix, List<Object> 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);
Click to copy
  • Get the original url of an image (This url is a direct expiring url to the storage)
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);
Click to copy

getImageEndpoint

global String getImageEndpoint (String imageId, Map<String, Object> sharinpix, List<Object> 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);
Click to copy

croppedImageUrl

global String croppedImageUrl(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);
Click to copy

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);
Click to copy

getImageExternalUrls

global List<Object> 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'));
Click to copy

getOrgTags

global List<Object> getOrgTags()

  • Retrieves all tags present in your Organization.
sharinpix.Utils u = new sharinpix.Utils();
list <object> lstobj = u.getOrgTags();
System.debug(lstobj);
Click to copy

getAlbumTagImages

global List<Object> 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);
Click to copy

getAlbumTagImages

global List<Object> 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);
Click to copy

getTagsOnImage

global List<Object> 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);
Click to copy

getTagNamesOnImage

global List<String> 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);
Click to copy

addTag

global Object addTag(String imageId, String tagName)

  • Adds a tag on an image.
sharinpix.Utils u = new sharinpix.Utils();
u.addTag('bab2179a-9e8d-4ad9-a42c-d7bc45eccdf5','testInsertTags');
Click to copy

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'});
Click to copy

clearTags

global Boolean clearTags(String imageId)

  • Clears all tags applied to an image.
sharinpix.Utils u = new sharinpix.Utils();
u.clearTags('bab2179a-9e8d-4ad9-a42c-d7bc45eccdf5');
Click to copy

uploadAttachment

global Object uploadAttachment(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);
Click to copy

uploadAttachment

global Object uploadAttachment(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);
Click to copy

uploadAttachment

global Object uploadAttachment(Id attachmentId, String albumId, Map<String, Object> userMetadatas, List<String> 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);
Click to copy

uploadContentDocument

global Object uploadContentDocument(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);
Click to copy

uploadContentDocument

global Object uploadContentDocument(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);
Click to copy

uploadContentDocument

global Object uploadContentDocument(Id contentDocumentId, String albumId, Map<String, Object> userMetadatas, List<String> tags)

  • Uploads Salesforce ContentDocuments to SharinPix albums. 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.uploadContentDocument('0698a00000HCfOWAA1','0018a00001rL2scAAC',null,new List<String>{ 'tagA', 'tagB' });
System.debug(result);
Click to copy

uploadFromUrl

global Object uploadFromUrl(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);
Click to copy

uploadFromUrl

global Object uploadFromUrl(String imageUrl, String albumId, String filename, map<string, object> metadatas)

  • Uploads an image to SharinPix using an URL.
sharinpix.Utils u = new sharinpix.Utils();
string url ='https://p.sharinpix.com/3/52be042/YXBwLnNoYXJpbnBpeC5jb20vaW1hZ2VzL2JhYjIxNzlhLTllOGQtNGFkOS1hNDJjLWQ3YmM0NWVjY2RmNS90aHVtYm5haWxzL29yaWdpbmFsLTMyNGM4NmY2MzY4LmpwZw/windows-jw-t2bh5k5e-unsplash.jpg';
object result = u.uploadFromUrl(url,'0018a00001rL2scAAC','test1', new Map<string, string> { 'contentDocumentId' => '0698a00000HCfOWAA1' });
System.debug(result);
Click to copy

uploadWebshot

global Object uploadWebshot(String url, String albumId)

  • Captures screenshot from website URL and uploads to SharinPix.
sharinpix.Utils u = new sharinpix.Utils();
string url ='https://p.sharinpix.com/3/09d8e43/YXBwLnNoYXJpbnBpeC5jb20vaW1hZ2VzL2JhYjIxNzlhLTllOGQtNGFkOS1hNDJjLWQ3YmM0NWVjY2RmNS90aHVtYm5haWxzL21pbmktZmYxODdmZDFjODcuanBn/windows-jw-t2bh5k5e-unsplash.jpg';
object getUploadWebShot = u.uploadWebshot(url,'0018a00001rL2scAAC');
System.debug(getUploadWebShot);
Click to copy

uploadWebshot

global Object uploadWebshot(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  :
    sharinpix.Utils.uploadWebshot('https:/test/maps/test', '00324000004GUxhAAG', new Map<string, object>{ 'tags' => new List<string> {'mapTag'}});
sharinpix.Utils u = new sharinpix.Utils();
object response = u.uploadWebshot('http://app.sharinpix.com/maps/udhuec23b24kj44j','5008a00001uwxsNAAQ',new Map<String,object> {'tags'=> 'test'});
System.debug(response);
Click to copy

generateMobileAppUrl

global String generateMobileAppUrl(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);
Click to copy

generateMobileAppUrl

global String generateMobileAppUrl(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);
Click to copy

splitToken

global static List<String> 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);
Click to copy

getAlbumImageIds

global List<String> 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);
Click to copy

deleteImage

global List<String> 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);
Click to copy

deleteImage

global List<String> deleteImage(String imageId, map<string, object> payload)

  • Deletes image corresponding to the given ID taking into consideration parameters passed in payload. Available options:
    • purge
      • Set to true to completely delete image from SharinPix. This action cannot be undone and image cannot be restored. Example usage:
        (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);
Click to copy

deleteImages

global List<String> deleteImages(List<String> 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)
Click to copy

deleteImages

global List<String> deleteImages(List<String> imageIds, map<string, object> payload)

  • Deletes images corresponding to the given IDs taking into consideration parameters passed in payload. Available options:
    • purge
      • Set 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)
Click to copy

updateSessionIdValidity

global Object updateSessionIdValidity(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); 
Click to copy

createContentDocumentFromUrl

You 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

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 filename

Note: 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';
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?

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.