You need to sign in to do that
Don't have an account?
Glen.ax1034
Error: Invalid Data.
Apex trigger ContractCompliance caused an unexpected exception, contact your administrator: ContractCompliance: execution of BeforeUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Contract.Status: Trigger.ContractCompliance: line 6, column 1
Error: Invalid Data.
Review all error messages below to correct your data.
trigger ContractCompliance on Opportunity (before update) { for (Opportunity opp:Trigger.new){ List<Contract> c = new List<Contract>([SELECT id from Contract where AccountId = :opp.accountid]); for(Contract cTypeObj : c) { if (cTypeObj.Status == 'Activated Signed') { if (cTypeObj.Contract_ID_Prefix__c == 'MSA') { opp.ContractStructure__c = 'Yes'; opp.MSA_or_Standalone_Effective_Date__c = cTypeObj.StartDate; } } } List<Account> a = new List<Account>([SELECT id from Account where Id = :opp.accountid]); for(Account aTypeObj : a) { opp.Legal_Account_Name__c = aTypeObj.Hoovers_Company_Name__c; opp.Customer_Contract_Street_Address_1__c = aTypeObj.Hoover_s_HQ_Address_1__c; opp.Customer_Contract_Street_Address_2__c = aTypeObj.Hoover_s_HQ_Address_2__c; opp.Customer_Notices_City__c = aTypeObj.Hoover_s_HQ_City__c; opp.Customer_Notices_Zip__c = aTypeObj.Hoover_s_HQ_Postal_Code__c; } } }
The purpose of this trigger is to pull values of fields to the sObject Opportunity from the related Contract(s)and Account(s)
Please Add Status column in your SOQL query,
List<Contract> c = new List<Contract>([SELECT id, Status from Contract where AccountId = :opp.accountid]);
And also make add all the missing column that you are using ahead this line.
All Answers
Please Add Status column in your SOQL query,
List<Contract> c = new List<Contract>([SELECT id, Status from Contract where AccountId = :opp.accountid]);
And also make add all the missing column that you are using ahead this line.
Solved.. at least i hope so.
do you think that this will error if those fields are blank in account and contract?
they shouldnt... because i ran it with some blank ones.. but i'm kind of new to apex.. and i'm thinking that perhaps this might be a potential error.
another question... how would i test this code? create an opportunity, account and contract and set the contract accountid to the account.id and the opportunity.accountid to the account.id? then upsert the account, then the contract, then the opportunity?
test class success