Skip to content

Instantly share code, notes, and snippets.

@dhaniksahni
Created August 1, 2020 11:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dhaniksahni/827ef8bce2b807b3f9fa6b40c3f7b20e to your computer and use it in GitHub Desktop.
Get Image Detail for Image map
public class ImageMapController {
@auraenabled(cacheable=true)
public static List<Image__c> getAllImages()
{
return [select id,name from Image__c];
}
@auraenabled(cacheable=true)
public static ImageResponse getImage(string id)
{
if(string.isEmpty(id))
{
throw new BaseException('Bad Input');
}
List<ContentDocumentLink> links=[SELECT ContentDocumentId,LinkedEntityId FROM ContentDocumentLink where LinkedEntityId=:id];
Set<Id> ids=new Set<Id>();
for(ContentDocumentLink link:links)
{
ids.add(link.ContentDocumentId);
}
List<ContentVersion> versions=[SELECT VersionData,Title,ContentDocumentId,FileExtension FROM ContentVersion WHERE ContentDocumentId = :ids AND IsLatest = true];
List<ContentDistribution> cdts=[select ContentDocumentId,DistributionPublicUrl,ContentDownloadURL from ContentDistribution where ContentDocumentId =:ids];
Map<String, ContentDistribution> contentList= new Map <String, ContentDistribution>();
for(ContentDistribution cdt:cdts)
{
contentList.put(cdt.ContentDocumentId, cdt);
}
List<ImageDetail__c> details=[select Id,Coordinate__c,Shape__c, LinkUrl__c,Detail__c from ImageDetail__c where Image__c=:id];
for(ContentVersion attach:versions)
{
ContentDistribution image=contentList.get(attach.ContentDocumentId);
if(image!=null)
{
ImageResponse response=new ImageResponse();
response.PublicUrl=image.DistributionPublicUrl;
response.DownloadableUrl=image.ContentDownloadUrl;
response.Details=details;
return response;
}
}
return null;
}
public class ImageResponse
{
@auraenabled
public string PublicUrl;
@auraenabled
public string DownloadableUrl;
@auraenabled
public List<ImageDetail__c> Details;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment