• Shekhar Agarwal
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
My question is in voting criteria, whenever your component is loaded whether you entered age value or not, attribute 'Eligible for voting' will give you default value' false'(i.e. Congrats! You can vote. OR 'Sorry! you can't ' . But I want 'Eligible for voting' value should only be displayed when we enter the age field. else don't show anything. How will be achieve this?
Below is the code:
Component Code:
<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
    <aura:attribute name="EligibleOrNot" type="boolean" default="true"></aura:attribute>
    
    <ui:inputText label="First name" aura:id="fname" placeholder="First Name"></ui:inputText>
    <ui:inputText label="Last name" aura:id="lname" placeholder="Last Name"></ui:inputText>
    <ui:inputText label="Age" aura:id="age" placeholder="Enter Age"></ui:inputText>
    <ui:button label="Check Eligibility" aura:id="checkeligibility" press="{!c.getEligibility}"></ui:button>
    
    <aura:if isTrue="{!v.EligibleOrNot}">
        Congrats! You can Vote.
        <ui:button label="Give Vote"></ui:button>
        
    <aura:set attribute="else">
         Sorry! You can not vote.
        <ui:button label="Cancel Vote"></ui:button>
        
    </aura:set>  
    
    </aura:if>
    
</aura:component>
Controller Code:
({
    getEligibility : function(component) {
        
        var vAge = component.find("age").get("v.value");
        
        if(vAge != null && vAge>=18){
            component.set("v.EligibleOrNot",true);
        }
        if(vAge!=null && vAge<18){
            component.set("v.EligibleOrNot",false);
        }
        
    }
})
I have created a custom object Student Master and whenever I am inserting a new record in Student Master, it has to check pan card number in another custom object "Black Listed Candidate" and if it is found then show  a warning message on the page that "PAN card is BlackListed" on Saving the record. This message needs to be shown in VisualForce page and then that page needs to be called in Custom object.
My VFP is getting called but message is not coming. Please help me for this.
My question is in voting criteria, whenever your component is loaded whether you entered age value or not, attribute 'Eligible for voting' will give you default value' false'(i.e. Congrats! You can vote. OR 'Sorry! you can't ' . But I want 'Eligible for voting' value should only be displayed when we enter the age field. else don't show anything. How will be achieve this?
Below is the code:
Component Code:
<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
    <aura:attribute name="EligibleOrNot" type="boolean" default="true"></aura:attribute>
    
    <ui:inputText label="First name" aura:id="fname" placeholder="First Name"></ui:inputText>
    <ui:inputText label="Last name" aura:id="lname" placeholder="Last Name"></ui:inputText>
    <ui:inputText label="Age" aura:id="age" placeholder="Enter Age"></ui:inputText>
    <ui:button label="Check Eligibility" aura:id="checkeligibility" press="{!c.getEligibility}"></ui:button>
    
    <aura:if isTrue="{!v.EligibleOrNot}">
        Congrats! You can Vote.
        <ui:button label="Give Vote"></ui:button>
        
    <aura:set attribute="else">
         Sorry! You can not vote.
        <ui:button label="Cancel Vote"></ui:button>
        
    </aura:set>  
    
    </aura:if>
    
</aura:component>
Controller Code:
({
    getEligibility : function(component) {
        
        var vAge = component.find("age").get("v.value");
        
        if(vAge != null && vAge>=18){
            component.set("v.EligibleOrNot",true);
        }
        if(vAge!=null && vAge<18){
            component.set("v.EligibleOrNot",false);
        }
        
    }
})
I have created a custom object Student Master and whenever I am inserting a new record in Student Master, it has to check pan card number in another custom object "Black Listed Candidate" and if it is found then show  a warning message on the page that "PAN card is BlackListed" on Saving the record. This message needs to be shown in VisualForce page and then that page needs to be called in Custom object.
My VFP is getting called but message is not coming. Please help me for this.
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'
                    }
                    )

                    
                );
            });
    }
}