• Itay Shechter 10
  • NEWBIE
  • 20 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hi all,

I'm trying to do a simple record update using lwc that calls apex method and for some reason, the update is not working for me. 

can anyone tell me what I am don't wrong? 

LWC.js:
import { api, LightningElement, track, wire } from 'lwc';
import LightningAlert from 'lightning/alert';
import { getRecord } from 'lightning/uiRecordApi';
import FILESCONFIRMATION_FIELD from '@salesforce/schema/Contact.Files_Confirmation__c'
import updateContactFilesConfirmation from '@salesforce/apex/updateContact.updateContactFilesConfirmation'


export default class DriverFilesAlert extends LightningElement {
    filesConfirm
    @api recordId

    @wire(getRecord, { recordId: '$recordId', fields: [FILESCONFIRMATION_FIELD] })
    accountHandler({ data }) {
        if (data) {
            console.log(data)
            this.filesConfirm = data.fields.Files_Confirmation__c.value
        }
    }

    updateHandler(){
        console.log('updateHandler')
        updateContactFilesConfirmation({contactId:this.recordId})
    }


}

LWC.html:
<template>
    <template if:true={recordId}>
        <lightning-button label="Click" onclick={updateHandler}></lightning-button>
    </template>
</template>

APEX:
public class updateContact {
    @AuraEnabled(cacheable=true)
    public static void updateContactFilesConfirmation(String contactId){
        system.debug('Im at the @updateContactFilesConfirmation@ funcation');
        Contact con = [SELECT Id FROM Contact WHERE Id =: contactId];
        con.LastName = 'test';
        try {
            system.debug('------Try to update----' + con.Id);
            update con;
        } catch (Exception e) {
            system.debug('------Error----');
        }
    }
}

So when I go to the logs that's what I see:
User-added image
And the contact was not updated at all...

Thanks
Hello!

I'm trying to get the values from some account fields that are related to an opportunity. I'm not sure why I was able to get the account name but not the custom fields...What am I doing wrong? 

I would appreciate your help

This one is working fine:
import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
import LightningAlert from 'lightning/alert';
import ACCOUNTNAME_FIELD from '@salesforce/schema/Opportunity.Account.Name'
import VALIDATEADDRESS_FIELD from '@salesforce/schema/Opportunity.Account.Address_Verified__c'
import ACCOUNTMANAGERFORGETT_FIELD from '@salesforce/schema/Opportunity.Account.Account_Manager_for_GT__c'
import VATNUMBER_FIELD from '@salesforce/schema/Opportunity.Account.Company_Id__c'
import PRIMARYCONTACT_FIELD from '@salesforce/schema/Opportunity.Account.Primary_Contact__c'
import FINANCECONTACT_FIELD from '@salesforce/schema/Opportunity.Account.Finance_Contact__c'
import LEGALCOMPANYNAME_FIELD from '@salesforce/schema/Opportunity.Account.Legal_Company_Name__c'
import PAYMENTMETHOD_FIELD from '@salesforce/schema/Opportunity.Account.Payment_Method__c'
import PAYMENTTERM_FIELD from '@salesforce/schema/Opportunity.Account.Payment_Term__c'
import ACCOUNTID_FIELD from '@salesforce/schema/Opportunity.AccountId'
export default class CompanyCreationAlerts extends LightningElement {
    accRecordId
    @api recordId

    
    @wire(getRecord, { recordId: '$recordId', fields: [ACCOUNTNAME_FIELD]})
    oppHandler({ data, error }) {
        if (data) {
            console.log(data)
        }
        if (error) {
            console.error(error)
        }
    }
}

This one is not working:
import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
import LightningAlert from 'lightning/alert';
import VALIDATEADDRESS_FIELD from '@salesforce/schema/Opportunity.Account.Address_Verified__c'
import ACCOUNTMANAGERFORGETT_FIELD from '@salesforce/schema/Opportunity.Account.Account_Manager_for_GT__c'
import VATNUMBER_FIELD from '@salesforce/schema/Opportunity.Account.Company_Id__c'
import PRIMARYCONTACT_FIELD from '@salesforce/schema/Opportunity.Account.Primary_Contact__c'
import FINANCECONTACT_FIELD from '@salesforce/schema/Opportunity.Account.Finance_Contact__c'
import LEGALCOMPANYNAME_FIELD from '@salesforce/schema/Opportunity.Account.Legal_Company_Name__c'
import PAYMENTMETHOD_FIELD from '@salesforce/schema/Opportunity.Account.Payment_Method__c'
import PAYMENTTERM_FIELD from '@salesforce/schema/Opportunity.Account.Payment_Term__c'
import ACCOUNTID_FIELD from '@salesforce/schema/Opportunity.AccountId'
export default class CompanyCreationAlerts extends LightningElement {
    accRecordId
    @api recordId

    
    @wire(getRecord, { recordId: '$recordId', fields: [ACCOUNTID_FIELD,VALIDATEADDRESS_FIELD,ACCOUNTMANAGERFORGETT_FIELD,
        VATNUMBER_FIELD, PRIMARYCONTACT_FIELD,FINANCECONTACT_FIELD, LEGALCOMPANYNAME_FIELD,PAYMENTMETHOD_FIELD, PAYMENTTERM_FIELD]})
    oppHandler({ data, error }) {
        if (data) {
            console.log(data)
        }
        if (error) {
            console.error(error)
        }
    }
}



 
Hi, I'm trying to use a standardcontroller in the Visualforce page in order to use it in a custom button. But I'm having this error:
Unknown constructor 'CarController.CarController(ApexPages.StandardController controller)'
I believe that I need to add something to the controller, but I could not find a solution that worked for me(I tried all the solutions that I found online)...

So, this is the code:
<apex:page  standardController="Case" extensions="CarController" lightningStylesheets="true" title="test">
    <apex:form>
        <apex:pageMessages/>
        <apex:pageBlock >    
            <apex:pageBlockSection columns="2">
                <apex:inputField value="{!abc.Name__c}"/> 
                <apex:inputField value="{!abc.License_Number__c}"/>
                <apex:inputField value="{!abc.Manufacturer__c}"/>
            </apex:pageBlockSection>
            
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!save}" styleClass="slds-button slds-button_brand"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
public class CarController{

    public Car__c abc {Get;Set;}

    public CarController() {     
        abc = new Car__c();
    }
    
    public PageReference save(){
    	try{
        	INSERT abc;
        }
        catch (exception e){
            
        }
        return null;
    }
    
}
P.S. I'm not a developer, just try to learn in order to get there one day... so I'll be happy to understand what is missing.

Thanks!



 
Hi all,

I'm trying to do a simple record update using lwc that calls apex method and for some reason, the update is not working for me. 

can anyone tell me what I am don't wrong? 

LWC.js:
import { api, LightningElement, track, wire } from 'lwc';
import LightningAlert from 'lightning/alert';
import { getRecord } from 'lightning/uiRecordApi';
import FILESCONFIRMATION_FIELD from '@salesforce/schema/Contact.Files_Confirmation__c'
import updateContactFilesConfirmation from '@salesforce/apex/updateContact.updateContactFilesConfirmation'


export default class DriverFilesAlert extends LightningElement {
    filesConfirm
    @api recordId

    @wire(getRecord, { recordId: '$recordId', fields: [FILESCONFIRMATION_FIELD] })
    accountHandler({ data }) {
        if (data) {
            console.log(data)
            this.filesConfirm = data.fields.Files_Confirmation__c.value
        }
    }

    updateHandler(){
        console.log('updateHandler')
        updateContactFilesConfirmation({contactId:this.recordId})
    }


}

LWC.html:
<template>
    <template if:true={recordId}>
        <lightning-button label="Click" onclick={updateHandler}></lightning-button>
    </template>
</template>

APEX:
public class updateContact {
    @AuraEnabled(cacheable=true)
    public static void updateContactFilesConfirmation(String contactId){
        system.debug('Im at the @updateContactFilesConfirmation@ funcation');
        Contact con = [SELECT Id FROM Contact WHERE Id =: contactId];
        con.LastName = 'test';
        try {
            system.debug('------Try to update----' + con.Id);
            update con;
        } catch (Exception e) {
            system.debug('------Error----');
        }
    }
}

So when I go to the logs that's what I see:
User-added image
And the contact was not updated at all...

Thanks
Hi, I'm trying to use a standardcontroller in the Visualforce page in order to use it in a custom button. But I'm having this error:
Unknown constructor 'CarController.CarController(ApexPages.StandardController controller)'
I believe that I need to add something to the controller, but I could not find a solution that worked for me(I tried all the solutions that I found online)...

So, this is the code:
<apex:page  standardController="Case" extensions="CarController" lightningStylesheets="true" title="test">
    <apex:form>
        <apex:pageMessages/>
        <apex:pageBlock >    
            <apex:pageBlockSection columns="2">
                <apex:inputField value="{!abc.Name__c}"/> 
                <apex:inputField value="{!abc.License_Number__c}"/>
                <apex:inputField value="{!abc.Manufacturer__c}"/>
            </apex:pageBlockSection>
            
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!save}" styleClass="slds-button slds-button_brand"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
public class CarController{

    public Car__c abc {Get;Set;}

    public CarController() {     
        abc = new Car__c();
    }
    
    public PageReference save(){
    	try{
        	INSERT abc;
        }
        catch (exception e){
            
        }
        return null;
    }
    
}
P.S. I'm not a developer, just try to learn in order to get there one day... so I'll be happy to understand what is missing.

Thanks!