Not able to see User record in apex - salesforce

I have created a lightning web component that is wrapped in a lightning component.
I am using the lightning component in quick action on the Contact object.
On the LWC we are querying the user attached to the current contact.
The class looks like below:
public without sharing class GetUserRecordClass {
#AuraEnabled
public static String printDetails( String argContactId ){
returnString = getUserRecord( argContactId );
}
private static String getUserRecord( String argContactId ){
try{
User userOnContact = [SELECT Id FROM User Where ContactId = :argContactId LIMIT 1];//Getting error on this line in QA org
String userId = userOnContact.Id;
return userId;
}
catch( Exception exceptionObject ){
System.debug( 'Exception occurred=' + exceptionObject.getMessage() );
System.debug( 'Stack trace=' + exceptionObject.getStackTraceString() );
throw exceptionObject;
}
}
}
The query on User is working fine in my Dev org.
I have deployed the code on QA org now.
I login into QA with the required user and click on the Quick Action button on the Contact record.
But getting below error in LWC:
List has no rows for assignment to SObject
The class is without sharing.
When I run the query with my user in the Developer console, I am able to get the result.
I tried verifying Org wide setting in both org and found a difference.
In Dev Org(Snapshot from Chrome):
In QA Org(Snapshot from Firefox):
I am not able to see Site User Visibility check box in the QA org. I believe by checking that, I may be able to fetch record in the QA org Apex.
Can you please let me know where to look else for this?

Related

Salesforce Deactivating the salesforce users who are not logged in last 3 months using apex program

I have written code for deactivating users who are not logged in last 3 months , but when I am running the program , it is giving me an exception like you can't deactivate this user because of the ownership of the records so then it is not checking for other users.
public class ExampleUser
{
public static void deactivate()
{
List<User> usersToUpdate = new List<User>();
for(User u: [SELECT Id, IsActive FROM User where IsActive= true and LastLoginDate <= :DATE.TODAY()-90])
{
u.IsActive = false;
/*try {
update u;
}
catch(Exception e){
System.debug(e);
}*/
usersToUpdate.add(u);
}
if (usersToUpdate.size()>0)
{
update usersToUpdate;
}
}
}
If I run the commented code(trying to deactivated each user seperately) it is giving an exception with more than 100 SOQL queries.
can anyone please help me in resolving this issue
Use Database.update(usersToUpdate, false) to avoid rolling back the entire transaction if one or more records fails.
That doesn't really solve your problem as such; it just means you do deactivate the users that can be deactivated. You'll need to develop a different solution if you want to review the users that cannot be deactivated for any reason.
You don't need to check the list size. Performing DML on an empty list does nothing.

How to test single registration page using selenium web driver and provide test report to development team?

I know basic selenium web driver and also written code using Page Object Model in TestNG frame work for one small application registration and login page.
Bu i don't know, how can provide test report to development team and what are the check points for automation testing please help me.
Example:
Assume my application have two pages like Registration and signin page
My code:
public class Sample {
Authentication_Locators authenticate;
WebDriver d = null;
#BeforeTest
public void beforeTest() throws Exception {
d = InitDriver.wbDriver("chrome", testData.getProperty("testUrl"));
authenticate = PageFactory.initElements(d,
Authentication_Locators.class);
}
#Test (priority = 0)
public void signIn() throws Exception {
Thread.sleep(1000);
authenticate.userName.sendKeys("user1");
authenticate.password.sendKeys("password1");
authenticate.signin.Click();
}
}
TesgNG creates HTML report of the execution which is located in the current working directory under results folder with name emailable_report. Also for more accurate reports you can also use Soft and hard asserts.
Hope this helps.

Specflow-Share browser session between features if triggered between steps

I have implemented Specflow to reuse some steps across features as in this example -Specflow,Selenium-Share data between different Step definitions or classes .Since, in our project, we are integrating multiple features & reusing them. What is the best way to share browser session across features if its triggered in between steps as per the above approach?
My Scenario:
Once an application created, I need to launch new session, login different User-set different services and approve it.
But after logging in fails with below error on Step definition 4 in reused Whenstep of Given(Set the service to (.*)). That particular step is from different feature, hence the new session needs to be used in those steps. The LaunchURl method below is just launching the website with url, no new session created - This works fine
OpenQA.Selenium.WebDriverException : Unexpected error. System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it "IP here"
[Given(#"A New Application is added")]
public void GivenANewApplicationIsAdded()
{
Given("UK_The Service is set");
Given("User Navigated to New Application screen");
When("User fills up form as in data row 1");
Then("new SID generated");
}
[Given(#"New Browser Launched")]
public void GivenNewBrowserLaunched()
{
SeleniumContext sl = new SeleniumContext();
this.seleniumContext = sl;
}
[Given(#"Login is successful with ""(.*)"" and ""(.*)""")]
public void GivenLoginIsSuccessfulWithAnd(string userName, string password)
{
SuperTests spr = new SuperTests();
_driver = spr.LaunchURL(seleniumContext.WebDriver);
//seleniumContext.WebDriver = _driver;
LoginPage lg = new LoginPage(_driver);
lg.LoginProcess(userName, password);
}
[Given(#"Set the service to ""(.*)""")]
public void GivenSetTheServiceTo(string serviceId)
{
When("Select a Service from the option "+serviceId);
Then("The Services is changed to the one selected " + serviceId);
}
In other feature
[When(#"Select a Service from the option (.*)")]
public void WhenSelectAServiceFromTheOptionTestTeam(string p0)
{
HomePage mst = new HomePage(seleniumContext.WebDriver);
mst.SetServiceId(p0);
}
The 2 work around what we figured was
Create a new instance of binding class to call the methods or steps as shown below
[Given(#"Set the service to ""(.*)""")]
public void GivenSetTheServiceTo(string serviceId)
{
var serIdSteps = new UK_SetServiceIDSteps(seleniumContext);
serIdSteps.WhenUK_SelectAServiceFromTheOptionTest(serviceId);
serIdSteps.ThenUK_TheServicesIsChangedToTheOneSelected(serviceId);
}
or
tried this which worked as well- basically calling a new method to create a new session. for this I need not create any new instance for Binding class. Called the Step directly.
[Given(#"New Browser Launched")]
public void GivenNewBrowserLaunched()
{
SuperTests spr = new SuperTests();
_driver = spr.LaunchURL("Firefox");
seleniumContext.WebDriver = _driver;
}
public void GivenSetTheServiceTo(string serviceId)
{
When("UK_Select a Service from the option "+serviceId);
Then("UK_The Services is changed to the one selected " + serviceId);
}
Not sure, which is correct way of doing it? Trying to figure it out from Reusable steps point?The latter one is not advised as we need to change the type of browser to launch at multiple place.

Using the ASP .NET PROFILE Provider in a WPF application

I've been able to find lots of stuff about using the ASP .NET Membership provider in WPF. I've even got the ASP .NET Role provider working in my WPF application. These are very easy to use in WPF. What I can't find any information about is how to use the ASP .NET PROFILE provider in a WPF application.
My application will be running on a laptop located in a moving vehicle; it cannot use Web Services to connect to a server and authenticate the user. My code needs to be able to retrieve the user's profile information from the local database.
I've tried several times to build a class that derives from ProfileBase but nothing I've tried has worked. To elaborate, the code below is an excerpt from my latest failed attempt:
public class UserProfile : ProfileBase {
[CustomProviderData( "AlarmsToDisplay;int" )]
public int AlarmsToDisplay {
get { return (int) GetPropertyValue( "AlarmsToDisplay" ); }
set { SetPropertyValue( "AlarmsToDisplay", value ); }
}
// Other properties following the same pattern follow.
private UserProfile() { }
public static UserProfile GetUserProfile( string username ) {
return Create( username ) as UserProfile;
}
public static UserProfile GetUserProfile( string username, bool isAuthenticated ) {
return Create( username, isAuthenticated ) as UserProfile;
}
}
In this code, the method GetUserProfile( string username, bool isAuthenticated ) returns null. I believe this is because the compiler can't cast a ProfileBase to a UserProfile, even though UserProfile descends from ProfileBase. Please correct me if I'm wrong.
Can someone point me to an existing article or describe the proper way to build a user profile class that extends from ProfileBase?
I've managed to resolve this issue on my own. Here's what works:
Remove the attributes from all of the CLR properties. These do not work with the default aspnet_Profiles table.
In app.Config, you need to add an "inherits" attribute to the tag. This has to be set to the fully qualified name of your class, separated from the assembly file name (no extension) by a comma.
Once these things were done, the GetUserProfile method and the ProfileBase class's Create methods return UserProfile objects.

Silverlight4 calling ASMX web service

I have a Visual Studio solution with a Silverlight project, and a web project which hosts the Silverlight app. The web project also contains an ASMX web service which is called by the Silverlight ap.
As described below, certain calls to the web service work fine, and yet others cause a CommunicationException to be thrown, wrapping a WebException - both with the message "The server returned the following error: 'not found'".
Firstly, here's my original method, which failed as described above (entity names changed for simplicity):
[WebMethod]
public Customer GetCustomer(int id)
{
CustomerDataContext dc = new CustomerDataContext();
return dc.Customers.SingleOrDefault(x => x.Id == id);
}
Secondly, to debug the problem I took Linq to SQL and the database out of the picture, and the below code worked fine:
[WebMethod]
public Customer GetCustomer(int id)
{
Customer c = new Customer() { ID=1, Name="Bob", History = new EntitySet<CustomerHistory>() };
return c;
}
Third, thinking about this, one difference between the two methods is that the first one would include values in the customer history. I extended the second method to include this, and it started failing again:
[WebMethod]
public Customer GetCustomer(int id)
{
Customer c = new Customer() { ID=1, Name="Bob", History = new EntitySet<CustomerHistory>() };
c.History.Add(new CustomerHistory() { Id=1, CustomerId=1, Text="bla" });
return c;
}
I'm stuck with regards to how to progress - my current thinking is that this could be a deserialization issue on the Silverlight side, when the object graph is deeper. This rationally doesn't make sense, but I can't think of anything else. I've confirmed that the transfer size and buffer size are big enough (2GB by default).
Any pointers would be appreciated.
Ahhhh the famous "Not Found" error, try to get details from that error using the tag in your web.config. That will create a log file providing details of the error.
The following link explains exaclty how to do it :
http://blogs.runatserver.com/lppinson/post/2010/04/15/Debugging-WCF-Web-Services.aspx

Resources