You need to sign in to do that
Don't have an account?
Jim Montgomery
Error "variable does not exist" using custom setting values in apex trigger
Here is my code. Getting error Variable does not exist: OppFieldName at line 21 column 11.
trigger Update_X_Reference on Opportunity (before update) {
for(Opportunity Opp : Trigger.new){
if(opp.is_ams_renewal__c)
{
Opportunity oldOpp = Trigger.oldMap.get(opp.Id);
Account_x_reference__c xref = [select ID,ams_renewal_email__C,X2019_AMS_Additional_Discount__c, ams_renewal_contact__c from account_x_reference__c where ID = :Opp.Account_X_Reference__c LIMIT 1];
if(oldOpp.AMS_Renewal_contact__c !=opp.AMS_renewal_contact__c){
TaxUpdateYear__C TUY = TaxUpdateYear__c.getInstance('UpdateYear');
String OppFieldName = TUY.Opportunity_Field_Name__c;
String XRefFieldName = TUY.X_Ref_Field_Name__c;
xref.ams_renewal_contact__c = opp.ams_renewal_contact__c;
}
if(oldOpp.ams_renewal_email__c != opp.ams_renewal_email__c)
{
xref.AMS_renewal_email__c = opp.ams_renewal_email__c;
}
if(oldOpp.OppFieldName != opp.OppFieldName)
{
xref.XRefFieldName = opp.OppFieldName;
}
update xref;
}
{
return;
}
}
}
trigger Update_X_Reference on Opportunity (before update) {
for(Opportunity Opp : Trigger.new){
if(opp.is_ams_renewal__c)
{
Opportunity oldOpp = Trigger.oldMap.get(opp.Id);
Account_x_reference__c xref = [select ID,ams_renewal_email__C,X2019_AMS_Additional_Discount__c, ams_renewal_contact__c from account_x_reference__c where ID = :Opp.Account_X_Reference__c LIMIT 1];
if(oldOpp.AMS_Renewal_contact__c !=opp.AMS_renewal_contact__c){
TaxUpdateYear__C TUY = TaxUpdateYear__c.getInstance('UpdateYear');
String OppFieldName = TUY.Opportunity_Field_Name__c;
String XRefFieldName = TUY.X_Ref_Field_Name__c;
xref.ams_renewal_contact__c = opp.ams_renewal_contact__c;
}
if(oldOpp.ams_renewal_email__c != opp.ams_renewal_email__c)
{
xref.AMS_renewal_email__c = opp.ams_renewal_email__c;
}
if(oldOpp.OppFieldName != opp.OppFieldName)
{
xref.XRefFieldName = opp.OppFieldName;
}
update xref;
}
{
return;
}
}
}
Or
https://salesforce.stackexchange.com/questions/8325/retrieving-value-using-dynamic-soql
https://salesforce.stackexchange.com/questions/4193/update-a-records-using-generic-fields
https://developer.salesforce.com/forums/?id=906F00000008xujIAA
Here is a Screenshot. You can see your fault.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
Tried moving it up to where I am declaring the other variables, but still no luck.