function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vikas KVikas K 

TRIGGER TO UPDATE A FIELD ON ONE OBJECT BASED ON FIELD CONDITION ON ANOTHER OBJECT

Hallo All,

I have masterdetail relationship between two objects quotes(parent) and quotelineitems(child)

REQUIREMENT: i am trying to create a trigger to update a field in quotes based on field condition in quotelineitems


NOTE: quotelineitems(child) also have lookup relationship with product(parent)

CODE:

trigger test2 on Quote (before insert) 
{
    if(trigger.isinsert && trigger.isbefore)
    {
        for(Quote q1:trigger.new)
        {
            list<quotelineitem> qli  = [select id,Produktname__c,Gegenkonto_AGBP__c from quotelineitem where Gegenkonto_AGBP__c = '84000' or Gegenkonto_AGBP__c = '84001'];
            list<quote> q = [select id,Name,Angebotsinhalt__c from quote where recordtype.name = 'angebot'];
            if(qli.Gegenkonto_AGBP__c == '84000')
            {
                q.Angebotsinhalt__c = qli.Produktname__c;
            } 
            else if(qli.Gegenkonto_AGBP__c == '84001')
            {
               q.Angebotsinhalt__c = 'produktion'; 
            }
            else
            {
                q.Angebotsinhalt__c = 'sonstiges';
            }
        }
    }
}

ERRORS:

Variable does not exist: Gegenkonto_AGBP__c
Variable does not exist: Produktname__c
Variable does not exist: Angebotsinhalt__c
Variable does not exist: Gegenkonto_AGBP__c
Variable does not exist: Angebotsinhalt__c
Variable does not exist: Angebotsinhalt__c


but when i look at the objects metadata i have all the above mentioned fields but when i try to code i am getting the above errors.

quote object fields:

Angebotsinhalt__c(text field)

quotelineitem fields:
Produktname__c(text field)
Gegenkonto_AGBP__c(picklist field)

Can someone please let me know at which part of the code i have gone wrong so that i can rectify?

Thanks for your help!




 
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi KAMVR,
  1. Check the field level access for these fields - if it has read/edit access for your profile.
  2. Other alternative which raises the error is - Apex class version ,try updating the version to higher version and saving the class.This worked for me in one of the scenario.

Please let me know if this was helpful.
Thanks.
Vikas KVikas K
thanks bhargavi for ur response.

yes there is read access for the fields of quotelineitems Produktname__c(text field),Gegenkonto_AGBP__c(picklist field)

and there is both read and edit access for the field that i want to edit i.e Angebotsinhalt__c field of quote object

inspite of having the access i am getting that error