+ Start a Discussion
ForceComForceCom 

Test method --userinfo.getUserId()------ERROR!!!!!---Emergency...!!!

hi I have a custom controller to test....I have written the test method for this  controller...please find below the part of a code which has an error...

 

I cannot capture the ContactId from userinfo1....since i logged in as a system admin...

 

To explain further, I capture the contact record Id from the user record created on the portal...I even used ....

 

Profile p = [select Id from profile where Name = 'Portal User'];

User userInfo1 = [Select ContactId, Id,lastname,ProfileId from User where ProfileId =: P.Id];

 

But I dont see the record of mine, when i log into the portal , i see some other record.....So How can i solve...this...or....how can I use the userinfo.getuserId in the test method.....I am stuck here...Please help !!!!!

 

User userInfo1 = [Select ContactId, Id from User where Id =: userInfo.getUserId()];
        contact = [Select Id,firstName,lastName,Anticipated_Term_Start_Date_

_c,Email,Program_of_Interest__c,HomePhone,MobilePhone,Birthdate,
        Contact_Status__c,Gender__c,OtherPhone,LeadSource,MailingStreet,MailingCity,MailingCountry,MailingPostalCode,MailingState,
        OtherStreet,OtherCity,OtherCountry, OtherPostalCode,OtherState,What_are_you_applying_to__c from Contact where Id =: userInfo1.ContactId];

 

Thank you all....

Best Answer chosen by Admin (Salesforce Developers)