You need to sign in to do that
Don't have an account?
Depton
How to set the ID field (look up) in a test method?
Hi,
I got the error:
Failure Message: "System.StringException: Invalid id: xx", Failure Stack Trace: "Class.take_ownership.test: line 13, column 90 External entry point"
the field, is a look up = Project_Milestone__c
so I have written in the test:
Project_Milestone__c= 'xx'
but then I´ve got the error.
How should I set the look up field ID for the test method?
Thank you!
Well, I expect that you don't really have a "Project_Milestone__c" object with that exact name. So, it's telling you that's not a valid type. Check your spellings, check the API name of your object. -S
All Answers
You should create a Project_Milestone__c object, and then insert it. After the insert you will have the id.
Project_Milestone__c pm = new Project_Milestone__c(Name='Peanuts' ... other fields if you need them, etc.);
insert pm;
Then later, when you need an Id for a Project_Milestone__c you use pm.id.
You would be well served by reading the "Testing Apex" section of the Apex documentation.
Best, Steve.
I got it!!!
Grand!!! thank you very much!!!
I was reading the "workbook" this morning on the train and I remember i read this part, I think I understood perfectly how to set it up.
:)
public static testmethod void test() {
Project_Milestone__c pm = new Project_Milestone__c(Name='Peanuts', Stage__c= 'Production', Kickoff__c=Date.today(), Deadline__c= Date.today()
);
insert pm;
Milestone1_Task__c record = new Milestone1_Task__c(Name='test',
Project_Milestone__c= 'pm.id', Task_Stage__c= 'Planned',Start_Date__c=Date.today(),Due_Date__c =Date.today(),Assigned_To__c='Marketing VSN' );
insert record;
I have finished it and got this error:
Error: Compile Error: Invalid type: Project_Milestone__c at line 13 column 34 : "in Bold"
Thank you
......, Project_Milestone__c = pm.id, ......
Don't put it in quotes, you're referring to a property of a declared sobject variable, not a string. -Steve
In bold the error
I am trying to create first the Project_Milestone__c
and then Milestone1_Task__c
I have added a ) in this line
Kickoff__c=Date.today(), Deadline__c= Date.today() );
but then I got the error:
on the previous line:
Error: Compile Error: Invalid type: Project_Milestone__c at line 13 column 34
Any ideas!!??
Thank you!!
Well, I expect that you don't really have a "Project_Milestone__c" object with that exact name. So, it's telling you that's not a valid type. Check your spellings, check the API name of your object. -S
Thank you,
you were right!!
Deployed!!
Thank you!