Skip to main content

Code reviews rule: Use of JavaScript in WebLinks

Written by David Martin

Use of JavaScript in WebLinks

Why is this an issue?

JavaScript WebLinks are no longer supported in Lightning Experience. They:

  • Do not work in Lightning Experience

  • Cannot be used in the Salesforce mobile app

  • Are considered legacy functionality

Examples

Example of incorrect WebLink (where linkType is javascript):

<WebLink>
<fullName>Account.Update_Status</fullName>
<linkType>javascript</linkType>
<url>alert('Updating status...');</url>
</WebLink>

Example of incorrect WebLink (where openType is onClickJavaScript):

<WebLink>
<fullName>Account.Update_Status</fullName>
<linkType>url</linkType>
<openType>onClickJavaScript</openType>
<url>/apex/MyPage?id={!Account.Id}</url>
</WebLink>

Example of correct approach (Lightning Quick Action). Note that the offending WebLink is replaced by a different metadata type β€” there is no Lightning-compatible variant of a JavaScript WebLink:

<QuickAction>
<fullName>Account.Update_Status</fullName>
<type>LightningComponent</type>
<lightningComponent>c:UpdateStatusAction</lightningComponent>
</QuickAction>

How can I fix violations?

Replace JavaScript Weblinks with Lightning-compatible alternatives:

  1. Quick Actions: For simple record operations, use quick actions.

  2. Lightning Web Components: For complex functionality, build LWC components and add them to page layouts.

  3. Flow: For guided processes, use Screen Flows launched from buttons.

  4. Custom Lightning Actions: Create Lightning components that can be invoked from buttons.

When should I disable this rule?

You may dismiss specific violations for orgs that exclusively use Salesforce Classic with no plans to migrate to Lightning Experience.

Resources

Did this answer your question?