Category: Apex
-
Lightning Message Channels in Background Utility Items?
Question I am trying to get a Background Utility Item (using Aura) to listen for and propagate some events from the Workspace API. After setting up my Lightning Message Channel and writing both a publisher and subscriber, I noticed that the subscriber is not receiving any events. When I checked the browser console, I saw…
-
Why Does My Apex Callout Fail with SunCertPathBuilderException?
Question I am trying to make an Apex callout from Salesforce to an external system that is hosted inside a corporate firewall. The firewall forwards the request to a load balancer, which then routes it to the appropriate web server. However, when I attempt the callout from Salesforce, I encounter the following error: The same…
-
Mass Updating Contacts Causes “Apex CPU Time Limit Exceeded”?
Question I’m attempting to perform a mass update on Contacts using Execute Anonymous, but I keep encountering the following error: System.LimitException: Apex CPU Time Limit Exceeded Here’s the code I’m using: Why is this happening, and how can I optimize my approach to avoid hitting the CPU time limit? Answer The Apex CPU time limit…
-
How Can I Call the Salesforce API from a Lightning Component?
Question I need to call the Apex Wrapper Metadata API from a Lightning component, but I am facing an issue where there is no native support for acquiring a valid API session ID from an @AuraEnabled method in an Apex controller. Salesforce documentation suggests using a Named Credential to bypass this security restriction. However, when…
-
How Can I Create a Chatter File Using Apex?
Question In the Chatter tab, I can navigate to “Files” and upload a file without attaching it to any specific record. I want to achieve the same functionality purely through Apex. How can this be done? Answer Yes, you can create a Chatter File (Salesforce File) using Apex by working with the ContentVersion object. Salesforce…
-
Does Salesforce Named Credentials Support OAuth2 Client Credentials Grant?
Question I need to authenticate an external API using OAuth2 Client Credentials Grant and prefer using Salesforce Named Credentials to handle authentication, token storage, and refresh automatically. However, I haven’t found clear documentation confirming its support for this grant type. From my research, Named Credentials primarily support OAuth flows like Authorization Code Grant and OpenID…
-
How to Pass a Variable from One Apex Class to Another?
Question I have an Apex class (MyCTIExtensions) that retrieves a phone number and stores it in a static variable (phoneNumber). When certain conditions are met (cases.size() > 1), the class calls a Visualforce page. The Visualforce page’s controller (FlowRedirectController) is supposed to retrieve this phoneNumber and use it to construct a URL for a Flow.…
-
Why is sfdx update not working on my laptop?
Question I’m trying to update the Salesforce CLI using sfdx update, but it keeps failing with the following error: I have tried running the update in a Command Prompt with Administrator privileges. I also uninstalled the CLI and reinstalled it using sf-x64.exe. I can install the CLI from scratch without any issues, but updating it…
-
Why Are Refresh Tokens Expiring? – Salesforce Connected App
Question We have configured our web application to authenticate with Salesforce using OAuth2 via a Connected App. The Connected App is set up to ensure that refresh tokens never expire unless manually revoked. When an admin connects the Connected App to our web application, we securely store the received refresh token so that we can…
-
How Can I Delete Triggers and Classes from Production?
Question I was told that classes and triggers cannot be deleted directly in Production. Instead, they must be deleted in a Sandbox and then deployed as deletions. However, after deleting a class in Sandbox, it does not appear as a deployable change—red or otherwise. Do deleted triggers/classes show up somewhere else for deployment? Does this…