• Athira Venugopal
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 1
    Replies
Here is my entire code, I am working in Visual studio code 
I have created a custom object 'Price', having two custom look up fields (Project, Unit) and some other fields,. I am trying to insert values into this custom object, but the look up field values(Project, Unit) are not getting inserted, all other fields got inserted.

Html template
<template>
  <lightning-card>
          <p class="slds-var-p-horizontal_small">

            <lightning-input label="Date" name="datefld" type="date" value={fDate} onchange={handledChange} ></lightning-input>
            <lightning-input label="Enquirer" name="enquiry" type="textarea" value={enq} onchange={handledChange} ></lightning-input>
    <lightning-record-edit-form object-api-name="Price__c">
    <lightning-input-field field-name="Project__c" required onchange={projectChange}>
    </lightning-input-field>
    </lightning-record-edit-form>
    <lightning-record-edit-form object-api-name="Price__c">
        <lightning-input-field field-name="Unit__c"  onchange={unitChange}>
        </lightning-input-field>
        </lightning-record-edit-form>
    
    
   <lightning-input label="Unit Rate" name="rate" type="Double" value={rNumber} onchange={handledChange}></lightning-input>
    <lightning-input label="Additional cost" name="cost" type="Double" value={cNumber} onchange={handledChange}></lightning-input>
    <lightning-input label="Discount" name="dis" type="Double" value={dNumber} onchange={handledChange}></lightning-input>
    <lightning-input label="Agreement cost" name="agree" type="Double" value={aNumber} onchange={handledChange}></lightning-input>
    <lightning-input label="Remarks" name = "remark" type="textarea" value={resultsum} onchange={handledChange}></lightning-input> 
    
     <lightning-button label="Save" onclick={handleClick}></lightning-button>
    
    
           </p>
           </lightning-card>
</template>

JS
import { LightningElement ,api, wire, track} from 'lwc';

import newPrice from '@salesforce/apex/PriceFetch.newPrice';
export default class PriceScreen extends LightningElement {
    datefld;
    enquiry;
    projSelected;
    unitSelected;
    rate;
    cost;
    dis;
    agree;
    remark;
 
    handledChange(event){

        if(event.target.name==='datefld'){

            console.log('handle Change'+event.target.value);

            this.datefld = event.target.value;

        }
        else if(event.target.name==='enquiry'){

            console.log('handle Change'+event.target.value)

            this.enquiry = event.target.value;    
       }

        else if(event.target.name==='rate'){

            console.log('handle Change'+event.target.value)

            this.rate = event.target.value;    
       }
       else if(event.target.name==='cost'){

        console.log('handle Change'+event.target.value)

        this.cost = event.target.value;    

    }
    else if(event.target.name==='dis'){

        console.log('handle Change'+event.target.value)

        this.dis = event.target.value;    
        
   
    }
    else if(event.target.name==='agree'){

        console.log('handle Change'+event.target.value)

        this.agree = event.target.value;    

    }
    else if(event.target.name==='remark'){

        console.log('handle Change'+event.target.value)

        this.remark = event.target.value;    

    }
    }
    projectChange(event) {
        projSelected = event.detail;
    }
    unitChange(event) {
        unitSelected = event.detail;
    }
   handleClick(event) {
        newPrice({ entryDate: this.datefld, enqName : this.enquiry, proj:projSelected, unit:unitSelected,
             unitRate:this.rate, addtnlCost:this.cost, discount:this.dis, agreeCost:this.agree,rem:this.remark })

        .then(result => {

            this.result = result;
           if(this.result == 'true') {
               alert("SUCCESS");
           }
        })
        .catch(error => {
             this.error = error;
             alert("FAILURE" + error);
              //this.error = error;
        });
    }
}
PriceFetch.cls (Apex controler class)
public with sharing class PriceFetch {
  
 
    @AuraEnabled
    public static Boolean newPrice(Date entryDate, String enqName, Id proj, Id unit,Double unitRate,Double addtnlCost, Double discount,Double agreeCost, String rem ){
     
       Price__c price = new Price__c();
       price.Date__c = entryDate;
       price.Name = enqName;
       price.Project__c = proj;
       price.Unit__c = unit;
       price.Unit_Rate__c = unitRate;
       price.Additional_cost__c = addtnlCost;
       price.Discount__c = discount;
       price.Agreement_cost__c = agreeCost;
       price.Remarks__c = rem;
       try {
        insert price;
        return true;
           
       } catch (Exception e) {
           throw new AuraHandledException('exceptionText' + e.getMessage());
         
       }
      
    }
}


Is there any mistake in my code
 
I have used lightning data table for my custom object, no data got displayed in the table
html
<template>
    <h2> Project Datatable</h2>
    <template if:true={accList}>
        <lightning-datatable data={accList} columns={columns} key-field="Id">
        </lightning-datatable>
    </template>
    <template if:true={error}>
        {error}
    </template>
</template>

JS
import { LightningElement ,api, wire, track} from 'lwc';
import getAccountList from '@salesforce/apex/PriceFetch.getAccountList';
export default class PriceScreen extends LightningElement {
    @track columns = [{
           api: 'BuildingNo__c',
            label: 'BuildingNo',
            fieldName: 'BuildingNo',
            type: 'text',
            sortable: true
        },
        {   api:'Location__c',
            label: 'Location',
            fieldName: 'Location',
            type: 'text',
            sortable: true
        }
    
    ];
 
    @track error;
    @track accList ;
    @wire(getAccountList)
    wiredAccounts({
        error,
        data
    }) {
        if (data) {
            this.accList = data;
        } else if (error) {
            this.error = error;
        }
    }
}
PriceFetch.cls (Apex class)
public with sharing class PriceFetch {
    @AuraEnabled(cacheable=true)
    public static List<Project__c> getAccountList() {
        return [SELECT Id,BuildingNo__c, Location__c
            FROM Project__c];
    }
}
 An empty table is the output, Please helpme
Here is my visual force page and apex controller:
StudentDisplay.vfp

<apex:page Controller="StudentDetails" >
    <apex:form >
        <apex:pageBlock title="New Student">
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!stud.Name}"/>
                <apex:inputField value="{!stud.Class__c}"/>
                <apex:inputField value="{!stud.DOB__c}"/>
                <apex:inputField value="{!stud.Physics__c}"/>
                 <apex:inputField value="{!stud.Chemistry__c}"/>
                 <apex:inputField value="{!stud.Maths__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!addNewStudent}" value="Save"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

StudentDetails .apxc
public class StudentDetails {
 public StudentData__c stud { get; set; }

    // Here initialize the book object
    public StudentDetails() {
        stud = new StudentData__c();
    }

    public PageReference addNewStudent() { 
       
        insert stud; 
        return null; 
    }
}
ContactComponent.cmp
<aura:component controller ="ContactController " implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name = "conList" type = "Contact"></aura:attribute>
    <lightning:input type ="text" label = "First Name" value="{!v.conList.FirstName}" ></lightning:input>
     <lightning:input type ="text" label = "Last Name" value="{!v.conList.LastName}"></lightning:input>
     <lightning:input  type ="tel" label = "Phone" value="{!v.conList.Phone}"></lightning:input>
     <lightning:input type ="email" label = "Email"  value="{!v.conList.Email}" ></lightning:input>
     <lightning:button variant="brand" label="Create" onclick="{!c.handleClick}" class="slds-m-left_x-small"></lightning:button>
</aura:component>

ContactComponentController.js

({
    handleClick : function(component, event, helper) {
        
        console.log("HIIIIIII" + conlist);
        var action = component.get("c.createContact");
        action.setParams({
           ac : component.get("v.conList")
        });
        action.setCallback(this,function(response){
            if(response.getState() == 'SUCCESS') {
            alert("Updated successfully");
            
        }
        });
    $A.enqueueAction(action);
    }
})

ContactController.apxc

public class ContactController {
    @auraEnabled
    public static void createContact( Contact c) {
      
        insert c;
    }

}

Is there any mistake in my code
<template>
<lightning-tabset>
<lightning-tab label="Item One">
One Content !
</lightning-tab>
<lightning-tab label="Item Two" title="2nd tab extended title">
Two Content !
</lightning-tab>
<lightning-tab label="Item Three">
Three Content !
</lightning-tab>
</lightning-tabset>
</template>

I am deploying using VSCODE
public class AccountProcessor {
 
    public AccountProcessor() {
      
    }
    public static void countContacts() {
       
        Account acc = [Select Id, Name from Account where name = 'chandra'];
Contact[] con = [SELECT Id,FirstName,LastName FROM Contact where AccountId =:acc.Id];
        acc.Number_of_Contacts__c = con.size();
        update acc;
        
        
    }
}
I am trying to update the 'Number of contacts' field in Account object.
Tried to call the countContacts() from anonymous window, But this exception occurs
AccountProcessor.countContacts();
public class AccountProcessor {
 
    public AccountProcessor() {
      
    }
    public static void countContacts() {
       
        Account acc = [Select Id, Name from Account where name = 'chandra'];
Contact[] con = [SELECT Id,FirstName,LastName FROM Contact where AccountId =:acc.Id];
        acc.Number_of_Contacts__c = con.size();
        update acc;
        
        
    }
}
I am trying to update the 'Number of contacts' field in Account object.
Tried to call the countContacts() from anonymous window, But this exception occurs
AccountProcessor.countContacts();
public class AccountProcessor {
 
    public AccountProcessor() {
      
    }
    public static void countContacts() {
       
        Account acc = [Select Id, Name from Account where name = 'chandra'];
Contact[] con = [SELECT Id,FirstName,LastName FROM Contact where AccountId =:acc.Id];
        acc.Number_of_Contacts__c = con.size();
        update acc;
        
        
    }
}
I am trying to update the 'Number of contacts' field in Account object.
Tried to call the countContacts() from anonymous window, But this exception occurs
AccountProcessor.countContacts();