Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following private method in my controller ::

@TestVisible private DSLogin__c createBlankLoginInfo() {
    DSLogin__c obj = new DSLogin__c();

    obj.Name = getSalesforceName();
    obj.strDBUsername__c = '';
    obj.strSessionToken__c = '';
    obj.DSServerId__c = '';
    obj.datetimeSessionStart__c = null;
    obj.datetimeSessionEnd__c = null;

    return obj;

In my test class I have the following test method ::

static testMethod void createBlankLoginInfo_UnitTest() {
    DSLoginController  con = new DSLoginController();

    System.assertNotEquals(con, null);

    DSLogin__c  LoginInfo = con.createBlankLoginInfo();

    System.assertNotEquals(LoginInfo, null);

Also, DSLogin__c has the following fields ::

DB_Username__c - Text(80)

DSServerId__c - Lookup(DSServer)

datetimeSessionEnd__c - Date/Time

datetimeSessionStart__c - Date/Time

strSessionToken__c - Text(255)

and the DSServer object is defined as ::

ServerURL__c - Text(255)

I am surprised to see this failing because I have called the method already in my controller. It all works just fine. I am adding a test for this method now and then this message shows up as I trying to save my changes.

System.StringException: Invalid Id:

Admittedly I am new to Salesforce/Apex/VisualForce/Eclipse/JSON/jQuery and last but not least HTML5 with (or without) CSS.

Can anyone explain to me what is happening?

Thank You in advance !!


PS. Full disclosure - I edited this post. Changed DSServer_c to DSServerId_c within the definition of the DSLogin_c object. My intent with this field is to store just the record id of the DSSever_c record/object. Hopefully, I am doing that sort of thing right or in a 'best-practice' manner.

share|improve this question
up vote 6 down vote accepted

'' isn't a valid Id. Use null instead.

share|improve this answer
Okay, makes sense. But, my code has been posting up to the Salesforce server just fine until I added this particular test. Let me give it a whirl. – Scott Guillot Apr 9 '14 at 19:08
Because the compiler doesn't check for id correctness; this is a runtime error. If a test doesn't cover a runtime error area, you won't know about the error until a page or trigger crashed. – sfdcfox Apr 9 '14 at 19:14
Ah, okay. I can go with it being a runtime error, but when viewing the page that is using this controller, no exceptions are thrown. Well, let me say that I have not had my execution or usage of the page disrupted by an exception. Now, that said, I think I will turn on debugging and look through a few runnings. Thanks !! – Scott Guillot Apr 9 '14 at 19:18
Possibly a try-catch block or maybe it's not called when you think it is. – sfdcfox Apr 9 '14 at 19:20
Ding, Ding, Ding !!! You nailed it. Thank You ! – Scott Guillot Apr 9 '14 at 19:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.