Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs
9 votes
Accepted

LWC + Jest: Mocking imperative Apex and returning a value

For easier readability, you can store as many .json files as needed for all your mocked data needs and have "less" in your jest test. Within your __tests__ directory, you can create a data ...
Kris Goncalves's user avatar
6 votes
Accepted

Apex Method Overloading is not working when called from LWC javascript Controller

This has nothing to do with polymorphism. Polymorphism deals with situations where you have multiple classes that share a common ancestor. What you're dealing with are called "overloaded methods.&...
sfdcfox's user avatar
  • 494k
5 votes

LWC + Jest: Mocking imperative Apex and returning a value

This is how I did it: jest.mock( "@salesforce/apex/MyController.insertRecords", () => { return { default: jest.fn(payload => { const ...
Matthew Souther's user avatar
4 votes
Accepted

Error calling Apex imperatively from LWC in a JavaScript method. Error gotten -> [F.default(...).then(...).error is not a function],

There isn't actually any Promise.error function. Instead it's Promise.catch, So you should just replace, checkSize({docId: fileId}) .then(result => { resultSize = result }) ....
Sachin Hooda's user avatar
  • 1,632
3 votes
Accepted

passing object from LWC to Apex not working as expected (Class does not have no-arg constructor error)

If your class has no constructors, you get a "free" zero-argument, do-nothing constructor. If you have at least one constructor defined, this "free" constructor goes away, and you ...
sfdcfox's user avatar
  • 494k
3 votes

LWC Jest test fails when testing data returned after apex imperative call

lwc-recipes is a good resource for examples of how to mock different LWC scenarios. For your situation, there's an example of apexImperativeMethodWithParams. In this scenario, you have to do two ...
Kris Goncalves's user avatar
3 votes
Accepted

Unable to insert contact record on button click using lwc and apex controller

The apex method requires a Contact as input parameter, but you're passing an object with these four properties that are not Contact's fields: FNAME LNAME Phone EMAIL You could either edit both JS ...
RubenDG's user avatar
  • 8,572
3 votes

How to detect Salesforce UI navigation in an LWC

I assume this behaviour is because the Salesforce UI is an SPA (Single Page Application). Not entirely. LWR itself doesn't suffer from this problem. See this demo. What you're experiencing is a side ...
sfdcfox's user avatar
  • 494k
3 votes
Accepted

How to use imperative apex from Salesforce Sites?

Yes, you can call Apex from sites/digital experiences. The key is permissions. Make sure the Guest User has access to the Apex class for unauthenticated sites, and that the member profiles have access ...
sfdcfox's user avatar
  • 494k
2 votes

Imperative Apex call under guest user results in List has no rows for assignment to SObject, anonymous execution works fine

Don't use a getter for this purpose. They can, and will, be called multiple times in a semi-unpredictable order. You can call the method directly from your wire handler: @wire(CurrentPageReference) ...
sfdcfox's user avatar
  • 494k
2 votes

I'm trying to call method Imperatively based on the wired result but not getting result

EDIT - Changed based on comment by Phil - Looking at the documentation, it appears that the salesforce/user/Id module must always execute before the main lwc controller class is constructed. Assign ...
Caspar Harmer's user avatar
1 vote

How to detect Salesforce UI navigation in an LWC

First of all, the connected-disconnected callbacks seems to be related to the node API, specifically to the isConnected attribute. doc A boolean indicating whether or not the Node is connected (...
Oleksii Fisher's user avatar
1 vote
Accepted

Gack Error Id : 2020409769-104966 (551437190) when there is no constructor without parameters

Initially noticed that issue on December 19, 2022 when trying to find a workaround for another gack id. Initial gack id was actually An internal server error has occurred Error ID: 1401126796-122884 (...
Patlatus's user avatar
  • 17k
1 vote
Accepted

Calling Apex function results in a "default(...).this is not a function" error, a similar function works perfectly

I found an answer, but wanted to leave this up in case it frustrates anyone else. I updated my VS Code LWC Extension to the latest version (55.8), wrote and added an identical Apex method (different ...
SFD's user avatar
  • 35
1 vote

Imperative Apex call under guest user results in List has no rows for assignment to SObject, anonymous execution works fine

The problem is with Guest User access. The topic started has deleted her answer: This was due to field level security on the guest user: To fix: Click the gear icon, then Setup. Go to Digital ...
Patlatus's user avatar
  • 17k
1 vote
Accepted

unescape String APEX

Don't JSON-encode your strings; the platform does this for you automatically. methodName({strLst: strLstLWC}); By double-encoding, you're making more work for yourself when you later have to double-...
sfdcfox's user avatar
  • 494k
1 vote

Display error in toast from imperative call

Try the below to see if this helps const event = new ShowToastEvent({ title: 'Save status', message: error.body.message, variant: 'error' });...
Mohith Shrivastava's user avatar
1 vote
Accepted

@track decorated property not updating LWC after imperative call

I think the problem is that you are reassigning the variable, and overwritting the actual tracked object. You can both: this.advisor.Name = 'Bossman'; //As fas as it is @tracked Or: this.advisor = {.....
Javier Ponce's user avatar
1 vote

@track decorated property not updating LWC after imperative call

You dont need the @track annotation since you are reassigning the entire variable. Can you try these 2 things? Deep clone the object (just as an attempt) and before assignin the value, assign it to ...
Gabriel Serrano Salas's user avatar
1 vote
Accepted

How to refresh Related records & get the latest Count in LWC

Though getRecordNotifyChange() should update the cache but you can also try setting a timeout using old way to refresh the related components. Try with both settimeout and without. You can also try ...
Anshul Agrawal's user avatar
1 vote

LWC + Jest: Mocking imperative Apex and returning a value

You can also use a __mocks__ directory at the root level of your project, like so: __mocks__/@salesforce/apex/ControllerName.MethodName module.exports = { default: jest.fn().mockResolvedValue([]) }; ...
Nicholas Zozaya's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible