• Michael Johnson 29
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 3
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 3
    Replies
Is it possible to set the networkid of a running user in a unit test?

I created a test user in a unit test with a profile that only has access to 1 community. Running a test as this user using system.runas(user) still has network.getnetworkId() returning as null. I've tried setting the users networkId both using User.networkId = networkid and User.network.Id = networkid and neither work (invalid foreign key relationship). Is there somewhere in the test I can define what network to run the test under? Any other ideas?

We have run into an issue when running unit tests that call a class from a managed package using a mock. When doing data manipulation within a test method (inserting new records) calling the class returns null value (in the case below a string 'Success' is expected to return).

@isTest(SeeAllData=true)
	static void testMock1() {
		system.debug(ManagedPackage1.Class1.ReturnSuccess('result', new ManagedPackage1.MockGenerator.Result1());
	}


Running the test above, the debug of 'Success' returns as expected. However, if any data manipulation is done at the beginning of the test method, null is always returned.
 

@isTest(SeeAllData=true)
	static void testMock1() {
		Account a = new Account();
		insert a;
		system.debug(ManagedPackage1.Class1.ReturnSuccess('result', new ManagedPackage1.MockGenerator.Result1());
	}

The bahavior completely changes, and the debug returns null. We have found a way around it doing the following.

@isTest(SeeAllData=true)
	static void testMock1() {
		Account a = new Account();
		insert a;
		test.starttest();
		system.debug(ManagedPackage1.Class1.ReturnSuccess('result', new ManagedPackage1.MockGenerator.Result1());
		test.stoptest();
	}
The result returns 'Success' as intended wrapped in test.starttest() and test.stoptest(). If the insert of the Account is also done within the start and stop test, the debug is again null. Any ideas as to why this behaves the way it does?

 

Is there a way to query Knowledgeable People (people endorsed on a topic) through Apex? You can grab this information through the Chatter API:

"Topics, Endorse People (/connect/topics/topicId/endorsements) is a collection of endorsements on knowledgeable people for a specific topic. Use this resource to endorse people for the specified topic and to get information about endorsements for a specific topic."

But I'd like to query this object in SOQL. I thought the object might be KnowledgeableUser, but it doesn't appear to be the case (the metadata is not the same, and querying against this does not return the same results as the Chatter API).

Any ideas?

I am having an issue where nested query results are not returning when being passed through a different class. 

Here is my scenario.

Master Object: Project__c
Child Object: ProjectRole__c

When using a subquery in the same class, the related subqueried objects show up just fine.

list<Project__c> pl = [Select Id, Name, (Id, Name from ProjectRoles__r) from Project__c];
system.debug(pl.get(0).ProjectRole__r);

Running this query in a class or in the developer console returns the ProjectRoles__r subquery just fine.

DEBUG|(ProjectRole__c:{Project__c=a0lg0000002tbnuAAA, Id=a0mg00000048QUTAA2, Name=PRR-0000117848}, ProjectRole__c:{Project__c=a0lg0000002tbnuAAA, Id=a0mg00000048QUUAA2, Name=PRR-0000117849})

However, when you reference a class to return this query, the subqueries are completely lost. 

public without sharing class QueryController {

	 public static list<Project__c> getProjects(){
 		return [Select Id, Name, (Id, Name from ProjectRoles__r) from Project__c];
 	}
}
list<Project__c> pl = QueryController.getProjects();
system.debug(pl.get(0).ProjectRole__r);
While the Project__c record is returned, none of the subqueried records are returned.
DEBUG|()

Anyone have any ideas?
Any idea how you can achieve an order by relevance clause in SOQL (similar to what returns by default in SOSL)? If not, is it possible to replicate the logic using some sort of custom class to parse and order the data? I may attempt doing this, but I wanted to see if anything out there existed already before spending too much time on it.
We are using a combination of Visualforce and AngularJS to build a community site. Whenever any type of Apex rerender is included (be it in an action function, action support, button etc) all scripts and content loaded using AngularJS break. This is only an issue using Internet Explorer. If I remove the rerender tags within the Visualforce components, everything works fine. Any suggestions?

Recently I've noticed setting showheader="false" breaks the ability to change the profile picture on a Visualforce page in <chatter:userPhotoUpload>. Anyone have any work arounds or know if this is intentional?


This allows you to click the image and change the picture without issue.

<apex:page>
	<chatter:userPhotoUpload showOriginalPhoto="true"/>
</apex:page>

This does not. Is there a script missing I can import?
<apex:page showheader="false">
	<chatter:userPhotoUpload showOriginalPhoto="true"/>
</apex:page>

 
Is it possible to set the networkid of a running user in a unit test?

I created a test user in a unit test with a profile that only has access to 1 community. Running a test as this user using system.runas(user) still has network.getnetworkId() returning as null. I've tried setting the users networkId both using User.networkId = networkid and User.network.Id = networkid and neither work (invalid foreign key relationship). Is there somewhere in the test I can define what network to run the test under? Any other ideas?

We have run into an issue when running unit tests that call a class from a managed package using a mock. When doing data manipulation within a test method (inserting new records) calling the class returns null value (in the case below a string 'Success' is expected to return).

@isTest(SeeAllData=true)
	static void testMock1() {
		system.debug(ManagedPackage1.Class1.ReturnSuccess('result', new ManagedPackage1.MockGenerator.Result1());
	}


Running the test above, the debug of 'Success' returns as expected. However, if any data manipulation is done at the beginning of the test method, null is always returned.
 

@isTest(SeeAllData=true)
	static void testMock1() {
		Account a = new Account();
		insert a;
		system.debug(ManagedPackage1.Class1.ReturnSuccess('result', new ManagedPackage1.MockGenerator.Result1());
	}

The bahavior completely changes, and the debug returns null. We have found a way around it doing the following.

@isTest(SeeAllData=true)
	static void testMock1() {
		Account a = new Account();
		insert a;
		test.starttest();
		system.debug(ManagedPackage1.Class1.ReturnSuccess('result', new ManagedPackage1.MockGenerator.Result1());
		test.stoptest();
	}
The result returns 'Success' as intended wrapped in test.starttest() and test.stoptest(). If the insert of the Account is also done within the start and stop test, the debug is again null. Any ideas as to why this behaves the way it does?

 

Any idea how you can achieve an order by relevance clause in SOQL (similar to what returns by default in SOSL)? If not, is it possible to replicate the logic using some sort of custom class to parse and order the data? I may attempt doing this, but I wanted to see if anything out there existed already before spending too much time on it.

Is there a way to query Knowledgeable People (people endorsed on a topic) through Apex? You can grab this information through the Chatter API:

"Topics, Endorse People (/connect/topics/topicId/endorsements) is a collection of endorsements on knowledgeable people for a specific topic. Use this resource to endorse people for the specified topic and to get information about endorsements for a specific topic."

But I'd like to query this object in SOQL. I thought the object might be KnowledgeableUser, but it doesn't appear to be the case (the metadata is not the same, and querying against this does not return the same results as the Chatter API).

Any ideas?

I am having an issue where nested query results are not returning when being passed through a different class. 

Here is my scenario.

Master Object: Project__c
Child Object: ProjectRole__c

When using a subquery in the same class, the related subqueried objects show up just fine.

list<Project__c> pl = [Select Id, Name, (Id, Name from ProjectRoles__r) from Project__c];
system.debug(pl.get(0).ProjectRole__r);

Running this query in a class or in the developer console returns the ProjectRoles__r subquery just fine.

DEBUG|(ProjectRole__c:{Project__c=a0lg0000002tbnuAAA, Id=a0mg00000048QUTAA2, Name=PRR-0000117848}, ProjectRole__c:{Project__c=a0lg0000002tbnuAAA, Id=a0mg00000048QUUAA2, Name=PRR-0000117849})

However, when you reference a class to return this query, the subqueries are completely lost. 

public without sharing class QueryController {

	 public static list<Project__c> getProjects(){
 		return [Select Id, Name, (Id, Name from ProjectRoles__r) from Project__c];
 	}
}
list<Project__c> pl = QueryController.getProjects();
system.debug(pl.get(0).ProjectRole__r);
While the Project__c record is returned, none of the subqueried records are returned.
DEBUG|()

Anyone have any ideas?

Recently I've noticed setting showheader="false" breaks the ability to change the profile picture on a Visualforce page in <chatter:userPhotoUpload>. Anyone have any work arounds or know if this is intentional?


This allows you to click the image and change the picture without issue.

<apex:page>
	<chatter:userPhotoUpload showOriginalPhoto="true"/>
</apex:page>

This does not. Is there a script missing I can import?
<apex:page showheader="false">
	<chatter:userPhotoUpload showOriginalPhoto="true"/>
</apex:page>