function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Keer YenduriKeer Yenduri 

Developer console code

public with sharing class DemoController
{
String LoggedInUserId;
public DemoController(ApexPages.StandardController controller)
{
LoggedInUSerId = UserInfo.getUserId();
}
}

in this program i want to execute in developer console:
i wrote like this
DemoController obj =new DemoController();
but it's not getting
Best Answer chosen by Keer Yenduri
Keer YenduriKeer Yenduri
Hi Sagar,


public with sharing class DemoController
{
String LoggedInUserId;
public DemoController()
{
LoggedInUSerId = UserInfo.getUserId();
System.debug('the output'+LoggedInUserId);
}
}

and in developer console:
DemoController obj =new DemoController();
the result is:
|the output00590000002t5qQAAQ

My Question is whther the output is right or wrong how can i find?




 

All Answers

santoshgoresantoshgore
Hi Keer,

In your main class constructor has a controller as a parameter,so while invoking you need to something like below:

DemoController obj =new DemoController(instanceOfStadardController);

Thanks,
Santosh
Keer YenduriKeer Yenduri
DemoController obj =new DemoController(instanceOfStadardController);
i got this error in developer console
1.Variable does not exist: instanceOfStadardController
Sagar PareekSagar Pareek
You need to include System.debug('the output'+LoggedInUserId); after assigning value to LoggedInUserId so that you can see the result in developer console. 
santoshgoresantoshgore
Hi Keer,

make ur main class as 
public with sharing class DemoController
{
String LoggedInUserId;
public DemoController()
{
LoggedInUSerId = UserInfo.getUserId();
}
}

and then run as 
DemoController obj =new DemoController();

thanks,
Santosh
 
Keer YenduriKeer Yenduri
Hi,

i did the same but i could not see the result
Keer YenduriKeer Yenduri
Hi Sagar,


public with sharing class DemoController
{
String LoggedInUserId;
public DemoController()
{
LoggedInUSerId = UserInfo.getUserId();
System.debug('the output'+LoggedInUserId);
}
}

and in developer console:
DemoController obj =new DemoController();
the result is:
|the output00590000002t5qQAAQ

My Question is whther the output is right or wrong how can i find?




 
This was selected as the best answer
lakslaks
Hi,

1. One way to check if you fetched the correct user information would be to append the id to your URL 
https://.......salesforce.com/<id printed in debug log - 00590000002t5qQAAQ>
This should take you to the particular User's profile.

2. You can also fetch the user information and confirm by executing the following in the query editor in the Developer console -> 
SELECT Name from User where Id = '00590000002t5qQAAQ'


Regards,
Lakshmi.