This is ridiculous, but I have issues displaying a list of accounts in a lightning component. The issue is, that I need to show the account icon along with the account name.

I basically have the .cmp like this:

<img src="{!currentAccount.PhotoUrl}" alt="" width="24" height="24" />

<a href="{!'/one/one.app?#/sObject/'+ currentAccount.Id + '/view'}" class="textUnderline outputLookupLink slds-truncate forceOutputLookup" style="border-bottom: 1px dotted; text-decoration: none;">

Any the exercept of the controller:

List<Account> accountList = [SELECT Id, Name, PhotoUrl FROM Account WHERE Id IN (SELECT Account2__c FROM AccountRelation__c WHERE Account1__c = :recordId)];

The problem: Account.PhotoUrl often redirects to the default image of the account, when no custom image was found in social media networks. This custom image is not a good fit for our design. I'd like to change it to another image to display, when no custom image was found.

So in short: accountHasSocialMediaImage => display the social media image !accountHasSocialMediaImage => display the default house image

Account.PhotoUrl always has a valid value - it's never null, but always points to a redirect to the default image. It can not be inferred from the value of .PhotoUrl if the account has a custom image.

Any ideas?


Anchor Tag:

Using the href attribute of an <a> tag leads to inconsistent behavior in different apps and shouldn’t be relied on. For example, don’t use this markup to link to a record:

<a href="/XXXXXXXXXXXXXXXXXX">Salesforce record ID (DON'T DO THIS)</a>

Use Navigation Events as indicated in the doc.

as per "to change it to another image to display, when no custom image was found."

You can use conditional rendering --> <aura:if>

to display the appropriate image based on your criteria

| improve this answer | |
  • Thank you for the reply. The thing is that I can't use conditional rendering, as the value of .PhotoURL is always something like "/images/$accountid.png". So from the URL alone, it can not be inferred whether the PhotoURL will display the default image or an image specific for that account. – Blake Jun 30 '18 at 11:00
  • well, if you know what the value of the default image is, you can add validation in your conditional rendering so if the default image url path matches xxx then use your default image instead – glls Jun 30 '18 at 15:53
  • That is exactly what's not working. Otherwise it would be trivial. The .PhotoURL has the same pattern, regardless what image the account uses. – Blake Jun 30 '18 at 16:00
  • its not clear what you mean by "not working" can you open a new post with how/what you have tried? – glls Jun 30 '18 at 16:04
  • 1
    I understand what you ar trying to do, what i dont understand is where you are stuck in your code. If the above is the only code you have, you are better of starting at Trailheads – glls Jun 30 '18 at 19:05

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.