• Henry Michel
  • 30 Points
  • Member since 2019

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
  • 0
I have an overridden standard 'New' button in lightning with my custom component but when I am using it from the related list of the parent object, I am not getting parent record id in the URL. Also, 'hasRecordId' is giving Id of the child record only. Any Solution for this??
Hi all,

I am trying to write information from the opportunitylineitem to the opportunity. On the LineItem there is a field called Product which is a standard lookup field to the product object. I am trying to get that name to go from the LineItem to the Opportunity to a custom field called product. When I was trying to reference the Standard lookup product I kept getting an error message saying it wasn't a field so changed it to the description to see if i could get the description to go from the LineItem to the Opportunity. The trigger did save but it didn't work so I wanted to post my code here to see if anyone could help.

So my first question is how do I reference a standard lookup field in apex and the second is this the best way to get information from the LineItem to the opportunity?
trigger OpportunityProductTrigger on OpportunityLineItem (after update) {

List<Id> oppIds = new List<Id>();
String Item;

    if(trigger.isAfter) {
        for (OpportunityLineItem oli: trigger.new){
        List<OpportunityLineItem> allOLI = [SELECT id, ProductCode FROM OpportunityLineItem WHERE OpportunityId in: oppids];
        List<Opportunity> oppsToUpdate = [SELECT id, Product__c FROM Opportunity WHERE id in: oppids];
        if(allOLI.size() > 0){
          for(OpportunityLineItem allOLI2: allOLI){
                    Item = allOLI2.ProductCode;
                }//END if(allOLI2.Number_of_Months__c > contractLengthMonths)
            } //END for(OpportunityLineItem allOLI2: allOLI)
            for(Opportunity oppUpdate: oppsToUpdate){
                oppUpdate.Product__c = Item;
            }// END for(Opportunity oppUpdate: oppsToUpdate)


I tried this : 
import { LightningElement, api, wire } from "lwc"; import { getRecord } from "lightning/uiRecordApi"; import ACCOUNT_RECORDTYPE_FIELD from '@salesforce/schema/Account.RecordTypeId'; export default class Account_Redirect extends NavigationMixin(LightningElement) { @api recordId; @api objectApiName; @wire(getRecord, { recordId: '$recordId', fields: [ACCOUNT_RECORDTYPE_FIELD] }) acc; get recordTypeId() { return this.acc.data.fields.RecordTypeId.value; } }
But i have the following error : 
"Cannot read property 'fields' of undefined"