You need to sign in to do that
Don't have an account?
Freddy Davaris
Apex Trigger Debugging Issue (new Apex coder)
Hi Everyone,
Just started coding with APEX last week and am trying to create a trigger that whenever an account field is edited, it looks into the opportunities of the account that has been edited. From the account's opportunities, it updates (see code below) a field labeled "Next Renewable Opportunity" when the opportunity is the account's next opportunity to be renewed.
Please Advise. When I run the trigger I get this error:
Error:Apex trigger CheckForNextRenewableOpp caused an unexpected exception, contact your administrator: CheckForNextRenewableOpp: execution of AfterUpdate caused by: System.TypeException: Invalid date: common.apex.runtime.impl.ApexFieldToken@3c8ccc3b: ()
Thanking you in advance,
FD
Just started coding with APEX last week and am trying to create a trigger that whenever an account field is edited, it looks into the opportunities of the account that has been edited. From the account's opportunities, it updates (see code below) a field labeled "Next Renewable Opportunity" when the opportunity is the account's next opportunity to be renewed.
trigger CheckForNextRenewableOpp on Account(after insert, after update) { // Get the related opportunities for the accounts in this trigger. List<Opportunity> relatedOpps = [SELECT Id,Name,Contract_Expiration_Date__c, Next_Renewable_Opportunity__c FROM Opportunity WHERE Contract_Expiration_Date__c__c != NULL AND AccountID IN :Trigger.New]; // Iterate over the related opportunities for(Opportunity opp : relatedOpps) { if (Account.Next_Renewal_Date__c != Null){ if ((date.valueof(opp.Contract_Expiration_Date__c) == date.valueOf(Account.Next_Renewal_Date__c) ) && (Opp.Next_Renewable_Opportunity__c == False)){ opp.Next_Renewable_Opportunity__c = True; // Sets next renewable opportunity field to 'TRUE' update opp; } else if (((date.valueof(opp.Contract_Expiration_Date__c) < Date.today()) || (date.valueof(opp.Contract_Expiration_Date__c) != date.valueOf(Account.Next_Renewal_Date__c))) && (opp.Next_Renewable_Opportunity__c == True)){ opp.Next_Renewable_Opportunity__c = False; // Sets next renewable oppotuinity field to 'False' update opp; } } } } // Contract Expiration Date: Opportunity Field, Type: Date Field // Next Renewal Date: Account Field, Type: Rollup Summary Field // Next Renewable Opportunity: Opportunity Field, Type: Checkbox Field
Please Advise. When I run the trigger I get this error:
Error:Apex trigger CheckForNextRenewableOpp caused an unexpected exception, contact your administrator: CheckForNextRenewableOpp: execution of AfterUpdate caused by: System.TypeException: Invalid date: common.apex.runtime.impl.ApexFieldToken@3c8ccc3b: ()
Thanking you in advance,
FD