• CLites
  • NEWBIE
  • 0 Points
  • Member since 2013

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

I am running in to an issue that I was hoping someone might have some insight in to. I have a method in a class triggered by contact insert or update. This method will check to see if a contact has a box checked and if it does, it will create a correspondinng user record with the ContactId set to the Id of the contact that was being created/edited. 

The issue that I am having is with the test code coverage. I am getting the error "UNKNOWN_EXCEPTION, portal account owner must have a role". Now I have seen the workaround for this by creating a user with a role and then putting the community user creation code inside System.runAs context with the user you created. This works for community users created in the test class itself, however, if the test class is not actually creating the community user directly, but rather by creating a contact which triggers the class mentioned above to create a community user, it fails with the same role error mentioned above. 

In all my searching, all I have found is a solution to the first issue where the community user is being created in the test class itself. I have not found any info for resolving it if the test class it then calling out to another class that creates the user. Any info on how I might be able to resolve would be greatly appreciated.

Thanks,

Chris
 
  • April 13, 2020
  • Like
  • 0

Hi,

 

I am a bit stuck on a problem and I was hoping that someone might be able to help. I am creating an inline visualforce page with a page block table. the table displays different images on each row when a user clicks on the image but when the table refreshes, the rows in the table reorder themselves. the image changes correctly but I need the order of the rows to remain constant. I am really stuck as to trying to figure out why these rows are reordering themselves. any help would be greatly appriciated. the page and controller are below.

 

<apex:page standardController="Project__c" extensions="ProjectRequirementLinkController">

     <apex:form >
     	<apex:actionFunction action="{!methodOne}" name="methodOneInJavascript" rerender="selectLineItemsTable">
	        <apex:param name="firstParam" assignTo="{!testId}" value="" />
	    </apex:actionFunction>
	    			    
		<apex:pageBlock >
			<apex:pageBlockButtons >
			<div>
			<apex:commandLink action="{!CreateRequirements}" target="_top" value="Link/Unlink Requirements" styleClass="btn" oncomplete="window.top.location='/{!Project__c.id}'; return false"/>
			<apex:commandLink action="{!URLFOR($Action.Requirement__c.New)}" target="_top" value="New Requirement" styleClass="btn" type="image/png"/>
			</div>
			</apex:pageBlockButtons>
			<apex:pageBlockSection title="Requirements for Account: {!Project__c.Account__r.Name}" columns="1">
		  		<apex:pageBlockTable id="selectLineItemsTable" value="{!linkedRequirements}"  var="item" width="95%">
		    		
		    		
		    		<apex:column >
		      			<div>
					    <apex:outputPanel onclick="methodOneInJavascript('{!item.requirement.Id}')" > 
					        <apex:image id="added" value="{!URLFOR($Resource.Checkboxes, item.picture)}"/> 
					    </apex:outputPanel>
       					 </div>
		    		</apex:column>
       					
       					
		    		<apex:column >
		      			<apex:facet name="header">Requirement Name</apex:facet>
		      			<apex:outputLink value="/{!item.requirement}" target="_blank">{!item.requirement.Name}</apex:outputLink>
		    		</apex:column>
		    		
		    		<apex:column >
		      			<apex:facet name="header">Requirement Subject</apex:facet>
		      			<apex:outputText value="{!item.requirement.Subject__c}"/>
		    		</apex:column>
		    		
		    		<apex:column >
		      			<apex:facet name="header">Requirement's Project</apex:facet>
		      			<apex:outputLink value="/{!item.requirement.Project__c}" target="_blank">{!item.requirement.Project__r.Name}</apex:outputLink>
		    		</apex:column>
		    		
		  		</apex:pageBlockTable>
			</apex:pageBlockSection>			
		</apex:pageBlock>
	</apex:form>
	
</apex:page>

 

 

public with sharing class ProjectRequirementLinkController {


/*Initialization*/
    public ProjectRequirementLinkController(ApexPages.StandardController controller) {
    	
    	projId=controller.getId();
    	
        proj2 = [SELECT Id, Name, Account__r.Id, Account__r.Name
				FROM Project__c 
        		WHERE Project__c.Id =: projId limit 1];		
        
       	loadRequirements();
       	
    }
    
/*End Initialization*/

/*Properties*/
 
    private final Project__c proj2;
    public Map<Id, SelectAddDeleteSObject> linkedRequirements2 {get; set;}
    public List<SelectAddDeleteSObject> linkedRequirements {
    	get{return linkedRequirements2.values();}
    	set;}
    private Id projId {get; set;}
     
    
/*End Properties*/

/*Action Methods*/


	private SelectableSObject SSO;
	public Id testId {get; set;}
	public String state = 'Checkboxes/SF_Checkbox_Unchecked.jpg';
	
    public void methodOne() {
    	if(linkedRequirements2.get(testId).status == SelectAddDeleteSObject.State.selected)
        {
        	linkedRequirements2.get(testId).status = SelectAddDeleteSObject.State.deleted;
        	linkedRequirements2.get(testId).picture = 'Checkboxes/SF_Checkbox_Red_X.jpg';
        }
        else if(linkedRequirements2.get(testId).status == SelectAddDeleteSObject.State.deleted)
        {
        	linkedRequirements2.get(testId).status = SelectAddDeleteSObject.State.selected;
        	linkedRequirements2.get(testId).picture = 'Checkboxes/SF_Checkbox_Checked.jpg';
        }
        else if(linkedRequirements2.get(testId).status == SelectAddDeleteSObject.State.unselected)
        {
        	linkedRequirements2.get(testId).status = SelectAddDeleteSObject.State.added;
        	linkedRequirements2.get(testId).picture = 'Checkboxes/SF_Checkbox_Checked_Green.jpg';
        }
        else if(linkedRequirements2.get(testId).status == SelectAddDeleteSObject.State.added)
        {
        	linkedRequirements2.get(testId).status = SelectAddDeleteSObject.State.unselected;
        	linkedRequirements2.get(testId).picture = 'Checkboxes/SF_Checkbox_Unchecked.jpg';
        }

    }
    
    
    
    
    public PageReference CreateRequirements()
    {
    	try
    	{
	    	List<Requirement__c> toUpdate = new List<Requirement__c>();
	    	for(SelectAddDeleteSObject currentRequirement : linkedRequirements2.values()){
	    		
	    		if(currentRequirement.status == SelectAddDeleteSObject.State.added){
	    			
	    			currentRequirement.requirement.Project__c = projId;
	    			toUpdate.add(currentRequirement.requirement);
	    		}
	    		else if(currentRequirement.status == SelectAddDeleteSObject.State.deleted){	
	    			currentRequirement.requirement.Project__c = null;
	    			toUpdate.add(currentRequirement.requirement);
	    		}
	    	}
	    	update toUpdate;
    	}
    	catch (DmlException e)
    	{
    		system.debug(LoggingLevel.ERROR, e.getMessage());
    	}
    	loadRequirements();
    	return null;
    }
/*End Action Methods*/

/*Helper Methods*/
	public void loadRequirements() {
		linkedRequirements2 = new Map<Id, SelectAddDeleteSObject>();
		linkedRequirements = new List<SelectAddDeleteSObject>();
		
		for(Requirement__c current_req : [SELECT Id, Name, Subject__c, Project__c, Project__r.Name
	        	  							FROM Requirement__c
	        	  							WHERE (Requirement__c.Account__r.Id =: proj2.Account__r.Id)
	        	  							])
		{
		    SelectAddDeleteSObject SAD_req = new SelectAddDeleteSObject(current_req);
		    
		    if(current_req.Project__c == projId){
		    	SAD_req.status = SelectAddDeleteSObject.State.selected;
		    	SAD_req.picture = 'Checkboxes/SF_Checkbox_Checked.jpg';
		    } 
		    linkedRequirements2.put(current_req.Id, SAD_req);
		}  
	}
/*End Helper Methods*/   






}

 

 

Thanks,

 

Chris

 

  • November 14, 2013
  • Like
  • 0
Hi,

I am running in to an issue that I was hoping someone might have some insight in to. I have a method in a class triggered by contact insert or update. This method will check to see if a contact has a box checked and if it does, it will create a correspondinng user record with the ContactId set to the Id of the contact that was being created/edited. 

The issue that I am having is with the test code coverage. I am getting the error "UNKNOWN_EXCEPTION, portal account owner must have a role". Now I have seen the workaround for this by creating a user with a role and then putting the community user creation code inside System.runAs context with the user you created. This works for community users created in the test class itself, however, if the test class is not actually creating the community user directly, but rather by creating a contact which triggers the class mentioned above to create a community user, it fails with the same role error mentioned above. 

In all my searching, all I have found is a solution to the first issue where the community user is being created in the test class itself. I have not found any info for resolving it if the test class it then calling out to another class that creates the user. Any info on how I might be able to resolve would be greatly appreciated.

Thanks,

Chris
 
  • April 13, 2020
  • Like
  • 0