0

I am building a VF page for my custom object Change Request.

In my object trigger on Save, I populate the Manager field of the record with this code:

if (trigger.isBefore && (trigger.isInsert || trigger.isUpdate))
    {
          system.debug('step 3 - set Manager ID & department name');

          for (Request_for_System_Change__c r : Trigger.new) {

                  string LineManagerid = [SELECT Id, ManagerId from User where Id =: r.OwnerId].ManagerId;
                  string DeptName = [SELECT Id, Department from User where Id =: userinfo.Getuserid()].Department;
                  r.Manager__c = LineManagerId;  
                  r.Department_Name_String__c = DeptName;             
          }         
        }

an that works fine.

So now I am building a VF page I need to do something similar but in my extension class as currently it just shows the manager ID like this "Manager: 009w0000003LRsuAAZ".

So at the top of my VF page I have:

<apex:page id="ChangeRequest" StandardController="Request_for_System_Change__c" extensions="RequestForSystemChangeController"
           standardStylesheets="false" 
            showHeader="false"  >

and the field is defined like this:

<apex:pageBlockSectionItem>
    <apex:outputLabel value="Manager: "/>
        <apex:panelGrid columns="1">
            <apex:outputText value="{!get_Manager(Request_for_System_Change__c.Owner__c)}"/>
         </apex:panelGrid>
</apex:pageBlockSectionItem>

In my extension class I have this method to get the Manager from the User object:

public string get_Manager(string owner_id){
    string LineManagerid = [SELECT Id, ManagerId from User where Id =: owner_id].ManagerId;
//      string LineManagerid; // = [SELECT Id, ManagerId from User where Id =:ApexPages.currentPage().getParameters().get(‘Manager_id’)];
        string DeptName = [SELECT Id, Department from User where Id =: userinfo.Getuserid()].Department;
        return LineManagerId;  
                  //r.Department_Name_String__c = DeptName;    


}

But I am getting an error:

Unknown function get_Manager. Check spelling.

so what is the correct way to do this, and where am I going wrong?

1 Answer 1

1
<apex:outputText value="{!Manager}"/>

Few changes--

In your constructor

public class yourClassName{ 
private Request_for_System_Change__c objRequest_for_System_Change;
public  yourClassName(ApexPages.standardController stdCtrl){

objRequest_for_System_Change = (Request_for_System_Change__c)stdCtrl.getRecord();

}
public string getManager(){
    string LineManagerid = [SELECT Id, ManagerId from User where Id =: objRequest_for_System_Change.OwnerId].ManagerId;

        string DeptName = [SELECT Id, Department from User where Id =: userinfo.Getuserid()].Department;
        return LineManagerId;  
                  //r.Department_Name_String__c = DeptName;    


}
}

change get_Manager to getManager

Use standardController and assign the record to local variable for access the ownerID

3
  • Thanks, just one question, how would SalesForce know that !Manager means !getManager? Dec 29, 2015 at 17:17
  • I am getting an error Visualforce Error System.QueryException: List has no rows for assignment to SObject on ` Class.RequestForSystemChangeController.getManager: line 63, column 1 ` Dec 29, 2015 at 17:19
  • 1
    @OurManInBananas In salesforce. If we use get for any method It will accessible in controller. So for access we need use without get in VF page. .... have you added objRequest_for_System_Change = (Request_for_System_Change__c)stdCtrl.getRecord(); in constructor ?
    – Ratan Paul
    Dec 29, 2015 at 17:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .