You need to sign in to do that
Don't have an account?
Lookup and update object in Apex Class
I have an Apex Class written by my in-house non-Salesforce developer. I tried to modify it and am now getting an internal server error. Here's the part of the code that works (there's a lot more, I'm just not showing it here).
Essentially, this is a combination of everything I've tried and it didn't work. the first List/For bit threw an internatl server error. The second For bit didn't actually do anything (but didn't throw an error - it didn't update the contract though). The bit under the "//This throws an internal server error" obviously didn't work either.
I'm a coding novice - pretty solid admin, but code is still new to me so I'm self-teaching as I go. Any and all help is appreciated.
As a note, the ContractId for aQuote is being grabbed at the bottom of the Apex Class in a getQuoteSOFor call (call? statement? method?)
private static string processSale(Quote aQuote) { if (aQuote.Opportunity.Account.Member_ID__c == null || aQuote.Opportunity.Account.Member_ID__c == '') { aQuote.Opportunity.Account.Member_ID__c = generateMemberID(aQuote.Opportunity.Account.Name); } //New clients - Build the Contract if (aQuote.Signed_MSSA__c == false && aQuote.Opportunity.Type == 'New Business') { Contract aContract = new Contract ( AccountId = aQuote.Opportunity.Account.id ,ContractTerm = aQuote.Initial_Contract_Term_Length__c.intValue() ,StartDate = aQuote.Initial_Contract_Start_Date__c ,Status = 'Draft' ,Number_of_Quotes__c = 1 ); insert aContract; aContract.Status = 'Activated'; update aContract; aQuote.ContractId = aContract.Id; aQuote.Opportunity.ContractId = aContract.Id; } }The part that isn't working is this:
//Existing clients - Append to the Contract if (aQuote.ContractId != null && aQuote.Opportunity.Type != 'New Business') { /* List<Contract> updateContract = New List<Contract>(); For(Contract con : [Select id, Number_of_Quotes__c , Addendums__c FROM Contract WHERE Id = :aQuote.ContractId]){ con.Addendums__c = aQuote.Addendum__c; con.Number_of_Quotes__c = con.Number_of_Quotes__c + 1; } update updateContract; For (Contract con : [Select id, Number_of_Quotes__c , Addendums__c FROM Contract WHERE Id = :aQuote.ContractId] ){ con.Number_Of_Quotes__c = con.Number_of_Quotes__c + 1; con.Addendums__c = aQuote.Addendum__c; } update con;*/ //This throws an internal server error Contract updateContract = [SELECT id, Number_of_Quotes__c , Addendums__c FROM Contract Where Id = :aQuote.ContractId LIMIT 1]; updateContract.Number_of_Quotes__c = updateContract.Number_of_Quotes__c + 1; updateContract.Addendums__c = aQuote.Addendum__c; update updateContract; }
Essentially, this is a combination of everything I've tried and it didn't work. the first List/For bit threw an internatl server error. The second For bit didn't actually do anything (but didn't throw an error - it didn't update the contract though). The bit under the "//This throws an internal server error" obviously didn't work either.
I'm a coding novice - pretty solid admin, but code is still new to me so I'm self-teaching as I go. Any and all help is appreciated.
As a note, the ContractId for aQuote is being grabbed at the bottom of the Apex Class in a getQuoteSOFor call (call? statement? method?)
Could you please tell "aQuote" is an object/instance of which Salesforce Object. Basically want to know type of "aQuote".
Secondly Could you please remove dml operation once and check again if the issue is persisting? These information could help in finding the root cause of the issue.
Regards,
Ashish Kr.
I have tried commenting out the entire Existing Clients section and the code worked flawlessly. It's somewhere in there that the error is being thrown.
Are you referring to the statement that updates aQuote or the Contract record? Or are you referring to commenting it out of my Apex Class? Sorry, I'm a very very inexperienced developer - much better with clicks than code.