• CBBsfdc
  • NEWBIE
  • 100 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 17
    Questions
  • 2
    Replies
Hello!
I'm trying to import a third-party js library in order to display a datatable.
https://datatables.net/examples/data_sources/js_array.html

I managed to import jQuery and DataTable js using import and static resources but when I try to translate the documentation sentence :
$('#example').DataTable()

into what a LWC accepts it doesn't work:
this.template.querySelector('table.example').DataTable();

Please find hereby my code:
filteredTable.html
<template>
    <lightning-card title="OST Events">
        <lightning-layout>
            <lightning-layout-item>
                    <table id="table_id" class="example">
                        <thead>
                            <tr>
                                <th>Column 1</th>
                                <th>Column 2</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>Row 1 Data 1</td>
                                <td>Row 1 Data 2</td>
                            </tr>
                            <tr>
                                <td>Row 2 Data 1</td>
                                <td>Row 2 Data 2</td>
                            </tr>
                        </tbody>
                    </table>
                <template if:true={error}>
                    <c-error-panel errors={error}></c-error-panel>
                </template>
            </lightning-layout-item>
        </lightning-layout>
    </lightning-card>
</template>

filteredTable.js
import { LightningElement, track } from 'lwc';
import { loadScript } from 'lightning/platformResourceLoader';
import DATATABLE from '@salesforce/resourceUrl/dataTablesv10_18';
import JQUERY from '@salesforce/resourceUrl/jQuery';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';

export default class FilteredTable extends LightningElement {
    DataTable;
    @track error;
    @track dataExample;

    dataTablejsInitialized = false;

    renderedCallback() {
        if (this.dataTablejsInitialized) {
            return;
        }
        this.dataTablejsInitialized = true;
        loadScript(this,JQUERY)
        .then(()=>{
            loadScript(this, DATATABLE+'/datatables.min.js')
        })
        .then(()=>{
            console.log("ENTRO EN EL .THEN DEL LOADSCRIPT");
            this.DataTable = this.template.querySelector('table.example').DataTable();
            })
            .catch(error => {
                this.error = error;
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error loading DataTables',
                        message: error.message,
                        variant: 'error'
                    })
                );
            });
    }

}

Is there an other way to call a function of an imported js library?

Thanks!
 
  • September 29, 2020
  • Like
  • 0
Hi all 

How to execute below code in anonymous window   
 
public class UserUpdate {
   public void updateUser(List<ID> ids){
        Id userId = ids.get(0);

        Profile prf = [select id from Profile where Name='Work.com Only User'];
        User usr = [select IsActive,UserRoleId,ProfileId,Title,CompanyName,CallCenterId,DelegatedApproverId,ManagerId from User where id=:userId];
        usr.UserRoleId = null;
        usr.ProfileId = prf.id;
        usr.Title = null;
        usr.CompanyName = null; 
        usr.CallCenterId = null;      
        usr.DelegatedApproverId = null;
        usr.ManagerId = null;
        usr.IsActive = false;
        update usr;
        
    }
    }
Anonymous code is 
 
List<Id> Ids = new List<Id>();
Ids.add(id);
UserUpdate.updateUser(Ids);

kindly Support and Suggest

Thanks ​​​​​​​
Hi all, 

I want to display Whenever Contacts are inserted, updated, deleted, and undeleted then Count should get rolled-up on Accounts.
 for this I had created a check box field like contact_roll_c and in contact field and number field like No_Of_Active_Contacts__c in Account object 

trigger updateAccount on Account (before Update) {

List<Contact> Contactlist=[select id,name,phone,accountid from contact where accountID In :trigger.new ];
map<id,integer> countMap=new map<id,integer>();
integer i=1;
for(contact c:contactlist)
{
       if(countmap.containskey(c.accountid))
       {
           i=countmap.get(c.accountid)+1;
           countmap.put(c.accountid,i);
       }
       else
       {
              countMap.put(c.accountid,i);
       }
}

for(account a:trigger.new)
{
try{
        if(countmap.containskey(a.id))
            a.Contact_Count__c=countMap.get(a.id);
   }
   catch(exception e)
   {
  
   }
}
}


Kindly support and suggest.

Thanks
 if it was possible to add a filter to the contact lookup fields in an opportunity, task, etc which are related to an account, to only show the contacts that are related to the chosen account.
UK in Billing Country or Shipping Country should get updated to United Kingdom.
US or USA in Billing Country or Shipping Country should get updated to United States