• ep2
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

I'm trying to write some tests for a Visualforce controller extension, however the tests are failing because a query in the controller is not retrieving related sObjects in a query. Outside of testing (in the sandbox), the related sObjects are retrieved without issue, but in testing the related sObjects are null.

 

Here is the query code in the controller:

private void queryRel ()
{
	for (Relationship__c r : [SELECT Id,Name,Primary_Client__r.Name,Owner.Id,Owner.Name,Owner.IsActive FROM Relationship__c WHERE Id = : relId FOR UPDATE])
		rel = r;
}

 In the test environment, Owner is null.

 

Here is the setup code for the test:

List<Relationship__c> rList = [SELECT Id,OwnerId,(SELECT Id FROM Accounts__r) FROM Relationship__c];
rList[2].OwnerId = [SELECT Id FROM User WHERE IsActive = TRUE AND Id != : UserInfo.getUserId() LIMIT 1].Id;
Database.update(rList[2]);

ApexPages.StandardController sc = new ApexPages.StandardController([SELECT Id FROM Relationship__c WHERE Id = : rList[0].Id]);
RelationshipAddController rac = new RelationshipAddController(sc);
System.AssertNotEquals('fatal',rac.pageMsgSeverity,rac.pageMsgBody + rac.rel);

 Currently that first assertion fails because an internal check to verify the Owner is active fails since Owner.IsActive is null.

 

Any suggestions would be greatly appreciated.

  • March 05, 2013
  • Like
  • 0

I have a VF page to override the standard view on an object. I'm doing this so I can add in a table which shows related child records and allow some editing on those child records. However, I'm having some trouble saving the updates to these child records.

 

What happens is that if I use my update button after just having edited a record (the edited field still has focus), the last edit will not be saved. However, if I make the same edit again, but this time click somewhere else on the page (to cause the field to lose focus) the edit goes through successfully.

 

When I finally figured out this was the issue (and it took a long time), I invetigated on standard SF pages and discovered this problem was not there. I also discovered this issue was present wether I used an inputField or inlineEditSupport.

 

Has anyone encountered this? Know of a way around it? Perhaps I'm approaching this solution incorrectly?

 

Here is the page code in case it helps:

<apex:page standardController="Relationship_Request__c" extensions="RelationshipRequestViewController">
	<apex:detail subject="{!request}" relatedList="false" inlineEdit="true"/>
	<apex:form >
		<apex:pageBlock mode="maindetail" rendered="{!IF(request.RecordType.Name='Client/Prospect Transfer',TRUE,FALSE)}">
			<apex:pageBlockSection title="Request Items" columns="1">
				<apex:pageMessages />
				<apex:outputPanel id="itemTable">
					<apex:pageBlockTable value="{!items}" var="item">
						<apex:column headerValue="Client/Prospect">
							<apex:outputField value="{!item.Account__c}"/>
						</apex:column>
						<apex:column headerValue="TIN">
							<apex:outputField value="{!item.Account__r.Tax_ID_Number__c}"/>
						</apex:column>
						<apex:column headerValue="Relationship">
							<apex:outputField value="{!item.Account__r.Relationship__c}"/>
						</apex:column>
						<apex:column headerValue="Remove?">
							<apex:outputPanel id="decision">
								<apex:outputField value="{!item.Decision__c}">
									<apex:inlineEditSupport event="ondblclick"/>
								</apex:outputField>
							</apex:outputPanel>
						</apex:column>
						<apex:column headerValue="Comments">
							<apex:outputField value="{!item.Comments__c}">
								<apex:inlineEditSupport event="ondblclick" disabled="{!item.Removed__c}"/>
							</apex:outputField>
						</apex:column>
						<apex:column headerValue="Status">
							<apex:outputField value="{!item.Status__c}"/>
						</apex:column>
					</apex:pageBlockTable>
				</apex:outputPanel>
			</apex:pageBlockSection>
			<apex:pageBlockButtons location="bottom">
				<apex:actionStatus id="itemButton">
					<apex:facet name="stop">
						<apex:commandButton id="updateButton" onmouseover="document.getElementById('updateButton').focus()" action="{!updateItems}" value="Update Request Items" rerender="itemTable">
							<apex:actionSupport event="onclick" rerender="itemTable" status="itemButton"/>
						</apex:commandButton>
					</apex:facet>
					<apex:facet name="start">
						<apex:commandButton value="Updating..." disabled="true"/>
					</apex:facet>
				</apex:actionStatus>
			</apex:pageBlockButtons>
		</apex:pageBlock>
	</apex:form>
	<apex:relatedList list="ProcessSteps"/>
	<apex:relatedList list="Relationship_Request_Items__r"/>
</apex:page>

 And the controller code:

public with sharing class RelationshipRequestViewController
{
    public Relationship_Request__c request {get; set;}
    private Map<Id,Relationship_Request_Item__c> itemMap;
    public List<Relationship_Request_Item__c> items {get; set;}
    
    public RelationshipRequestViewController (ApexPages.StandardController sc)
    {
        request = [SELECT Id,Current_Owner__c,Approver__c,New_Owner__c,Process_Status__c,RecordType.Name
                   FROM Relationship_Request__c
                   WHERE Id = : sc.getId()];
		queryItems();
    }
    
    private void queryItems ()
    {
    	itemMap = new Map<Id,Relationship_Request_Item__c>
    	(
    		[SELECT Id,Decision__c,Comments__c,Status__c,Account__c,Account__r.Relationship__c,
    				Account__r.Tax_ID_Number__c,Account__r.Pseudo_TIN__c,Removed__c
    		 FROM Relationship_Request_Item__c
    		 WHERE Relationship_Request__c = : request.Id
    		 ORDER BY Account__r.Pseudo_TIN__c,Id]
    	);
    	items = itemMap.values();
    }
    
    public void updateItems ()
    {
//    	System.Assert(false,items);
    	List<Database.SaveResult> srList = Database.update(items);
    	for (Integer i = 0; i < srList.size(); i++)
    	{
    		if (!srList[i].isSuccess())
				items[i].addError(srList[i].getErrors()[0].getMessage());
    	}
    	queryItems();
    }
}

 

  • February 15, 2013
  • Like
  • 0

I'm trying to write some tests for a Visualforce controller extension, however the tests are failing because a query in the controller is not retrieving related sObjects in a query. Outside of testing (in the sandbox), the related sObjects are retrieved without issue, but in testing the related sObjects are null.

 

Here is the query code in the controller:

private void queryRel ()
{
	for (Relationship__c r : [SELECT Id,Name,Primary_Client__r.Name,Owner.Id,Owner.Name,Owner.IsActive FROM Relationship__c WHERE Id = : relId FOR UPDATE])
		rel = r;
}

 In the test environment, Owner is null.

 

Here is the setup code for the test:

List<Relationship__c> rList = [SELECT Id,OwnerId,(SELECT Id FROM Accounts__r) FROM Relationship__c];
rList[2].OwnerId = [SELECT Id FROM User WHERE IsActive = TRUE AND Id != : UserInfo.getUserId() LIMIT 1].Id;
Database.update(rList[2]);

ApexPages.StandardController sc = new ApexPages.StandardController([SELECT Id FROM Relationship__c WHERE Id = : rList[0].Id]);
RelationshipAddController rac = new RelationshipAddController(sc);
System.AssertNotEquals('fatal',rac.pageMsgSeverity,rac.pageMsgBody + rac.rel);

 Currently that first assertion fails because an internal check to verify the Owner is active fails since Owner.IsActive is null.

 

Any suggestions would be greatly appreciated.

  • March 05, 2013
  • Like
  • 0