Lightning Update List of Records Workaround (Quick Fix)
Salesforce Lightning can cause type issues when upserting records from JavaScript to Apex, throwing errors about generic sObject lists. The solution demonstrated involves creating a new list of the specific sObject type in Apex and adding the records to it before the upsert call, bypassing casting issues. This quick fix is a practical workaround for developers facing similar type enforcement problems when working with Lightning components and Apex integrations.
- Passing generic sObject lists to Apex upsert causes errors in Lightning context.
- Create a new typed list in Apex and add passed records before upsert.
- Avoid attempts to cast or modify records in JavaScript to fix type issues.
- Use @AuraEnabled methods carefully with strongly typed input parameters.
- This workaround resolves 'upsert not allowed on generic sObject list' errors.
I’ve been doing some work with Salesforce Lightning, and so far it is certainly proving… challenging. I ran into an issue the other day to which I could find no obvious solution. I was attempting to pass a set of records from my javascript controller to the Apex controller for upsert. However it was throwing an error about ‘upsert not allowed on generic sObject list’ or something of that nature when the list of sObjects was in-fact defined as a specific type. After messing around with some various attempts at casting the list and modifying objects in the javascript controller before passing to the apex to have types I couldn’t find an elegant solution. Instead I found a workaround of simply creating a new list of the proper object type and adding the passed in records to it. I feel like there is probably a ‘proper’ way to make this work, but it works for me, so I figured I’d share.