Posts

Showing Apex Error on UI for Lightning WebComponents(lwc)

Image
 Template: <template>      <lightning-card   title = "Showing error From Apex" >          <lightning-button   label = "Get Contacts"   onclick = {handleGetContacts} ></lightning-button>                   <template   if:true = {error} >              <c-error-panel   errors = {error} ></c-error-panel>          </template>      </lightning-card> </template> Js:      import  {  LightningElement , wire  }  from   'lwc' ; //importing from apex import  srchval  from   '@salesforce/apex/showErrorMsg.showError' ; export default   class   ShowErrorfromApex ...

ToastMessage

 showInfoToast : function(component, event, helper) {         var toastEvent = $A.get("e.force:showToast");         toastEvent.setParams({             title : 'Info Message',             message: 'Mode is dismissible ,duration is 5sec and this is normal Message',             messageTemplate: 'Record {0} created! See it {1}!',             duration:' 5000',             key: 'info_alt',             type: 'info',             mode: 'dismissible'         });         toastEvent.fire();     },     showSuccessToast : function(component, event, helper) {         var toastEvent = $A.get("e.force:showToast");         toastEvent.setPar...

Comparing Two Values Using Aura If

<aura:application >     <aura:attribute name="items" type="List" default="[1,2,3]" />     <aura:attribute name="current" type="Integer" default="2" />     <aura:iteration items="{!v.items}" var="item">         <aura:if isTrue="{!v.current == item}">             <div>Current: {!item}</div>             <aura:set attribute="else">                 <div>Not Current: {!item}</div>             </aura:set>         </aura:if>     </aura:iteration> </aura:application> Output Not Current: 1 Current: 2 Not Current: 3

To find array index of complex

<aura:component >          <aura:handler name="render" value="{!this}" action="{!c.myAction}"/>     <aura:attribute name="objs" type="Object[]" /> </aura:component> ({ myAction : function(component, event, helper) { var studentsArray =      [     {     "rollnumber": 1,     "name": "dj",     "subject": "physics"    },    {    "rollnumber": 2,   "name": "tanmay",   "subject": "biology"    },   {    "rollnumber": 3,    "name": "amit",    "subject": "chemistry"    },                   ];            console.log('studentsArray'+JSON.stringify(studentsArray[0]));         console.log(studentsArray[0].rollnumber);   console.log(studentsArray[0].name...

javascript to search array of object

var studentsArray = [ { "rollnumber" : 1 , "name" : "dj" , "subject" : "physics" }, { "rollnumber" : 2 , "name" : "tanmay" , "subject" : "biology" }, { "rollnumber" : 3 , "name" : "amit" , "subject" : "chemistry" }, ]; function functiontofindIndexByKeyValue ( arraytosearch , key , valuetosearch ) { for ( var i = 0 ; i < arraytosearch . length ; i ++) { if ( arraytosearch [ i ][ key ] == valuetosearch ) { return i ; } } return null ; } var index = functiontofindIndexByKeyValue ( studentsArray , "name" , "tanmay" ); alert ( index ); function getIndex ( val ) { for ( var i = 0 ; i < imageList . length ; i ++) { if ( imageList [ i ] ...

Array to push element to array

mpex_app.app <aura:application extends="force:slds">   <c:mpex1></c:mpex1> </aura:application> CMP <aura:component>   <aura:attribute name="objs" type="Object[]" />   <aura:handler name="init" value="{!this}" action="{!c.doInit}" />   <table>     <tr>       <th>Product</th>       <th>Price</th>     </tr>     <aura:iteration items="{!v.objs}" var="obj">       <tr>         <td>{!obj.product}</td>         <td>{!obj.price}</td>       </tr>     </aura:iteration>   </table>   <!-- component B -->   <lightning:button variant="brand" label="Add another" title="Brand action" onclick="{! c.handleClick }" /> </aura:component> JS ({ ...

Multiple Checkboxex with default as true

toggle_smle_app.app <aura:application extends="force:slds">     <aura:attribute name="allaccounts" type="List" default="[ { BillingCity: 'Denver' }, { BillingCity: 'Ontario' }, { BillingCity: 'San Francisco' } ]" />     <aura:attribute name="selectedCities" type="List" default="[]" />     <aura:iteration var="a" items="{!v.allaccounts}" indexVar="indx">         <ui:inputCheckbox aura:id="checkbox"                           value="true" text="{!a.BillingCity}"                           name="{!indx}"                           label="{!a.BillingCity}"                           change="{!c.selectoptionvalue}"/>     </aura:iterat...