• Rushikesh Khandale
  • NEWBIE
  • 83 Points
  • Member since 2019

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 14
    Replies
Hi,
I had written code for 3 fileds (FirstName,LastName,PhysicalAttributes) for inserting record in Contact Object.It was successfully Saving Record.
But when i am trying to insert Record using FirstName and LastName i am getting error like

Error creating record
Upsert failed. First exception on row 0; first error: INVALID_TYPE_ON_FIELD_IN_RECORD, Physical Attributes: value not of required type: : [Physical_Attributes__c]
Close


Because while Inserting Records we can skip some Fields(i.e;Non-Mandatory)Fields.Can any one Plz suggest me.

Here is my code:

<template>
    <lightning-card title="Insert Contact" icon-name="standard:contact">
            <div class="slds-p-around_x-small">
                <lightning-input label="FirstName" value={rec.FirstName} onchange={handleFirstNameChange}></lightning-input>
                <lightning-input label="LastName" value={rec.LastName} onchange={handleLastNameChange}></lightning-input>
                <lightning-input type="text" label="PhysicalAttributes" value={rec.Physical_Attributes__c} onchange={handlePhysicalAttributesChange}></lightning-input><br/>
                <lightning-button label="Save" onclick={handleClick}></lightning-button>
            </div>
        </lightning-card>
</template>

import { LightningElement,track } from 'lwc';
import createContact from '@salesforce/apex/insertContactApexWeb.saveContactRecord';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import FIRSTNAME_FIELD from '@salesforce/schema/Contact.FirstName__c';
import LASTNAME_FIELD from '@salesforce/schema/Contact.LastName__c';
import PHYSICALATTRIBUTES_FIELD from '@salesforce/schema/Contact.Physical_Attributes__c';
export default class InsertContact extends LightningElement {
    @track firstname = FIRSTNAME_FIELD;
    @track lastname = LASTNAME_FIELD;
    @track physicalattributes = PHYSICALATTRIBUTES_FIELD;
   @track  rec = {
        FirstName : this.firstname,
        LastName : this.lastname,
        Physical_Attributes__c: this.physicalattributes
    }
    handleFirstNameChange(event) {
        this.rec.FirstName = event.target.value;
    }
    
    handleLastNameChange(event) {
        this.rec.LastName = event.target.value;
    }
    
    handlePhysicalAttributesChange(event) {
        this.rec.Physical_Attributes__c= event.target.value;
    }
    handleClick() {
        createContact({ con : this.rec })
       .then(result => {
            // Clear the user enter values
            this.rec = {};
            window.console.log('result ===> '+result);
            // Show success messsage
            this.dispatchEvent(new ShowToastEvent({
                title: 'Success!!',
                message: 'Contact Created Successfully!!',
                variant: 'success'
            }),);
        })
        .catch(error => {            
            this.error = error.message;
            window.console.log('error body--'+error.body.message);
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error creating record',
                    message: error.body.message,
                    variant: 'error',
                }),
            );
            window.console.log("error", JSON.stringify(this.error));
        });

    }
    
}


Apex Class:
public with sharing class insertContactApexWeb {
   
    @AuraEnabled
    public static void saveContactRecord(Contact con){
        System.debug('acc--'+con);
        try{
            insert con;
        }
        catch(Exception ex) {
            throw new AuraHandledException(ex.getMessage());
        }
    }
}

I'm using a datatable in a lightning (aura) component. Since the columns don't allow for notation to get the relationship_field__r.QualifiedApiName I am trying to flatten the data the way you would with a lookup field on an object (as referenced here: https://salesforce.stackexchange.com/questions/200761/parent-field-in-lightning-datatable)

However it is not working and my column is still displaying blank.

Has anyone had success with a similar requirement displaying custom metadata relationship field names in a datatable?

I am trying to build a quick action, when clicked, will check for the Status field. IF status != Closed, wil redirect to visualforce page. Below is my component and controller codes. 
CloseCase.cmp
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,flexipage:availableForAllPageTypes">
     <!-- This attribute saves the record ID -->
    <aura:attribute name="recordId" type="String" />
     <aura:attribute name="CaseObject" type="Object" /> 
    <aura:attribute type="Object" name="record"/>
 
    <aura:attribute name="CaseStatusValue" type = "String" /> -->
   

   <aura:attribute name="recordLoadError" type="String"/>

   <force:recordData aura:id="recordLoader"
   recordId="{!v.recordId}"
   fields="Name,Status"
   targetFields="{!v.CaseObject}"
   targetError="{!v.recordLoadError}"
   targetRecord="{!v.record}"                    
   />

    
    
    <!-- This executes a function from the controller as soon as the component is open. 
    This is recommended when the action only processes data and there’s no need for user interaction -->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>

CloseCaseController.js
({
    doInit : function(component, event, helper) {
        var Caseid = component.get("v.recordId");
        var CaseStatus = component.get("v.CaseObject").Status;
        console.log(CaseStatus);
        if(CaseStatus != "Closed"){     
        var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
        "url": "/apex/KBReviewClose?id="+Caseid+"",
        "width" : "700",
        "height" : "1000",
        "scrollbars" : "yes"
    });
        
    urlEvent.fire();
    }
        else{ 
                    var resultsToast = $A.get("e.force:showToast");
                    resultsToast.setParams({
                        "title" : "Failed",
                        "message" : "Case is already closed",
                        "type" : "warning",
                         "duration" : "60000ms"
                    });
                      resultsToast.fire();}
    }
})

On the controller side, I am trying to get the 'Status' value of the case record and redirecting to a visualforce page if status is not equal to 'Closed'.

I am getting the below error. please help.
Error while creating component for lightning component quick action [Action failed: c:LCC_Close_KB_Review_Case$controller$doInit [Cannot read property 'Status' of null]].
 
  • January 20, 2020
  • Like
  • 0
Hi, 

I have a need to change the prefix of the existing standard autonumber format that starts withn MP- TO CM- for specific record type Custom_Calendar_Marketing_Project While keeping the numeric format same {0000}. I have created the formula field that will display the auto-number in CM- format for the recordtype. 
 
IF(RecordType.Name = 'Custom_Calendar_Marketing_Project', 'CM-'+MID(Name, 4, 5),Name)
This is not working. :(

The datatype for the existing auto-number is currently on "Auto Number". What are the implications of when I change the data type to Text for autonumber for my formula to work? So, this formula only will work when I change the existing autonumber data type to text from autonumber? 

Is formula field is the best or should I use workflow to achieve this? 

I know lots of question. I need to drill on this down to make this work. 

Thank you, 
Natto
  • March 09, 2020
  • Like
  • 0
Hi,
I had written code for 3 fileds (FirstName,LastName,PhysicalAttributes) for inserting record in Contact Object.It was successfully Saving Record.
But when i am trying to insert Record using FirstName and LastName i am getting error like

Error creating record
Upsert failed. First exception on row 0; first error: INVALID_TYPE_ON_FIELD_IN_RECORD, Physical Attributes: value not of required type: : [Physical_Attributes__c]
Close


Because while Inserting Records we can skip some Fields(i.e;Non-Mandatory)Fields.Can any one Plz suggest me.

Here is my code:

<template>
    <lightning-card title="Insert Contact" icon-name="standard:contact">
            <div class="slds-p-around_x-small">
                <lightning-input label="FirstName" value={rec.FirstName} onchange={handleFirstNameChange}></lightning-input>
                <lightning-input label="LastName" value={rec.LastName} onchange={handleLastNameChange}></lightning-input>
                <lightning-input type="text" label="PhysicalAttributes" value={rec.Physical_Attributes__c} onchange={handlePhysicalAttributesChange}></lightning-input><br/>
                <lightning-button label="Save" onclick={handleClick}></lightning-button>
            </div>
        </lightning-card>
</template>

import { LightningElement,track } from 'lwc';
import createContact from '@salesforce/apex/insertContactApexWeb.saveContactRecord';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import FIRSTNAME_FIELD from '@salesforce/schema/Contact.FirstName__c';
import LASTNAME_FIELD from '@salesforce/schema/Contact.LastName__c';
import PHYSICALATTRIBUTES_FIELD from '@salesforce/schema/Contact.Physical_Attributes__c';
export default class InsertContact extends LightningElement {
    @track firstname = FIRSTNAME_FIELD;
    @track lastname = LASTNAME_FIELD;
    @track physicalattributes = PHYSICALATTRIBUTES_FIELD;
   @track  rec = {
        FirstName : this.firstname,
        LastName : this.lastname,
        Physical_Attributes__c: this.physicalattributes
    }
    handleFirstNameChange(event) {
        this.rec.FirstName = event.target.value;
    }
    
    handleLastNameChange(event) {
        this.rec.LastName = event.target.value;
    }
    
    handlePhysicalAttributesChange(event) {
        this.rec.Physical_Attributes__c= event.target.value;
    }
    handleClick() {
        createContact({ con : this.rec })
       .then(result => {
            // Clear the user enter values
            this.rec = {};
            window.console.log('result ===> '+result);
            // Show success messsage
            this.dispatchEvent(new ShowToastEvent({
                title: 'Success!!',
                message: 'Contact Created Successfully!!',
                variant: 'success'
            }),);
        })
        .catch(error => {            
            this.error = error.message;
            window.console.log('error body--'+error.body.message);
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error creating record',
                    message: error.body.message,
                    variant: 'error',
                }),
            );
            window.console.log("error", JSON.stringify(this.error));
        });

    }
    
}


Apex Class:
public with sharing class insertContactApexWeb {
   
    @AuraEnabled
    public static void saveContactRecord(Contact con){
        System.debug('acc--'+con);
        try{
            insert con;
        }
        catch(Exception ex) {
            throw new AuraHandledException(ex.getMessage());
        }
    }
}

I'm using a datatable in a lightning (aura) component. Since the columns don't allow for notation to get the relationship_field__r.QualifiedApiName I am trying to flatten the data the way you would with a lookup field on an object (as referenced here: https://salesforce.stackexchange.com/questions/200761/parent-field-in-lightning-datatable)

However it is not working and my column is still displaying blank.

Has anyone had success with a similar requirement displaying custom metadata relationship field names in a datatable?

I am calling another method of another class from another class but getting an error 'Method does not exist or incorrect signature: void getMDMSearchResult(String) from the type SearchPatientController' . not sure how to resolve it, Please help.

Parameters of the callled method :

    public List <GaineAcc> getMDMSearchResult(String searchTermFirst,String searchTermLast, String location,String recordTypeString,String email,String phone,Date birthdate,String middleName, String touchId, String hubId, String MDMId,String addstr,String zipCode, String gender){
/**
* @author: Shubham Sinha
* @date: 02/10/2020
* @description: This class is used for creating User Account and User records when a person tries to Login through Janrain
**/

Public Class BIIB_CreateAccountAndUser_Helper{
    /**
* 
* @description: Wrapper class for User and Account Creation, getting wrapper values from BIIB_ADU_Janrain_AuthProviderHandler Class

**/    
    Public class RegistrationDetails {
        
        public String firstName;
        public String lastName;
        public String fullName;
        public String email;
        public String username;
        public String locale;
        public String provider;
        Public String siteLoginUrl; 
        Public String identifier; 
        Public String link;
        Public Map<String,String> attributeMap;
        
        Public RegistrationDetails(){
            this.firstName ='';
            this.lastName ='';
            this.fullName = '';
            this.email= '';
            this.username = '';
            this.locale = '';
            this.provider ='';
            this.siteLoginUrl= '';
            this.identifier ='';
            this.link = '';
            
        }
    }
    /**
* @author: Shubham Sinha
* @description: Creates User Account and Patient therapy record.

**/
    public Static User createUserAccount(registrationDetails regDetailsWrapObj){
        Product_vod__c prodCatlog = [SELECT Name FROM Product_vod__c WHERE Name = :System.label.BIIB_Product_Aducanumab][0];
        Id recordTypeId = Schema.SObjectType.BIIB_Patient_Therapy__c.getRecordTypeInfosByName().get('AD').getRecordTypeId();
        Id recordTypeIdAccount = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Patient').getRecordTypeId();
        
        List<Account> checkAccountData = [SELECT id,FirstName, LastName, PersonEmail,BIIB_PASS_Zip_Code__c FROM Account 
                                          WHERE LastName =: regDetailsWrapObj.LastName AND FirstName =:regDetailsWrapObj.FirstName
                                          AND BIIB_PASS_Zip_Code__c =:  regDetailsWrapObj.attributemap.get('ZIP')
                                           Limit 1 ];
        Account createAccount;
        if(checkAccountData.size()> 0)
        {
            createAccount = checkAccountData[0];
            BIIB_Patient_Therapy__c patTherapy = new BIIB_Patient_Therapy__c();
            patTherapy.RecordTypeId = recordTypeId;
            patTherapy.BIIB_Indication__c = System.label.BIIB_Patient_Therapy_Indication;
            patTherapy.BIIB_Therapy__c = prodCatlog.id;
            patTherapy.BIIB_Patient__c= createAccount.id;
            
            insert patTherapy;
        }
        else 
        {
      
           
            createAccount = new Account ();
            createAccount.FirstName= regDetailsWrapObj.firstName;
            createAccount.LastName =regDetailsWrapObj.lastName;
            createAccount.RecordTypeId = recordTypeIdAccount;
            insert createAccount;
 
          BIIB_Patient_Therapy__c accPatTherapy = new BIIB_Patient_Therapy__c();
            accPatTherapy.BIIB_Indication__c = System.label.BIIB_Patient_Therapy_Indication;
            accPatTherapy.BIIB_Therapy__c = prodCatlog.id;
            accPatTherapy.BIIB_Patient__c= createAccount.id;
            insert accPatTherapy;
                String searchTermFirst = regDetailsWrapObj.firstName;


              ApexPages.StandardController accStdControllerObj = new ApexPages.StandardController(new Account());
            SearchPatientController tc = new SearchPatientController(accStdControllerObj);
            tc.getMDMSearchResult( searchTermFirst); 
        }
     
        User aduUser = createAduCommunityUser(regDetailsWrapObj, createAccount.id);
        return aduUser;
Hi, I would like add buttons at each row of visuallforce page and when I click the button it should give an alert which should get the Name of that Account since here I am using my standardCOntroller as Account object.

I've below code
<apex:page standardController="Account" recordSetVar="Accounts" sidebar="False">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection title="Details">
            <apex:pageBlockTable value="{!Accounts}" var="a">
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.Type}"/>
                <apex:column value="{!a.Website}"/>
                <apex:column headerValue="Details">
                    <apex:commandButton value="Details"/></apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

It gave me buttons at each row.
User-added image
Please tell me how to create custom action for the button to get the Name of the account as a alert..
  • February 14, 2020
  • Like
  • 0
We have some custom buttons on the Opportunity Object that work in Classic but do not working in Lightning. The buttons allow our development staff to open an Opportunity from the Contact page and some information like Opportunity Name, Account Name and Primary Contact are prefilled. This works in Classic but with the switch to Lightning those three fields do not get autopopulated when the button is used. I will also share screenshots for what the coding is for the custom and standard buttons.

Can someone tell me how to replicate this behavior in Lightning?

See the screenshots of the custom "New Contact Donation (501)" button and the standard/native "New Contact Donation (Managed). One other thing that I've noticed is that when I switch to Classic and try out the buttons the custom button fills out the Opportunity Name, Account Name and Primary Contact fields on the new Opportunity but the standard/native only fills out the Opportunity Name and Account Name... doing nothing with the Primary Contact field.

Thank you very much,

User-added imageUser-added image
I am trying to build a quick action, when clicked, will check for the Status field. IF status != Closed, wil redirect to visualforce page. Below is my component and controller codes. 
CloseCase.cmp
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,flexipage:availableForAllPageTypes">
     <!-- This attribute saves the record ID -->
    <aura:attribute name="recordId" type="String" />
     <aura:attribute name="CaseObject" type="Object" /> 
    <aura:attribute type="Object" name="record"/>
 
    <aura:attribute name="CaseStatusValue" type = "String" /> -->
   

   <aura:attribute name="recordLoadError" type="String"/>

   <force:recordData aura:id="recordLoader"
   recordId="{!v.recordId}"
   fields="Name,Status"
   targetFields="{!v.CaseObject}"
   targetError="{!v.recordLoadError}"
   targetRecord="{!v.record}"                    
   />

    
    
    <!-- This executes a function from the controller as soon as the component is open. 
    This is recommended when the action only processes data and there’s no need for user interaction -->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>

CloseCaseController.js
({
    doInit : function(component, event, helper) {
        var Caseid = component.get("v.recordId");
        var CaseStatus = component.get("v.CaseObject").Status;
        console.log(CaseStatus);
        if(CaseStatus != "Closed"){     
        var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
        "url": "/apex/KBReviewClose?id="+Caseid+"",
        "width" : "700",
        "height" : "1000",
        "scrollbars" : "yes"
    });
        
    urlEvent.fire();
    }
        else{ 
                    var resultsToast = $A.get("e.force:showToast");
                    resultsToast.setParams({
                        "title" : "Failed",
                        "message" : "Case is already closed",
                        "type" : "warning",
                         "duration" : "60000ms"
                    });
                      resultsToast.fire();}
    }
})

On the controller side, I am trying to get the 'Status' value of the case record and redirecting to a visualforce page if status is not equal to 'Closed'.

I am getting the below error. please help.
Error while creating component for lightning component quick action [Action failed: c:LCC_Close_KB_Review_Case$controller$doInit [Cannot read property 'Status' of null]].
 
  • January 20, 2020
  • Like
  • 0
Hi,

We used to be able to do this in Aura:
String labelName = 'mylabel';
$A.getReference("$Label.c."+ labelName);



$A is not accessible in LWC

Following the documentation I can only see a way to get access to Label's value through import.
As far as I know import don't work dynamically. You can only write an import if you know the name of the label.

I was hoping for a solution involving Apex and/or SOQL but could not find anything.

Any idea?