+ Start a Discussion
Josh Davis 13Josh Davis 13 

How to use Id in apex that needs tested before deployed?

I have a user who imports data in our production instance, and I wrote a scheduled apex to process that data. The most sure way to query the records to process is to use the user's LastModifiedById. However, I have to write and test the code in our sandbox, and test 75%+ to deploy to production. The user's production Id isn't recognized in sandbox, so no records are found and not enough of the code gets tested. How would you work around this?
Best Answer chosen by Josh Davis 13
Ray C. KaoRay C. Kao
Do you need a sample code which demonstrate querying user information in the testing code.
Then, the testing code can run in both Sandbox and Production without any modification?
If so, here is one. Please have fun with it.
private class aTestClass {
    static testMethod void unitTest() {
        User marc = [ SELECT Id FROM User WHERE Name = 'Marc Benioff' ];
        List<Object__c> objs = [ SELECT Id FROM Object__c WHERE LastModifiedById = :marc.Id ];