1

So I'm still very new to coding and Apex. I have a custom object called Invoice that is a part of a managed package that some users in my org do not have access to. So basically what I'm trying to do is build a visualforce page that gives them a window into viewing invoices without having to purchase extra licenses. They don't need to edit anything, they just need basic information from invoices. I created a very basic controller and VF page, but obviously it still doesn't work because they don't have access to invoices.

My Controller:

public class Test_SC_INV_VF_Controller {
private final Service_Call__c sc;
public Invoice__c inv;

public Test_SC_INV_VF_Controller(ApexPages.StandardController stdController) {
    this.sc = (Service_Call__c)stdController.getRecord();
}

public Invoice__c getInvoice() {
    inv = [select Id, Name, Invoice_Notes__c From Invoice__c 
                                where Service_Call__c = :sc.Id];

    return inv;
  }
}

My VF Page:

<apex:page standardController="Service_Call__c" extensions="Test_SC_INV_VF_Controller">
INV: {!invoice.name}
</apex:page>

I guess my question is, is there any way to save multiple values in strings in the controller and then pass them over to the VF page? Or will I have to create a getInvoiceName() method and another getInvoiceTotal() method and so on to get individual values to display on VF page?

Thanks in advance!

1 Answer 1

2

Add a getter and setter, and you can reference the invoice record directly.

public Invoice__c inv { get; set; }

...

{!inv.name}

You might consider making the query in your page's constructor. Never put a query that runs each time in a getter or setter method, because it can cause you to reach governor limits (i.e. your page can crash).

3
  • Thank you for that! I didn't know that, I will definitely look into putting the query in a constructor instead. My users still won't be able to see the invoice this way though right?
    – ad_rey
    Commented Aug 29, 2018 at 19:37
  • @ad_rey They can see only what you allow them to see. If they can't see the object/field, then you'd be better off creating a list of normal string fields (public string invoiceName { get; set; }), query the record, then assign the values to those fields (inv = [select ... from invoice__c...]; invoiceName = inv.name; etc).
    – sfdcfox
    Commented Aug 29, 2018 at 20:32
  • Yeah I had a feeling that's what I was going to have to do. Thank you so much!
    – ad_rey
    Commented Aug 29, 2018 at 21:52

You must log in to answer this question.

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