• Vardan Minasyan 9
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hi! 
I want to use/create an autocomplete textbox using Lightning Web Components. Particularly, I want an autocomplete textbox for looking up a PriceBookEntry2 so that I can add a product to an opportunity, on the same page as Opportunity. 
I see options for autocomplete textbox for Visual Force, for Aura Lightning. However, I can't find anything for Lightning Web Components. 

I do see Lightning-Input (https://developer.salesforce.com/docs/component-library/bundle/lightning-input/example), but I don't know how to make it an autocomplete type.

What's the best way to go about it?

The final result needs to be an opportunity form, where a person can add/edit/delete products on the same page. 
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:
 
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'
                    }
                    )

                    
                );
            });
    }
}

 
Hi! 
I want to use/create an autocomplete textbox using Lightning Web Components. Particularly, I want an autocomplete textbox for looking up a PriceBookEntry2 so that I can add a product to an opportunity, on the same page as Opportunity. 
I see options for autocomplete textbox for Visual Force, for Aura Lightning. However, I can't find anything for Lightning Web Components. 

I do see Lightning-Input (https://developer.salesforce.com/docs/component-library/bundle/lightning-input/example), but I don't know how to make it an autocomplete type.

What's the best way to go about it?

The final result needs to be an opportunity form, where a person can add/edit/delete products on the same page. 
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:
 
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'
                    }
                    )

                    
                );
            });
    }
}