You need to sign in to do that
Don't have an account?
variable does not exist - Update Lookup Field value with newly inserted object Id
Hi,
I'm brand new to apex. I'm trying to update an already existing apex class with some code that will, based on field values, create a new record. I then want to update the Quote and Opportunity to tie back to that newly created record and I'm getting the error for "Variable does not exist" for everything I'm trying.
Here's a snippet of the code I'm using. It does more than just this, but the errors are being thrown at the aQuote.ContractId & aQuote.Opportunity.ContractId
What do I need to do to ensure the Opp & Quote records get tied back to the Contract?
Thanks!
I'm brand new to apex. I'm trying to update an already existing apex class with some code that will, based on field values, create a new record. I then want to update the Quote and Opportunity to tie back to that newly created record and I'm getting the error for "Variable does not exist" for everything I'm trying.
Here's a snippet of the code I'm using. It does more than just this, but the errors are being thrown at the aQuote.ContractId & aQuote.Opportunity.ContractId
private static string processSale(Quote aQuote) { if (aQuote.IsPaid__c && (aQuote.Opportunity.Account.Has_a_signed_MSSA__c == 'No' || aQuote.Opportunity.Account.Has_a_signed_MSSA__c == null ) && aQuote.Opportunity.Account.Type != 'Current Customer') { Contract aContract = new Contract ( AccountId = aQuote.Opportunity.Account.id ,ContractTerm = aQuote.Initial_Contract_Term_Length__c.intValue() ,StartDate = aQuote.Initial_Contract_Start_Date__c ); insert aContract; aQuote.ContractId = aContract.Id; aQuote.Opportunity.ContractId = aContract.Id; update aQuote; update aQuote.Opportunity; } }
What do I need to do to ensure the Opp & Quote records get tied back to the Contract?
Thanks!
All Answers
By default Contract field on Opportunity is hidden from all profiles.
In order to make it visible follow the steps
https://help.salesforce.com/articleView?id=000213295&type=1
Can you please let us know what error you are facing during the execution of this code. It looks to fine. Is there any error ?
Thanks,
Abhishek Bansal.
If it not inserting a new Contract record then it is clear that the code is not executed after If statement. There must be some variable that are not set correctly and being used in the If statement. You should check them properly and then try to execute your code. If there is any urgency on this then you can contact me on Gmail or Skype:
Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790
Thanks,
Abhishek Bansal.