• sealless
  • NEWBIE
  • 0 Points
  • Member since 2011

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

I have replaced the standard layout (View detail) for a custom object with a Visualforce page

 

<apex:page standardController="Appointment__c">
    <apex:sectionHeader title="{!$ObjectType.Appointment__c.label}" subtitle="{!Appointment__c.Name}"/>
    <apex:pageBlock title="{!$ObjectType.Appointment__c.label} Detail">
        <apex:pageBlockSection showHeader="false" columns="1">
            <apex:outputField value="{!Appointment__c.Tutor_Name__c}"/>
            <apex:outputField value="{!Appointment__c.Student_Name__c}"/>           
        </apex:pageBlockSection>
     </apex:pageBlock>    
     <apex:relatedList list="Session_Reports__r"/>
</apex:page>

 Nothing very interesting - especially since I have cut this down for demonstration purposes.  Fields from the parent object are displayed, a related list is displayed.  This works.  Until...

 

Until I attempt to view this page as a user with a profile that has no access to the child object in the related list.  This user gets the following error message instead

 

'Session_Reports__r' is not a valid child relationship name for entity Appointment 

 

If I switch back to use the default layout constructed roughly in a similar manner - two fields and the same related list - the layout is displayed properly in all cases.  Users with access to the child object see the related list, users without no access to the child object see nothing at all (including no error message!).  This is exactly the behaviour I want to replicate using a VF page.  But I can not.

 

I have tried some tips found online - remove and re-add the related list in the layout in order to make the VF work was one of them and it made no difference - but have not succeeded in making this work. It seems like I have a fundamental misunderstanding of how this should work - I really expected to be able to put in apex:relatedList and have VF figure out if it could or could not display it based on the profile of the user.  Is that not the case?

 

Thanks for any advice you can provide.

Just getting started with unit testing a controller extension and I have found a lot of good tips on this board.  I'm still not so sure I understand a testing pattern I see frequently.  Namely, the creation of the PageReference object.  For example here is a simplified version of my extension

 

public class AppointmentControllerExtension {
    
    private ApexPages.StandardController standardController;
    private final Appointment__c appointment;
    
    public AppointmentControllerExtension (ApexPages.StandardController stdController) {
        this.appointment = (Appointment__c)stdController.getRecord();
        this.standardController = stdController;
     }
     
    public String getStudentName() {
    
        String studentName = 'Not Found';
        
        if (appointment.Student__c != null ) {
            Student__c student = [SELECT First_Name__c, Last_Name__c
                                    FROM Student__c
                                   WHERE Id = :appointment.Student__c];
            if (student != null) {
                studentName = student.First_Name__c + ' ' + student.Last_Name__c; 
            }   
        }
        return studentName;
    
    }
    
}

 And the corresponding test class

 

@istest
public class AppointmentControllerExtensionTest {
          
    public static testmethod void testStudentName() {
        
        String firstName = 'First';
        String lastName  = 'Last';
        Student__c student = new Student__c(First_Name__c = firstname, Last_Name__c = lastName);
        insert student;
        
        Appointment__c appointment = new Appointment__c(Student__c = student.Id); 
        insert appointment;
        
        // Instantiate VisualForce Page - but why?
        
        //PageReference pg = Page.Appt_New;
        //Test.setCurrentPage(pg);
        //ApexPages.currentPage().getParameters().put('id', appointment.id);
        
        // Instantiate custom Controller
        
        ApexPages.StandardController stc = new ApexPages.StandardController(appointment);
        AppointmentControllerExtension ae = new AppointmentControllerExtension(stc);
        
        // Test get method
        
        String studentName = ae.getStudentName();
        System.assertEquals(studentName, firstName + ' ' + lastName);
    
    }
   
}

 

I have commented out the references to PageReference and the test runs just fine.  So...what is it that I am missing when I don't include these three lines?  They must serve a purpose, right?

 

Thanks for any insights you can provide.

I have replaced the standard layout (View detail) for a custom object with a Visualforce page

 

<apex:page standardController="Appointment__c">
    <apex:sectionHeader title="{!$ObjectType.Appointment__c.label}" subtitle="{!Appointment__c.Name}"/>
    <apex:pageBlock title="{!$ObjectType.Appointment__c.label} Detail">
        <apex:pageBlockSection showHeader="false" columns="1">
            <apex:outputField value="{!Appointment__c.Tutor_Name__c}"/>
            <apex:outputField value="{!Appointment__c.Student_Name__c}"/>           
        </apex:pageBlockSection>
     </apex:pageBlock>    
     <apex:relatedList list="Session_Reports__r"/>
</apex:page>

 Nothing very interesting - especially since I have cut this down for demonstration purposes.  Fields from the parent object are displayed, a related list is displayed.  This works.  Until...

 

Until I attempt to view this page as a user with a profile that has no access to the child object in the related list.  This user gets the following error message instead

 

'Session_Reports__r' is not a valid child relationship name for entity Appointment 

 

If I switch back to use the default layout constructed roughly in a similar manner - two fields and the same related list - the layout is displayed properly in all cases.  Users with access to the child object see the related list, users without no access to the child object see nothing at all (including no error message!).  This is exactly the behaviour I want to replicate using a VF page.  But I can not.

 

I have tried some tips found online - remove and re-add the related list in the layout in order to make the VF work was one of them and it made no difference - but have not succeeded in making this work. It seems like I have a fundamental misunderstanding of how this should work - I really expected to be able to put in apex:relatedList and have VF figure out if it could or could not display it based on the profile of the user.  Is that not the case?

 

Thanks for any advice you can provide.

Just getting started with unit testing a controller extension and I have found a lot of good tips on this board.  I'm still not so sure I understand a testing pattern I see frequently.  Namely, the creation of the PageReference object.  For example here is a simplified version of my extension

 

public class AppointmentControllerExtension {
    
    private ApexPages.StandardController standardController;
    private final Appointment__c appointment;
    
    public AppointmentControllerExtension (ApexPages.StandardController stdController) {
        this.appointment = (Appointment__c)stdController.getRecord();
        this.standardController = stdController;
     }
     
    public String getStudentName() {
    
        String studentName = 'Not Found';
        
        if (appointment.Student__c != null ) {
            Student__c student = [SELECT First_Name__c, Last_Name__c
                                    FROM Student__c
                                   WHERE Id = :appointment.Student__c];
            if (student != null) {
                studentName = student.First_Name__c + ' ' + student.Last_Name__c; 
            }   
        }
        return studentName;
    
    }
    
}

 And the corresponding test class

 

@istest
public class AppointmentControllerExtensionTest {
          
    public static testmethod void testStudentName() {
        
        String firstName = 'First';
        String lastName  = 'Last';
        Student__c student = new Student__c(First_Name__c = firstname, Last_Name__c = lastName);
        insert student;
        
        Appointment__c appointment = new Appointment__c(Student__c = student.Id); 
        insert appointment;
        
        // Instantiate VisualForce Page - but why?
        
        //PageReference pg = Page.Appt_New;
        //Test.setCurrentPage(pg);
        //ApexPages.currentPage().getParameters().put('id', appointment.id);
        
        // Instantiate custom Controller
        
        ApexPages.StandardController stc = new ApexPages.StandardController(appointment);
        AppointmentControllerExtension ae = new AppointmentControllerExtension(stc);
        
        // Test get method
        
        String studentName = ae.getStudentName();
        System.assertEquals(studentName, firstName + ' ' + lastName);
    
    }
   
}

 

I have commented out the references to PageReference and the test runs just fine.  So...what is it that I am missing when I don't include these three lines?  They must serve a purpose, right?

 

Thanks for any insights you can provide.

Is it possible to access via apex the object icon url similar to the describeTabs() call for the Metatdata api? DescribeTabs is only for external application calls.

 

I can't seem to find anything out there that would allow a developer access to the icon via apex or visualforce.

 

Any help would be much appreciated.

 

Thank you.