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
RuleyRuley 

Force.com Free user with Custom Controller and Visualforce Page

I have a force.com Free app where my Free license users can access the objects standard pages, create, edit as they should. However I created a custom controller and Visualforce form page that they can see all of the correct data that they should have, but the save button doesn't actually perform the action. That profile has security access to the class and the page. It isn't throwing an error, it is just doing nothing. My system admin user works just fine and handles the data correctly, so I'm guessing it is something wrong in a security setting, only I don't know what it is because those Free users have permission on the object (and they can save via the standard object page), the class and the page. 

 

On the button, the action calls my Custom Controller that grabs all of the records in the form, loops over them and then saves. It isn't throwing an error, it acts like it submits the page, but nothing happens. The values remain in the fields as they were typed. And debugging appears like that save action on the button never takes place.

goabhigogoabhigo

Can you post the save call(in VF page) and that method in controller?

Just wanted to check whether you have written it in correct way.

RuleyRuley

Here is the Visualforce page

 

<apex:page controller="TaskTimeEntryController" id="thePage" showHeader="true" sidebar="true">
	<apex:form id="theForm">
		<apex:sectionHeader title="Task List & Time Entry" Subtitle="{!$User.FirstName} {!$User.LastName}"/>
		<apex:pageBlock id="theBlock">
			<apex:pageBlockButtons >
				<apex:commandButton action="{!save}" value="Save"/>
			</apex:pageBlockButtons>
			<apex:pageBlockSection columns="1" id="theBlockSection">
				<apex:pageBlockTable value="{!lstTasksForUser}" var="lstTasks" id="FullTaskList" width="100%">
					<apex:column HeaderValue="Task Name">
						<apex:outputLink value="/{!lstTasks.ID}" id="theLink">{!lstTasks.Name}</apex:outputLink>
					</apex:column>
					<apex:column HeaderValue="Status">
						<apex:outputText Value="{!lstTasks.Task_Status__c}"></apex:outputText>
					</apex:column>
					<apex:column HeaderValue="Due Date">
						<apex:outputText Value="{!MONTH(lstTasks.Current_End_Date__c)}/{!DAY(lstTasks.Current_End_Date__c)}/{!YEAR(lstTasks.Current_End_Date__c)}"></apex:outputText>
					</apex:column>
					<apex:column HeaderValue="Task Time">
						<apex:outputText Value="{!lstTasks.Current_Hours__c}"></apex:outputText>
					</apex:column>
					<apex:column HeaderValue="Task Duration">
						<apex:outputText Value="{!lstTasks.Current_Duration__c}"></apex:outputText>
					</apex:column>
					<apex:column HeaderValue="Future Time">
						<apex:repeat value="{!lstTasks.Future_Time_Entries__r}" var="tmpFutureTime" id="theRepeat">
							<apex:outputText value="{!tmpFutureTime.Estimated_Time__c}" id="theValue"/><br/>
						</apex:repeat>
					</apex:column>
					<apex:column HeaderValue="Work Type">
						<apex:selectList id="chooseWorkType" size="1">
				            <apex:selectOption itemValue="Development" itemLabel="Development"/>
				            <apex:selectOption itemValue="Discovery" itemLabel="Discovery"/>
				            <apex:selectOption itemValue="Design" itemLabel="Design"/>
				            <apex:selectOption itemValue="Implementation" itemLabel="Implementation"/>
				            <apex:selectOption itemValue="Testing" itemLabel="Testing"/>
				            <apex:selectOption itemValue="Project Management" itemLabel="Project Management"/>
				        </apex:selectList>
					</apex:column>
					<apex:column HeaderValue="Time Entry">
						<apex:inputText id="TimeEntry"></apex:inputText>
						<apex:inputHidden id="TaskID" value="{!lstTasks.ID}"></apex:inputHidden>
					</apex:column>
				</apex:pageBlockTable>
			</apex:pageBlockSection>
		</apex:pageBlock>
	</apex:form>
</apex:page>

 

 

 

Here is my custom controller

 

public class TaskTimeEntryController {
	public List<Task__c> lstTasksForUser {get;set;} //= new List<Task__c>();
	public List<Time_Entry__c> lstTimeToEnter = new List<Time_Entry__c>();
	public ID insertedTimeTaskID {get; set;}
	public Date insertedTimeDate {get; set;}
	public Double insertedTimeWorked {get; set;}
	public String insertedWorkType {get; set;}
	
	public TaskTimeEntryController(){
		populateTaskList();
	}
	
	private void populateTaskList() {
		lstTasksForUser = [
			Select ID, Name, Task_Status__c, Current_Hours__c, Current_End_Date__c, Current_Duration__c, Assigned_To__c, 
				(Select Estimated_Time__c From Future_Time_Entries__r)
			From Task__c 
			WHERE Assigned_To__c = :UserInfo.getUserId()
			ORDER BY Current_End_Date__c];
	}
	
	public List<Task__c> getUsersTasks() {
		return lstTasksForUser;
	}
		
	//save and return to the page
	public PageReference save() {
		string tempFieldToFind;
		string txtForm = 'thePage:theForm:theBlock:theBlockSection:FullTaskList:';
		integer intCounter = 0;
		boolean blnLoop = true;
		insertedTimeDate = date.today();
		
		while(blnLoop){
			tempFieldToFind = txtForm + intCounter + ':TimeEntry';
			if(Apexpages.currentPage().getParameters().containsKey(tempFieldToFind)){
				if(Apexpages.currentPage().getParameters().get(tempFieldToFind).length()>0){
					insertedTimeWorked = decimal.valueOf(Apexpages.currentPage().getParameters().get(tempFieldToFind));
					tempFieldToFind = txtForm + intCounter + ':TaskID';
					insertedTimeTaskID = Apexpages.currentPage().getParameters().get(tempFieldToFind);
					tempFieldToFind = txtForm + intCounter + ':chooseWorkType';
					insertedWorkType = Apexpages.currentPage().getParameters().get(tempFieldToFind);
					
					Time_Entry__c objNewTimeEntry = new Time_Entry__c(Task__c=insertedTimeTaskID, Date_Worked__c=insertedTimeDate, Time_Worked__c=insertedTimeWorked, Type_Of_Work__c=insertedWorkType);
					lstTimeToEnter.add(objNewTimeEntry);
				}
				
				intCounter++;
			} else {
				blnLoop=false;
			}
		}
			
		insert lstTimeToEnter;
		populateTaskList();
		lstTimeToEnter.clear(); //clear them so we don't duplicate information the next time through

		PageReference pr = new PageReference('/apex/MainTaskListAndTimeEntry');
		return pr;
	}
}

 

 

eyewellseeyewellse

Hello Ruley,

 

Have you tried using the Apex Monitoring feature of salesforce to track what happens in your code?

(you can set a certain user to be monitored as they access VF pages, and capture the Trace of execution, including debug statements - go to Setup->Admin Setup->Monitoring->Debug Logs)

 

Have you tried adding Try{}Catch(){} statements, and System.Debug() statements, to your Apex, to see how far your execution gets?

 

Erik

RuleyRuley

I watched the logs and it just does another get on the list, doesn't act like it gets to the save at all.

goabhigogoabhigo

Hi,

 

After the PageReference pr = new PageReference('/apex/MainTaskListAndTimeEntry');

add,

pr.setRedirect(true);

return pr;

 

Add some System.debug() statements in your save() method and try saving a record(keep open your System Log). Check the log whether the System.debug() are executed.

 

What is 'MainTaskListAndTimeEntry' page? Is it the same VF page you posted here? I hope its not.

RuleyRuley

I have been playing around with this more, and added some debug statements, found that it wasn't getting into my save method at all when that button was clicked.

 

I added the setRedirect(true) line, but nothing happend, since it wasn't even getting into the save.

 

I also tried changing the name from save to saveInput on a suggestion from eyewells that it may not like a reserved word. But still nothing.

 

MainTaskListAndTimeEntry.page is the VF page that I posted. I want to come back to the same page I was on. Why would that be a problem? I've seen it done in other code examples and I don't understand why it would work for a user that is an admin versus another profile that is just the force.com free user.

goabhigogoabhigo

Hey check whether that user has got permission(in his profile) to 'create' object.

RuleyRuley

They do, if the user goes in to any of the objects normal page (the default one created when the object is created) they can add, edit and delete, without issue. So the rights on the object seem to be fine.