You need to sign in to do that
Don't have an account?
Dman100
Thanks for any help.
Invalid initial expression type for field Opportunity.CloseDate, expecting: Date
please help...I'm trying to write unit test code for a class file I've created, but I'm getting the following error:
Invalid initial expression type for field Opportunity.CloseDate, expecting: Date
Here is my class file and unit test code:
Code:
public class OpportunityOwnerRole { public static void UpdateOwnerRole(Opportunity[] opps) { Opportunity opp = [select ownerid from Opportunity where id in :opps]; Id oid = opp.ownerid; User role = [select userroleid from User where id = :oid]; Id urid = role.userroleid; UserRole userrole = [select name from UserRole where id = :urid]; String strownerrole = userrole.name; for (Opportunity op: opps) { op.owner_role__c = strownerrole; } } public static void InsertOwnerRole(Opportunity[] opps) { List<Opportunity> OpptoUpdate= new List<Opportunity>(); Opportunity opp = [select ownerid from Opportunity where id in :opps]; Id oid = opp.ownerid; User role = [select userroleid from User where id = :oid]; Id urid = role.userroleid; UserRole userrole = [select name from UserRole where id = :urid]; String strownerrole = userrole.name; for (Opportunity op : opps) { Opportunity o = new Opportunity( Id = op.Id ); o.owner_role__c = strownerrole; OpptoUpdate.add(o); } update OpptoUpdate; } public static testMethod void testOpportunityOwnerRoleClass() { // Create a new opportunity to test Opportunity o = new Opportunity(Ownerid='00540000000o1y6AAA',Name='Test Opportunity Owner Role Trigger',CloseDate='2008-12-31',StageName='Prospecting'); insert o; // Check if owner role field has been set to updated with owner role System.assert('VP, North American Sales', [Select Owner_Role__c from Opportunity WHERE ownerid = '00540000000o1y6AAA']); } }
Thanks for any help.
'2008-12-31' despite looking like a date is a string, you need to construct an instance on the Date class, try Date.newInstance(2008,12,31) instead.
http://www.salesforce.com/us/developer/docs/apexcode/index_CSH.htm#apex_methods_system_date.htm
Date.newInstance(2008,12,31) worked for me ... Tx