• ifthikar Ahmed 1
  • NEWBIE
  • 130 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 27
    Questions
  • 15
    Replies
Lightning Data Table issue :

i have a LWC component on Inquiry Obj (Parent) which is having look up relation with the child (Relavent Proprties).
My component will display all the child records of the parent obj with inline edit functionality.
Also i have "create relavent Proprty" standerd quick action button that craetes a New relevent Prop record.

Problem is that , when a new record is created from quick action button . my data table is not getting refreshed. data table shuld show all the values in the Db. why so 

Please help 

JavaScript : 
import { LightningElement, wire, api,track  } from 'lwc';
import getRelProp from '@salesforce/apex/selectRelPropController.getRelProp';
import { refreshApex } from '@salesforce/apex';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import updateRelProp from '@salesforce/apex/selectRelPropController.updateRelProp';
import { getRecordNotifyChange } from 'lightning/uiRecordApi';
const COLS = [
    { label: 'SL.No', 
    fieldName: "recordLink", 
    type: 'url',
    typeAttributes: { label: { fieldName: "Name" }, tooltip:"Relavent Property", target: "_blank" }
    
    },
    { label: 'Property Name',
     fieldName: 'recordLinkProp',
     type: 'url',
     typeAttributes: { label: { fieldName: "PropertyRel" }, tooltip:"Property", target: "_blank" }
    
    },
    { label: 'Price', fieldName: 'Price__c' ,  type: 'currency' },
    { label: 'Created Date', fieldName: 'CreatedDate' , type: 'date' },
    { label: 'Include this in PDF', fieldName: 'Include_This_in_PDF__c' , editable: true, type: 'boolean' }
    
    
];


export default class DatatableUpdate extends LightningElement {
    @api recordId;
    columns = COLS;
    draftValues = [];
    @track wiredPropList = [];
    error;  
    @track relList = [];
    
      @wire(getRelProp, { accId: '$recordId' })
    getRelPropList(result) { 
        this.wiredPropList = result;
     if (result.data) { 
         
        console.log(result.data.length);
      var temprelList = [];  
      for (var i = 0; i < result.data.length; i++) {  
       let tempRecord = Object.assign({}, result.data[i]); //cloning object  
       tempRecord.recordLink = "/" + tempRecord.Id;       
       tempRecord.PropertyRel =  tempRecord.Property__r.Name;
       tempRecord.recordLinkProp = "/" + tempRecord.Id;       
       temprelList.push(tempRecord); 
       console.log(temprelList) ;
      }  
      this.relList = temprelList;  
      this.error = undefined;  
     } else if (result.error) {  
      this.error = error;  
      this.relList = undefined;  
     }  
    }
     
    async handleSave(event) {
        const updatedFields = event.detail.draftValues;
        console.log("chk1" +JSON.stringify(updatedFields));
        // Prepare the record IDs for getRecordNotifyChange()
        const notifyChangeIds = updatedFields.map(row => { return { "recordId": row.Id } });
        console.log("chk2" +JSON.stringify(notifyChangeIds));
    
       // Pass edited fields to the updateContacts Apex controller
        await updateRelProp({data: updatedFields})
        .then(result => {
            console.log(JSON.stringify("Apex update result: "+ result));
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Included for PDF Generation',
                    variant: 'success'
                })
            );
    
        // Refresh LDS cache and wires
        getRecordNotifyChange(notifyChangeIds);
    
        // Display fresh data in the datatable
        refreshApex(this.wiredPropList).then(() => {
            // Clear all draft values in the datatable
            console.log();
            this.draftValues = [];
          });
    
        
       })
        .catch(error => {
         this.dispatchEvent(
              new ShowToastEvent({
                  title: 'Error updating or refreshing records',
                  message: error.body.message,
                  variant: 'error'
              })
          );
      });
       
    }
}

Component : 

<template>
    <lightning-card title="Relevant Properties" icon-name="custom:custom63">
    
       
     <div > 
        <template if:true={relList}>
            <lightning-datatable
                key-field="Id"
                data={relList}
                columns={columns}
                onsave={handleSave}
                show-row-number-column
                draft-values={draftValues}>
            </lightning-datatable>  
        </template>
        
        <template if:true={relList.error}>
            <!-- handle Apex error -->
        </template>
    </div>
        
    </lightning-card>
    </template>

User-added image

apex controller : 

public with sharing class selectRelPropController {
    
    @AuraEnabled(cacheable=true)
    public static List<Relevant_Property__c> getRelProp(String accId) {
        
        return [
            SELECT Id, Name, Property__r.Name , Property__c, Price__c , Include_This_in_PDF__c ,CreatedDate 
            FROM Relevant_Property__c
            WHERE Inquiry__c  = :accId
            WITH SECURITY_ENFORCED
        ];
    }
    
    @AuraEnabled
    public static string updateRelProp(Object data) {
        List<Relevant_Property__c> relPropRecForUpdate = (List<Relevant_Property__c>) JSON.deserialize(
            JSON.serialize(data),
            List<Relevant_Property__c>.class
        );
        try {
            system.debug('Records' +relPropRecForUpdate);
            update relPropRecForUpdate;
            return 'Success: pls click on Generate PDF Button to generate the Document';
        }
        catch (Exception e) {
            return 'The following exception has occurred: ' + e.getMessage();
        }}
}

pls helpppppppppp
error : 
Challenge Not yet complete... here's what's wrong:
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Approval for deal more than $ 100K is must: []
Close errors


1.Validation rules :
User-added image
2.Approval process :

User-added imageUser-added imageUser-added image3.Process builder :

screet shot attached in next post

 
can a soql query return Boolean and string value ?
i am new to salesforce getting parssing error what is wrongwith my query 

select id,name (select id, name from Contacts) from Account where Name ='test6'
What are two uses of External IDS? Choose 2 answers
  1. To prevent an import from creating duplicate records using Upsert
  2. To identify the sObject type in Salesforce
  3. To create a record in a development environment with the same salesforce ID as in another environment
  4. To create relationships between records imported from an external system.
i am new and can some explain when to use DescribeFieldResult ,  DescribeSObjectResult ,Schema.SObjectType 
Hi I am trying to create a contact related record when a new account is created

trigger Createcontact on Account (before insert) {  
List<Contact> contactList=new List<Contact>();
    for (Account a : Trigger.new) {
    Contact c=new Contact();
    c.firstName=a.Name;
    c.lastName=a.Name;  
    contactList.add(c);
        // Iterate over each sObject
    }
  insert contactList;
}

the above trigger creates a new contact where in i want the contact to be related to the respective account
can we use trigger.old in after insert event ???

More over, my code is to create a new invoice record when the "active checbox" is selected true in the coustomer obj and the old value shuld be unchecked. event has to update evvent where in my trigger works fine in  after Insert how come pls explain

trigger test1 on Apex_Customer__c (after Insert) {
   list <APEX_Invoice__c> upinv = new list <APEX_Invoice__c>();
   for(Apex_Customer__c newcus : trigger.new)
   {
       
       
       if(newcus.APEX_Active__c == True && trigger.oldmap.get(newcus.id).APEX_Active__c != True )
       {
           APEX_Invoice__c newinv = new APEX_Invoice__c();
           newinv.APEX_Customer__c = newcus.Id;
           upinv.add(newinv);
       }
   }
insert upinv;
}
Lightning Data Table issue :

i have a LWC component on Inquiry Obj (Parent) which is having look up relation with the child (Relavent Proprties).
My component will display all the child records of the parent obj with inline edit functionality.
Also i have "create relavent Proprty" standerd quick action button that craetes a New relevent Prop record.

Problem is that , when a new record is created from quick action button . my data table is not getting refreshed. data table shuld show all the values in the Db. why so 

Please help 

JavaScript : 
import { LightningElement, wire, api,track  } from 'lwc';
import getRelProp from '@salesforce/apex/selectRelPropController.getRelProp';
import { refreshApex } from '@salesforce/apex';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import updateRelProp from '@salesforce/apex/selectRelPropController.updateRelProp';
import { getRecordNotifyChange } from 'lightning/uiRecordApi';
const COLS = [
    { label: 'SL.No', 
    fieldName: "recordLink", 
    type: 'url',
    typeAttributes: { label: { fieldName: "Name" }, tooltip:"Relavent Property", target: "_blank" }
    
    },
    { label: 'Property Name',
     fieldName: 'recordLinkProp',
     type: 'url',
     typeAttributes: { label: { fieldName: "PropertyRel" }, tooltip:"Property", target: "_blank" }
    
    },
    { label: 'Price', fieldName: 'Price__c' ,  type: 'currency' },
    { label: 'Created Date', fieldName: 'CreatedDate' , type: 'date' },
    { label: 'Include this in PDF', fieldName: 'Include_This_in_PDF__c' , editable: true, type: 'boolean' }
    
    
];


export default class DatatableUpdate extends LightningElement {
    @api recordId;
    columns = COLS;
    draftValues = [];
    @track wiredPropList = [];
    error;  
    @track relList = [];
    
      @wire(getRelProp, { accId: '$recordId' })
    getRelPropList(result) { 
        this.wiredPropList = result;
     if (result.data) { 
         
        console.log(result.data.length);
      var temprelList = [];  
      for (var i = 0; i < result.data.length; i++) {  
       let tempRecord = Object.assign({}, result.data[i]); //cloning object  
       tempRecord.recordLink = "/" + tempRecord.Id;       
       tempRecord.PropertyRel =  tempRecord.Property__r.Name;
       tempRecord.recordLinkProp = "/" + tempRecord.Id;       
       temprelList.push(tempRecord); 
       console.log(temprelList) ;
      }  
      this.relList = temprelList;  
      this.error = undefined;  
     } else if (result.error) {  
      this.error = error;  
      this.relList = undefined;  
     }  
    }
     
    async handleSave(event) {
        const updatedFields = event.detail.draftValues;
        console.log("chk1" +JSON.stringify(updatedFields));
        // Prepare the record IDs for getRecordNotifyChange()
        const notifyChangeIds = updatedFields.map(row => { return { "recordId": row.Id } });
        console.log("chk2" +JSON.stringify(notifyChangeIds));
    
       // Pass edited fields to the updateContacts Apex controller
        await updateRelProp({data: updatedFields})
        .then(result => {
            console.log(JSON.stringify("Apex update result: "+ result));
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Included for PDF Generation',
                    variant: 'success'
                })
            );
    
        // Refresh LDS cache and wires
        getRecordNotifyChange(notifyChangeIds);
    
        // Display fresh data in the datatable
        refreshApex(this.wiredPropList).then(() => {
            // Clear all draft values in the datatable
            console.log();
            this.draftValues = [];
          });
    
        
       })
        .catch(error => {
         this.dispatchEvent(
              new ShowToastEvent({
                  title: 'Error updating or refreshing records',
                  message: error.body.message,
                  variant: 'error'
              })
          );
      });
       
    }
}

Component : 

<template>
    <lightning-card title="Relevant Properties" icon-name="custom:custom63">
    
       
     <div > 
        <template if:true={relList}>
            <lightning-datatable
                key-field="Id"
                data={relList}
                columns={columns}
                onsave={handleSave}
                show-row-number-column
                draft-values={draftValues}>
            </lightning-datatable>  
        </template>
        
        <template if:true={relList.error}>
            <!-- handle Apex error -->
        </template>
    </div>
        
    </lightning-card>
    </template>

User-added image

apex controller : 

public with sharing class selectRelPropController {
    
    @AuraEnabled(cacheable=true)
    public static List<Relevant_Property__c> getRelProp(String accId) {
        
        return [
            SELECT Id, Name, Property__r.Name , Property__c, Price__c , Include_This_in_PDF__c ,CreatedDate 
            FROM Relevant_Property__c
            WHERE Inquiry__c  = :accId
            WITH SECURITY_ENFORCED
        ];
    }
    
    @AuraEnabled
    public static string updateRelProp(Object data) {
        List<Relevant_Property__c> relPropRecForUpdate = (List<Relevant_Property__c>) JSON.deserialize(
            JSON.serialize(data),
            List<Relevant_Property__c>.class
        );
        try {
            system.debug('Records' +relPropRecForUpdate);
            update relPropRecForUpdate;
            return 'Success: pls click on Generate PDF Button to generate the Document';
        }
        catch (Exception e) {
            return 'The following exception has occurred: ' + e.getMessage();
        }}
}

pls helpppppppppp
error : 
Challenge Not yet complete... here's what's wrong:
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Approval for deal more than $ 100K is must: []
Close errors


1.Validation rules :
User-added image
2.Approval process :

User-added imageUser-added imageUser-added image3.Process builder :

screet shot attached in next post

 
can a soql query return Boolean and string value ?
Hi I am trying to create a contact related record when a new account is created

trigger Createcontact on Account (before insert) {  
List<Contact> contactList=new List<Contact>();
    for (Account a : Trigger.new) {
    Contact c=new Contact();
    c.firstName=a.Name;
    c.lastName=a.Name;  
    contactList.add(c);
        // Iterate over each sObject
    }
  insert contactList;
}

the above trigger creates a new contact where in i want the contact to be related to the respective account

Additionally, if you update or delete a record in its before trigger, or delete a record in its after trigger, you will receive a runtime error. This includes both direct and indirect operations. For example, if you update account A, and the before update trigger of account A inserts contact B, and the after insert trigger of contact B queries for account A and updates it using the DML update statement or database method, then you are indirectly updating account A in its before trigger, and you will receive a runtime error.

can some one help me understan with an example pls
Hi..
i am new to salesforce ,

in visual force , while using controller to get the object fields from an object 2 typs of methods are used 
1.
public Account getAccount() {
       return account; 
  }

2.
public Account account { get; private set; }
does they both do the same job and which place we hv to go with the 1st method and for which place do we have to go with 2nd  , pls explain
 
I am working on the App Customization Specialist Superbadge and this one has me baffled. Here is the part I'm stuck on...

Quick Self Sign Up
Maria asked for a quick way for users to sign themselves up for a Shift directly from a Volunteer Shift record. Your solution was an action with the label Sign Me Up. To keep it simple there should be no fields on the pop-up. Instead the action automatically sets the Volunteer to the user clicking the button, changes the status to Confirmed, and assigns the currently viewed Shift as the new record's Volunteer Shift. Once the action is done show the friendly message "Congratulations, you are signed up!".

Based on what I'm reading, they seem to be asking me to create a Quick Action button that creates a new record with the necessary fields set to default values. The problem is that two of the fields that are required are Lookups that I was required to create in the first challenge. One to supply the User Name and another to supply the Volunteer Shift Name. Quick Action default values can't populate Lookup fields, right? I tried creating a flow, but you can't trigger an autolaunched flow from a Quick Action, only Screen Flows. The challenge wants one button click and it's done. Can someone tell me what I'm missing here?