You need to sign in to do that
Don't have an account?
AncaComaneciu
You have uncommitted work pending. Please commit or rollback before calling out
I have 2 lightning components that do HttpRequest:
- 1st components requests some infrmation that needs to be saved in Salesforce
- 2nd component requests some information for display purposes
Use cases:
- just 1st component in a SFDC community - all works ok
- just 2nd component in a SFDC community - all works ok
- 2nd component and then 1st component in a SFDC community - all works ok
- 1st component and then 2nd component in a SFDC community - it gives me the "You have uncommitted work pending. Please commit or rollback before calling out" error.
It seems that all aura code is executed on one single thread instead of having one thread for each lightning component.
I tried to do the update in a future call but it still fails...
Does anyone knows how i could fix this?
- 1st components requests some infrmation that needs to be saved in Salesforce
- 2nd component requests some information for display purposes
Use cases:
- just 1st component in a SFDC community - all works ok
- just 2nd component in a SFDC community - all works ok
- 2nd component and then 1st component in a SFDC community - all works ok
- 1st component and then 2nd component in a SFDC community - it gives me the "You have uncommitted work pending. Please commit or rollback before calling out" error.
It seems that all aura code is executed on one single thread instead of having one thread for each lightning component.
I tried to do the update in a future call but it still fails...
Does anyone knows how i could fix this?
All Answers
I am using this in a customer community where i have 2 separate lghtning components that work without any issues independantly. the problem is when i put both of them on the same page, the logic for both components is executed on the same thread.
I cannot share my code here but i will give as example what you gave me:
i have the first lightning component that does the following action:
public PageReference CallWebService() {
// Execute a call to a Web Service
HttpRequest req = new HttpRequest();
req.setEndpoint('http://MyWebService12345678790.com?id=' + myAccount.Id);
req.setMethod('GET');
HttpResponse response = new Http().send(req);
// Simulate an update
myAccount.Name = 'Test Account 2';
update myAccount;
return null;
}
and the second component that does the following action:
public PageReference CallWebService2() {
// Execute a call to a Web Service
HttpRequest req = new HttpRequest();
req.setEndpoint('http://MyWebService12345678790.com?id=' + myAccount.Id);
req.setMethod('GET');
HttpResponse response = new Http().send(req);
return null;
}