• RAJAT MESHRAM
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
I try to build my own LWC Datatable component on Work Order object - which will show related Work Order Line Items records. The table is empty. How to retrieve the records into my LWC?
Here is my code:
woliDatatableDemo.html
<template>
    <lightning-card title="NEW Work Order Line Item" icon-name="custom:custom63">
            <div style="width: auto;">
                    <lightning-datatable
                        key-field="Id"
                        data={data}
                        columns={columns}
                        ></lightning-datatable>
                     </div>
        </lightning-card>
    </template>

woliDatatableDemo.js
import { LightningElement, api, track, wire } from "lwc";
import getWOLIs from '@salesforce/apex/woliControllerDatatable.getWOLIs';

const columns = [
    {
        label: 'Device', fieldName: 'AssetId'
    },

    { label: 'Serial No.', fieldName: 'Serial_No__c'},

    { label: 'Product', fieldName: 'PricebookEntryId'},

    { label: 'Quantity', fieldName: 'Quantity'},

    { label: 'List Price', fieldName: 'ListPrice'},

    { label: 'Discount', fieldName: 'Discount'},

    { label: 'Total Price', fieldName: 'TotalPrice'},
    
];

export default class WoliDatatableDemo extends LightningElement {

    @api recordId;
    @track data = [];
    @track columns = columns;
    
  
    @wire(getWOLIs, { woid: "$recordId" })
    
    wiredRecordsMethod({ data, error }) {
    if (data) {
       let result = JSON.parse(JSON.stringify(data));
        this.data = result.map(function(item) {
          return item;
        })
      this.error = undefined;
    } else if (error) {
      this.error = error;
      this.data = undefined;
    }
}
}

woliControllerDatatable.cls
public with sharing class woliControllerDatatable {

    @AuraEnabled(cacheable=true)
    public static List<WorkOrderLineItem> getWOLIs(String woId) {
        return [
            SELECT Quantity, PricebookEntryId, Serial_No__c, TotalPrice, WorkOrder.WorkOrderNumber, Work_Order_No__c,
                     Duration, ListPrice, Discount, WorkOrderId, Parent_WOLI__c, AssetId
            FROM WorkOrderLineItem
            WHERE Parent_WOLI__c = false AND WorkOrderId = :woId
            WITH SECURITY_ENFORCED
        ];}
}

 
  • September 14, 2022
  • Like
  • 0
public class Claim_Property_from_Sales_Region {

    public contact con {get;set;}
  
    public PageReference Cancel() {
    PageReference prf = new PageReference('https://ap8.salesforce.com/a0H/o');
        return prf;
    }


    public PageReference claimAndCountinue() {
    updateSearchItemsMap();
    SetStatusWorking();
        return null;
    }

    public void SetStatusWorking(){
     List<Property__c> pt = new List<Property__c>();
      set<id> idSet = mapHoldingSelectedRecords.keySet();
     List<Property__c> prplist = [Select id,Status__c from Property__c where id in : idSet];
        for(Property__c prp : prplist){
        Property__c property = new Property__c();
        property.id =  prp.id;
     //   property.Agent__c = UserInfo.getUserId();
        property.Status__c  = 'Working';
        pt.add(property);
        update pt;
        }
}
     
    
    public PageReference claimProp() {
    updateSearchItemsMap();
    SetStatusWorking();
    PageReference pf = new PageReference('https://ap8.salesforce.com/a0H/o');
        return pf;
    }


    public Claim_Property_from_Sales_Region() {
     mapHoldingSelectedRecords = new Map<Id, WrapperClass>();
     init();
    }

   
   Public Integer size{get;set;}
 Public Integer noOfRecords{get; set;}
 public List <WrapperClass> wrapperRecordList{get;set;}
 Map<Id, WrapperClass> mapHoldingSelectedRecords{get;set;}
 
 
 public void init() {
 wrapperRecordList = new List<WrapperClass>();
 for (Property__c p : (List<Property__c>)setCon.getRecords()) {
 if(mapHoldingSelectedRecords != null && mapHoldingSelectedRecords.containsKey(p.id)){
 wrapperRecordList.add(mapHoldingSelectedRecords.get(p.id));
 
 }
 else{
   wrapperRecordList.add(new WrapperClass(p, false));
 }
 }
 } 
 
   public ApexPages.StandardSetController setCon {
 get {
 if(setCon == null) {
   setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT id, Property_Name__c,Property_City__c, Listing_Price__c, Status__c,createdDate FROM Property__c where Status__c = 'open']));
   setCon.setPageSize(5);
 }
   return setCon;
 }
 set;
 }
 public Boolean hasNext {
 get {
   return setCon.getHasNext();
 }
 set;
 }
 
 public Boolean hasPrevious {
 get {
   return setCon.getHasPrevious();
 }
 set;
 }
 
 public Integer pageNumber {
 get {
   return setCon.getPageNumber();
 }
 set;
 }
   Public Integer getTotalPages(){
     Decimal totalSize = setCon.getResultSize();
     Decimal pageSize = setCon.getPageSize();
     Decimal pages = totalSize/pageSize;
     return (Integer)pages.round(System.RoundingMode.CEILING);
 }
 
 public void first() {
   updateSearchItemsMap();
   setCon.first();
   init();
 }
 
 public void last() {
   updateSearchItemsMap();
   setCon.last();
   init();
 }
 public void previous() {
   updateSearchItemsMap();
   setCon.previous();
   init();
 }
 
 public void next() {
   updateSearchItemsMap();
   setCon.next();
   init();
 }

 private void updateSearchItemsMap() {
 for(WrapperClass wrp : wrapperRecordList){
  if(wrp.isSelected){
     mapHoldingSelectedRecords.put(wrp.prop.id, wrp);
  }
  if(wrp.isSelected == false && mapHoldingSelectedRecords.containsKey(wrp.prop.id)){
     mapHoldingSelectedRecords.remove(wrp.prop.id);
  }
 }
 }
 public class WrapperClass {
 public Boolean isSelected {get;set;}
 public Property__c prop {get;set;}
 public WrapperClass(Property__c prop, Boolean isSelected) {
    this.prop = prop;
    this.isSelected = isSelected;
 }
 }
}

 
Hi all,

I want to write a validation rule where picklist value country is US the phone number should display with country code +1 and Australia +61 and India  is +91 
 I have tried this 

ISPICKVAL( Country__c , "UK")  

AND(NOT(ISBLANK(Phone_c)),
NOT(REGEX(Phone,"[+44]{3}[1-9]{1}[0-9]{9}"))

 
ISPICKVAL( Country__c , "USA")  
 AND(NOT(ISBLANK(Phone_c)),
NOT(REGEX(Phone,"[+1]{2}[1-9]{1}[0-9]{9}"))

ISPICKVAL( Country__c , "India")  
 
AND( NOT(ISBLANK(Phone_c)),
NOT(REGEX(Phone,"[+91]{3}[1-9]{1}[0-9]{9}"))

ISPICKVAL( Country__c , "Australia")  
 AND(NOT(ISBLANK(Phone_c)),
NOT(REGEX(Phone,"[+61]{3}[1-9]{1}[0-9]{9}"))

)

Thank you in advance 
sheeba