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.

Example

The following example demonstrates how to call the duplicateImage method.

The duplicateImage method is used to duplicate an image to another album and has options to enable tag and image sync while performing the duplication.

global static string duplicateImage(string imageId, string albumId, map<string, object> options) 

The method parameters are:

  • imageIdThe image public ID.
  • albumIdThe ID of the target album, that is, the album on which the duplicated image will be uploaded. Note: 18 Chars ID is required for Salesforce ID.
  • options: A map accepting keys tags and sync. The keys tags and sync should be set to true for the method to perform tag duplication and image sync.

The method returns a String containing the duplicated image ID.

sharinpix.Utils.duplicateImage('a95f9022-3d4a-456c-aadc-9e25d350b70b', '00324000004GUxhAAG', new map<string, object>{ 'tags' => true, 'sync' => true});

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

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);

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');

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);

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

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});

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');

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);

duplicateImage

global static string duplicateImage(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 = sharinpix.Utils.duplicateImage('66d6d11a-6399-4713-be28-ebcbdc148c3b','0018a00001rL2sXAAS',new Map<String, object>{'tags'=> true});
System.debug(response);

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);

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);
  • 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);

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);

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<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'));

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);

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);

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);

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);

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);

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');

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 Boolean clearTags(String imageId)

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

uploadAttachment

global Object uploadAttachment(Id attachmentId, String albumId)

  • Uploads Salesforce attachments to SharinPix albums.

uploadAttachment

global Object uploadAttachment(Id attachmentId, String albumId, Map<String, Object> userMetadatas)

  • Uploads Salesforce attachments to SharinPix albums.

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);

uploadContentDocument

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

  • Uploads Salesforce ContentDocuments to SharinPix albums.

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 on every image.

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://p.sharinpix.com/3/52be042/YXBwLnNoYXJpbnBpeC5jb20vaW1hZ2VzL2JhYjIxNzlhLTllOGQtNGFkOS1hNDJjLWQ3YmM0NWVjY2RmNS90aHVtYm5haWxzL29yaWdpbmFsLTMyNGM4NmY2MzY4LmpwZw/windows-jw-t2bh5k5e-unsplash.jpg';
object result =u.uploadFromUrl(url,'0018a00001rL2scAAC','test');
System.debug(result);

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);

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);

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);

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);

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);

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);

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);

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);

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});

deleteImages

global List<String> deleteImages(List<String> imageIds)

  • Deletes images corresponding to the given IDs
sharinpix.Utils u = new sharinpix.Utils();
list <String> delImg = u.deleteImages(new list <String>{'0e7d41a8-b1b8-440a-9734-24e5a2923075'});
System.debug(delImg)

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> ids = new list <string>();
ids.add('fa2b5a41-e43c-4ed0-ac85-58ff5b90a4ed');
list<String> imageIds = u.deleteImages(ids);
system.debug(imageIds);

0 Comments

Add your comment

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