0

i got this visualforce page (i will only paste the relevant part) :

This is the first block of the page

<apex:pageBlock title="Data input" id="di" tabStyle="lead"> 
    <apex:outputPanel id="userLookup_ActiveUsers">
    <apex:pageBlockSection columns="6" id="UserSelection1">
        <apex:pageBlockSectionItem id="FromUser1" rendered="{!isNotSales}">
            <apex:outputLabel >Sales person:</apex:outputLabel>
            <apex:inputField value="{!auxFields.OwnerId}" id="SalesP" required="false"  />
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem id="StartDate">
            <apex:outputLabel >Since:</apex:outputLabel>
            <apex:inputField value="{!auxFields.StartDate}" required="false" id="StartD" />
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem id="EndDate">
            <apex:outputLabel >To:</apex:outputLabel>
            <apex:inputField value="{!auxFields.EndDate}" required="false" id="EndD" />
        </apex:pageBlockSectionItem>                
    </apex:pageBlockSection>
    </apex:outputPanel> 
    <apex:pageBlockButtons location="bottom"> 
        <apex:actionStatus id="loadingSearch" ><apex:facet name="start"><apex:image value="/img/loading.gif"/></apex:facet></apex:actionStatus>                   
        <apex:commandButton value="Refresh" action="{!doRefreshData}" id="removeButton" rerender="theForm" status="loadingSearch" oncomplete="reload();"/>
    </apex:pageBlockButtons>                   
</apex:pageBlock> 

First the field Ownerid was null by default but only System admins could see this page. Now they asked me to made it visible for salespeople too, but they can only see their own user stats.

What i did was to initialize the value on the controller with the current user and if the profile of the person isn't System admin put the rendered of this field to false.

This is controller's code that i modified:

public without sharing class ReportFunnelAnalysis {

    public Campaign auxFields                     {get;set;}
    public List<Decimal> grandTotals              {get;set;}
    public Map<String,DataObject> inboundSources  {get;set;}
    public Map<String,DataObject> outboundSources {get;set;} 

    public boolean isNotSales {get;set;}
    public User userloggedin {get;set;}

    public List<PieWedgeData> inboundRevenue      {get;set;}
    public List<PieWedgeData> outboundRevenue     {get;set;}    
    public List<PieWedgeData> allRevenue          {get;set;}

    public ReportFunnelAnalysis(){
        isNotSales = System.UserInfo.getProfileId()!='00eb0000000UqLg';
        auxFields = new Campaign(OwnerId=System.UserInfo.getUserId(), StartDate = Date.newInstance(System.today().year(), System.today().month(), 1), EndDate=System.today()); 
        doRefreshData();
    }

The Ownerid of the campaign wasn't declared before the change request so it was initialized to null.

But this had a collateral effect, which was that now i can't edit dates. I paste screencaps: Before editing for sales people: http://puu.sh/l2XW3/ef6ce20e62.png

Now: http://puu.sh/l2Y5X/66929ddb10.png

Why did the Date fields were affected by the changes in code? if i only edited the rendered blocksection items related to the owner?

Which way would you do it so the admins can search for any user and salesperson can only see their own but being able to edit dates?

2
  • 1
    most probably the role hierarchy causing this effect. Provide read permission for user object and edit permissions for date fields (Field level security). – Ashwani Oct 30 '15 at 8:16
  • They have Edit permission for that Date fields for the Campaign object. They can't edit the date fields tho. – Alexander Aeons Torn Oct 30 '15 at 9:45
0

It was related to the fact that they hadn't market the user Detail Checkbox 'Marketing User'. So they couldn't take advantage of the Campaign object that was used on apex to store the 'Sales' person.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.