You need to sign in to do that
Don't have an account?

Need help with a test class for my trigger
New to triggers, and i've finally got my trigger working as needed in the sandbox.
here it is ..
here is my class
Please let me know if there is something i'm missing, i'm still learning
here it is ..
trigger ClosedOpportunityTrigger on Opportunity (before insert, before update) { for(Opportunity opp : Trigger.New) { Id closedBy; Date closedOn = opp.CreatedDate.date(); if (opp.IsClosed) { closedBy = opp.LastModifiedById; closedOn = opp.LastModifiedDate.date(); if (Trigger.isUpdate) { Opportunity old = Trigger.OldMap.get(opp.Id); if (old.IsClosed == opp.IsClosed) { closedBy = old.Closed_By__c; closedOn = old.CloseDate; } } } opp.Closed_By__c = closedBy; opp.CloseDate = closedOn; } }My test class isn't working, i'm getting "Your ClassID property is missing or null" error from Force IDE
here is my class
@isTest public class OppCloseDateTest { static testMethod void TestChangeOpportunityClosedby() { Opportunity opp = new Opportunity(); opp.Name= 'Opportunity'; opp.StageName='Closed Grant'; opp.CloseDate=System.today(); Update opp; } }
Please let me know if there is something i'm missing, i'm still learning
Please use below apex class and test class code.
Apex class:
Test Class:
This is covering 100% in my org.
Please let me know if you need assitance on this or contact me on below details:
Thanks
Gaurav
Email: gauravgarg.nmims@gmail.com
Skype: gaurav62990
All Answers
Your are updating opportunity in your test class with out inserting it.First insert the opportunity and then update the opportunity.
Please use the below mentioned code:
Please try below code.
Let me know if you still face some issues.
Thanks,
Gaurav
Could you please try saving the class file directly on your salesforce org. Or please refersh the code from org and then save.
Thanks,
Gaurav
Your class "ClosedOpportunityTrigger" is on the second line having 23% code i.e. 3/13 lines.
Can you please check which all lines aren't covered using testMethod.
Please follow steps to find the lines not covered:
1. Open developer console.
2. ctrl + shift + O (chracter O).
3. Enter class name "ClosedOpportunityTrigger".
4. Click on code coverage button and check.
Blue lines are the covered lines.
Red lines are which need to be covered.
Let me know if you need on this.
Thanks,
Gaurav
Email: gauravgarg.nmims@gmail.com
Skype: gaurav62990
Please use below apex class and test class code.
Apex class:
Test Class:
This is covering 100% in my org.
Please let me know if you need assitance on this or contact me on below details:
Thanks
Gaurav
Email: gauravgarg.nmims@gmail.com
Skype: gaurav62990
"Save error: Invalid constructor syntax, name=value pairs can only be used for SObjects OppCloseDateTest.cls /Closed Date Trigger/src/classes line 5 "
Do you have AccountTrigger having controller which access Name as parameters. If not, please try below code.
Please try if you still have any required field on Account object. If so, please add those field in Account test data.
Account acct = new Account();
acct.Name='Test Account';
// Insert required field here.
insert acct;
Please let me know if you still face issues on this, or you can contact me on below details.
Thanks,
Gaurav
Email: gauravgarg.nmims@gmail.com
Skype: gaurav62990