You need to sign in to do that
Don't have an account?
Apex Trigger to Apex Class
Hello,
I am trying to create an Apex Class for the Apex Trigger below. How would I go about doing this? Here is a link to my original post: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BWej. Thanks for your help!
I am trying to create an Apex Class for the Apex Trigger below. How would I go about doing this? Here is a link to my original post: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BWej. Thanks for your help!
trigger fillInAccount on MPM4_BASE__Milestone1_Project__c(after insert, after update) { Set<Id> oppIds = new Set<Id>(); for(MPM4_BASE__Milestone1_Project__c proj : trigger.new){ if(proj.Opportunity_Name__c != null){ oppIds.add(proj.Opportunity_Name__c); } } Map<Id,Opportunity> oppMap = new Map<Id,Opportunity>([Select AccountId from Opportunity where id in :oppIds]); Set<Id> accIds = new Set<Id>(); for(Opportunity opp : oppMap.values()){ accIds.add(opp.AccountId); } Map<Id,Account> accMap = new Map<Id,Account>([Select Project__c from Account where Id In :accIds]);//Replace Project__c with your field API name for(MPM4_BASE__Milestone1_Project__c proj : trigger.new){ if(oppMap.containsKey(proj.Opportunity_Name__c)) { accMap.get(oppMap.get(proj.Opportunity_Name__c).AccountId).Project__c = proj.id; //Replace Project__c with your field API name } } update accMap.values(); }
I have a workaround for this problem.
Just remove that line from apex test class which is giving the error and try to deploy the trigger and test class.
I hope it will definitely resolve the issue.
Modify your test class as below :
Please let me know the status of your deployment process after doing the changes in test class .
Thanks,
Abhishek Bansal.
All Answers
Please find test class for your trigger :
Please run this test class and see the code coverage of your trigger in developer console.
If it runs successfully and code coverage is above or equal to 75% than please include this test class along with trigger in your deployment process and migrate it to production.
You will not face any issues then.
Let me know if you need any help on this.
Regards,
Abhishek
So the test class worked great! Now I am doing a change set to get the class and trigger into our production org. However when I validated the class in our production org, it came back with this error:
System.AssertException: Assertion Failed: Expected: null, Actual: a0H4000000GQMdzEAH
Stack Trace: Class.TestFillAccount.validateFillAccount: line 14, column 1
What did we do wrong? Thanks!
Nick
I have a workaround for this problem.
Just remove that line from apex test class which is giving the error and try to deploy the trigger and test class.
I hope it will definitely resolve the issue.
Modify your test class as below :
Please let me know the status of your deployment process after doing the changes in test class .
Thanks,
Abhishek Bansal.
It works perfect! Thank you so much! This is going to be a huge help to our company!!
Thanks,
Nick