You need to sign in to do that
Don't have an account?
Vardan Minasyan 9
getting meaningful errors from createRecord
Hi ! I am working with Lighting Web Components, and looking to understand how to get meaningful error codes from the createRecord() function.
The example I am working with is an Opportunity Create javascript function. It is supposed to fail because it is missing the Opportunity Stage Name. It fails as expected, however, the error message is not at all helpful. Here is the error message that I am receiving:
:[object Object] reduce: An error occurred while trying to update the record. Please try again. status:400 undefined.
My question is how can I go about getting meaningful error messages in this case. Do I have to enable some kind of logging in Salesforce Options? Write a custom Apex Class that throws better errors? Or is there a different way to access the createRecord() error return to actually see what the error is?
Here is the javascript code:
The example I am working with is an Opportunity Create javascript function. It is supposed to fail because it is missing the Opportunity Stage Name. It fails as expected, however, the error message is not at all helpful. Here is the error message that I am receiving:
:[object Object] reduce: An error occurred while trying to update the record. Please try again. status:400 undefined.
My question is how can I go about getting meaningful error messages in this case. Do I have to enable some kind of logging in Salesforce Options? Write a custom Apex Class that throws better errors? Or is there a different way to access the createRecord() error return to actually see what the error is?
Here is the javascript code:
import { LightningElement, track } from 'lwc'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import { createRecord } from 'lightning/uiRecordApi'; import { reduceErrors } from 'c/ldsUtils'; import OPPORTUNITY_OBJECT from '@salesforce/schema/Opportunity'; import NAME_FIELD from '@salesforce/schema/Opportunity.Name'; import CloseDate_FIELD from '@salesforce/schema/Opportunity.CloseDate'; import StageName_FIELD from '@salesforce/schema/Opportunity.StageName'; export default class LdsCreateOpportunity extends LightningElement { @track opportunityId; // errorInfo = undefined; name = ''; closeDate = new Date('December 17, 2019 03:24:00'); stageName = 'Prospecting'; // @track error; handleNameChange(event) { this.opportunityId = undefined; this.name = event.target.value; } createOpportunity() { const fields = {}; fields[NAME_FIELD.fieldApiName] = this.name; fields[CloseDate_FIELD.fieldApiName] = this.closeDate; // fields[StageName_FIELD.fieldApiName] = this.stageName; // - this breaks the save by omitting the required stage name field const recordInput = { apiName: OPPORTUNITY_OBJECT.objectApiName, fields }; createRecord(recordInput) .then(opportunity => { this.opportunityId = opportunity.id; this.dispatchEvent( new ShowToastEvent({ title: 'Success', message: 'Opportunity created. Message goes here!', variant: 'success' }) ); }) .catch(error => { this.dispatchEvent( new ShowToastEvent({ title: 'Error creating record', message:'Here is the error:' + error.body + ' reduce: ' + reduceErrors(error).join(', ') + 'status:' + error.status + ' ;status text' + error.statustext, variant: 'error' } ) ); }); } }
Here is the link: LWC Debugging (https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.debug_mode_enable). Still am surprised that the actual error that shows is just status:400 undefined
All Answers
Here is the link: LWC Debugging (https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.debug_mode_enable). Still am surprised that the actual error that shows is just status:400 undefined
RyanAtTGH, how did u specified the Owner Id. I am also getting the error while creating a new record in Contact Object?