ForceChallenges
ProblemsDailyNotesInterview
Sign in

Practice

All problemsSOQL practiceApex trigger challengesDaily challengeOpportunityTrigger.oldMapBefore UpdateBulkificationContactValidationGROUP BYSemi-JoinAccountBefore Insert

Interview questions

All questionsAdminAdministrationApexApex TriggerAsync ApexDevelopmentField ServiceField ServiceIntegrationLwc

By company

DeloitteSalesforceAccentureInfosysPwCCognizant

Learn

Study notes

ForceChallenges

AboutContact usPrivacy PolicyTerms of ServiceFor AI assistants (llms.txt)
© 2026 ForceChallenges · Salesforce SOQL & Apex trigger practice
Development questions12 of 102
DevelopmentMedium 1 min read

What is the difference between calling Apex with @wire and calling it imperatively in LWC?

Answer

@wire

  • Declarative and reactive: re-runs automatically when $ parameters change.
  • Requires the Apex method to be @AuraEnabled(cacheable=true).
  • Results are cached client-side; refresh with refreshApex.
  • Can't be triggered manually; ideal for read-only data on load.

Imperative

  • You call the method like a promise on an event (button click, etc.).
  • Works with non-cacheable methods, so it can perform DML.
  • You control timing and handle .then/.catch or async/await.
javascript
async handleSave() {
  try { await saveRecord({ rec: this.rec }); }
  catch (e) { this.error = e.body.message; }
}

Use wire for reading data, imperative for DML or user-triggered calls.

lwcapexwire
Practice SOQL & Apex
PreviousWhat is refreshApex and how do you use it in an LWC?Next What is Lightning Message Service (LMS) and how do you use it to communicate between components?

More Development questions

  • What is reactivity in LWC and when does a field trigger a re-render?
  • What are the best practices to improve LWC performance?
  • How do you unit test an LWC with Jest?
  • How do you use a third-party JavaScript library or static resource in LWC?
  • Why can renderedCallback run multiple times and how do you prevent repeated execution?