Find your content:

Search form

You are here

System.StringException: Invalid Id:

 
Share

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 !!

-Scott.

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.


Attribution to: Scott Guillot

Possible Suggestion/Solution #1

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


Attribution to: sfdcfox
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/32337

My Block Status

My Block Content