You need to sign in to do that
Don't have an account?
Awesome User11
Variable does not exist: tc.Account _Name__c at line 13 column 58
I am putting together code for an update to a custom object (opportunity hierarchy) based on set fields (IDs) being provided in the opportunity object.
I am getting an error that my field Account_Name__c is not a variable the exists. Any ideas?
I am getting an error that my field Account_Name__c is not a variable the exists. Any ideas?
trigger OpptyHierarchy on Opportunity_Hierarchy__c (before insert, before update) { Set<string> OpportunityID = new set<string>(); for (Opportunity_Hierarchy__c tc : trigger.new) { if (tc.Account_Name__c != NULL) {OpportunityID.add(tc.Account_Name__c); } } Map<string, Opportunity> Opportunity = new Map <string, Opportunity>(); for (Opportunity obj : [SELECT ID, AccountID, Main_Account__c, Enterprise_Account__c from Opportunity Where OpportunityID in: Opportunity]) {Opportunity.put(obj.Account_Name__c,obj); } for (Opportunity_Hierarchy__c t: trigger.new) { if (Opportunity.containsKey(tc.Account_Name__c)) tc.Account_Name__c = Opportunity.get(tc.Account_Name__c).ID; tc.Main_Account__c = Opportunity.get(tc.Account_Name__c).Main_Account__c; tc.Enterprise_Account__c = Opportunity.get(tc.Account_Name__c).Enterprise_Account__c; } }
In your for loop your are using tc as an trigger.new instance but in your loop your wrote only t instead of tc -
change it: like below
Now I received another error that states:
Error: Compile Error: Invalid field Account_Name__c for SObject Opportunity at line 10 column 84
No such column 'OpportunityID' on entity 'Opportunity'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 8 column 28
I suggest you please complete trailhead first. go here for trailhead;
https://trailhead.salesforce.com/
also if you want to lear Apex visit this site:
http://www.sfdc99.com/