public with sharing class ProfilePhotoClass { @AuraEnabled(cacheable=true) public static string ProfilePhotoMethod(String Id){ try { List allRelatedCd=[SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId=:Id ]; System.debug('allRelatedCd'+allRelatedCd); List idTitles=new List(); for(ContentDocumentLink cd:allRelatedCd){ idTitles.add([SELECT Id,Title FROM ContentDocument WHERE Id=:cd.ContentDocumentId]); } System.debug('idTitles'+idTitles); ListidofProfile=new List();//Storing that ids whos title contains Profile for(ContentDocument vb:idTitles){ if(vb.Title.containsIgnoreCase('Profile')){ idofProfile.add(vb.Id); } } System.debug('idofProfile'+idofProfile); ContentDocument contentList0=[SELECT Id FROM ContentDocument WHERE Id =:idofProfile ORDER BY CreatedDate DESC LIMIT 1]; System.debug('contentList0'+contentList0); ContentVersion cv = [SELECT Id,ContentBodyId FROM ContentVersion WHERE ContentDocumentId = :contentList0.Id]; System.debug('cv'+cv); return 'https://suprnova-dev-ed.develop.file.force.com/sfc/servlet.shepherd/version/renditionDownload?rendition=ORIGINAL_Jpg&versionId='+cv.Id+'&operationContext=CHATTER&contentId='+cv.ContentBodyId; } catch (Exception e) { throw new AuraHandledException(e.getMessage()); } } }