7

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:

This is the image that is beeing shown

=> 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?

  • 2
    +1 for the improvement, next time, if you can update your question, that way, we can remove the downvotes or even upvote, it will be easier for everyone. You might want to delete Show a list of accounts with their image. Thanks! – glls Jul 1 '18 at 16:35
1

The "easiest" solution I have found for this particular problem is creating a custom field of type x depending where the image is/will be stored or referenced, for ex, amazon bucket, url, or a richTextfield within Salesforce.

This would allow you to easily render the output image conditionally, otherwise, you would basically have to validate somehow that the actual request url of the image returns a value, since accounts might reference an actual url that resembles https://pbs.twimg.com/profile_images/..... if loaded from Twitter, or some other variant if from youtube, etc etc.. In my experience, there is no clean and easy way of checking this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.