Posts

Showing posts from 2018

Working with Conditional Attribute Defaults in Lightning

Setting defaults on attributes in lightning can be a useful tool when setting the initial state of components.

There is an 'undocumented feature' that allows us to set attribute defaults conditionally, but you may find that this does not work exactly as you would expect.

It turns out that setting a conditional default will 'lock' any changes to that attribute, as demonstrated below.

In this example we create two attributes 'myString' and 'mySimpleString'. Both attributes have default values but the default on 'myString' is wrapped in a condition.

We then trigger an init handler to update the value of both strings to be 'Set Directly' when the component is initialised.

The example shows that 'mySimpleString' will update to the new value, but 'myString' does not.


For additional complexity, setting a conditional default with an object reference will 'lock' any changes to that attribute, except from the object used in…

Detect URL Format (Lightning Experience)

Following the announcement that the URL format in lightning experience will change from /one/one.app we are looking for a way of detecting which format is being used so that we can generate URLs in Apex.

For example, if we were to generate a PDF in Visualforce containing a URL to a lightning page we would like to correct the URL to use the correct format depending on whether the org is using `/one/one.app` or `/lightning`
What does it do? From the announcement:

It changes the URL format used by Lightning Experience standard apps and the Salesforce mobile app. For example:
Current format: https://<lightning.domain.com>/one/one.app/#/sObject/Account/home
New format: https://<lightning.domain.com>/lightning/o/Account/home

In Summer '18 the new URL format will be enforced, but in Spring '18 it can be enabled for testing via a critical update.
Why do we care? If the user enabled the critical update themselves we need to be able to make sure that our features still work.

London's Calling 2018: Getting Started with Salesforce Lightning Components & Lightning Data Service

Image
Many thanks to London's Calling for recording my session on Lightning Components and Lightning Data Service.

The full video is now available on YouTube.

Using targetRecord on Lightning Data Service

Image
The force:recordData attribute targetRecord promises to be a useful addition to Lightning Data Service in future versions.

We had hoped that the schema information would be included in the object so that client side validation and conditional field display would be possible, but that doesn't seem to be the case.
Available attributesfields: The fields that have been made accessible from force:recordData. e.g. v.record.fields.Name.valuechildRelationships: The child relationships defined on the recordapiName: The full API Name of the record. e.g. Accountid: The ID of the recordrecordTypeInfo: Any record type information relating to the record Convert the proxy to a readable object Sometimes being able to view the data in the record proxy object is useful for debugging. I have created a helpful method for this:
In your component helper, insert the following code:

Then, from anywhere in that component you can call helper.ouputProxy(record) where the record argument is the record proxy…

Handy Scripts for Salesforce Lightning Development

Lightning FLS. Throw exception if any field is not accessible.
https://gist.github.com/danic85/a5519c6591bce94cf4e7c7064506c50b
SLDS Wizard Progress Bar - Bar will not display without z-index on containing div
https://gist.github.com/danic85/cf71ce35e2cc25b273ff6be6a75b6d48 Binding lightning:input checkbox value. Must bind to 'checked' not 'value'
https://gist.github.com/danic85/4c48f7dd1d4532049b491c8cd1d47f31
Control visibility of lightning component using slds-hide
https://gist.github.com/danic85/d56e11650783e7fd6f635e962da3d79b
Lightning Select component markup with select inside iteration.
https://gist.github.com/danic85/de627813450c9b5a8b176c11c6b4e0e6