Requirement: a lightning component that displays a list of ~5 accounts with their Name and their Account image.
Methodology:
CMP:
<aura:iteration items="{!v.relatedRecords}" var="currentAccount" indexVar="index">
<lightning:icon iconName="standard:account" size="small" />
<a href="{!'/one/one.app?#/sObject/'+ currentAccount.Id + '/view'}" class="textUnderline outputLookupLink slds-truncate forceOutputLookup" style="border-bottom: 1px dotted; text-decoration: none;">
{!currentAccount.Name}
</a>
</aura:iteration>
APEX:
public static List<Account> getAccounts(final Id recordId) {
List<Account> allAccounts = [SELECT Id, Name, PhotoUrl FROM Account WHERE Id IN (SELECT Account2__c FROM AccountRelation__c WHERE Account1__c = :recordId)];
return allAccounts;
}
And a Helper, which just transfers the data from the Apex-Controller to the view.
The issue: when an account does not have a custom image, the following is shown instead:
=> I don't like that default picture and would like to replace it with the normal one for accounts (the "house").
I found that pretty difficult, because .PhotoUrl always has a value like this:
/services/images/photo/0010Y00000rTgqfQAE
Regardless of whether an image has been set. 0010Y00000rTgqfQAE is equal to the Id of the Account. That's why I can't use any condition on the .PhotoURL field to replace it.
I tried writing an apex crawler that makes a HTTP request to follow the .PhotoURL until the endpoint (it's a redirect and the endpoint is the actual image, which would be suitable for pattern analysis), but it fails to retrieve the final image, as a valid salesforce session would be required to see the image.
Basically I'd prefer a simpler solution with normal salesforce functionality. Maybe there is some pattern to display a list of accounts along with their images?