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

How to maintain URL state?



I have a controller InvoiceController that does two things:


1. initInvoice finds an object of type Invoice__c and stores it in InvoiceController.inv which is defined as 

public static Invoice__c inv {set; get;}



2. saveInvoice updates the Invoice__c object that we fetched in initInvoice. saveInoice is called when a user clicks a button on the VF page.



My question is - is there a way to keep the object somewhere between calls? When saveInvoice gets called, the  InvoiceController.inv is null , and I'd like it to be what we've loaded in initInvoice

Best Answer chosen by Admin (Salesforce Developers) 

Don't make it static. Static variables are also transient, which means they are not stored in the view state.