So I am trying to create a VF page where it will be easy to manage multiples records of a related list at a time.

My problems are:

I don't know how to launch the page from a new button on the related list.

I am using a custom controller to manage the VF page, because I can create all the functions I wanted with it, but now I can't find a way to create a button or an action. I think it is because I don't use the standard cotroller on my VF page, nor do I use a recordSetVar. So my visalForce page isn't available when I want to use it.

I could use the URL method to launch the page, but I don't know what to write in the formula field to lauch the page. here is my controller constructor and VF page page component, also what my page looks like for now.

VF code:

 <apex:page controller="ProductRequestController" tabstyle="ProductRequest">

apex controller:

public class ProductRequestController {
    public pageReference recordPage {get; set;}
    public List<ProductRequestWrapper> deletedWrappers {get; set;}
    public Map<String, List<ProductrequestWrapper>> wrappers {get; set;}

     public ProductRequestController(ApexPages.StandardController controller) {
                recordPage = controller.view();
                wrappers = new Map<String, List<ProductrequestWrapper>>();
                deletedWrappers = new List<ProductRequestWrapper>();
                for (String str: getProductTypevalues()){
                    wrappers.put(str, new List<ProductrequestWrapper>());
                Project__c proj = (Project__c)controller.getRecord();
                Opportunity opp = (Opportunity)controller.getRecord();
                for(ProductRequest product : [SELECT Id, Product_Category__c FROM ProductRequest 
                                              WHERE Project__c = :controller.getId()
                                              OR Opportunity__c = :controller.getId()]) {
                                                  ProductRequestWrapper wrapper = new ProductRequestWrapper(wrappers.get(product.Product_Category__c).size(), product);

And my page: enter image description here

I am happy from what my page looks like and I dont want to change it, the add and clone buttons all works.

I want my related list to be on two object

I want to have the related list of productrequest on Opportunity and project, but how do I make it that the code will know how which of the lookup relationship to fill when I create a Productrequest on the two possible objects?

I know that I can't pass an argument to a custom controller, but how do I know what is the Id of the object record page from where I use the button to open the VF page?

and lastly

How to I close the page to go back to the record page from where I open the VF page?

I thougt that if my save method returned the pageReference, It could work, but I have my doubts and I cant test it while I dont know How to open my page from a record page

Here is my save method for now :

public pageReference save() {
        List<ProductRequest> productsRequested = new List<ProductRequest>();
        List<ProductRequest> productsDeleted = new List<productRequest>();
        for (List<ProductrequestWrapper> products : wrappers.values()) {
            for (ProductRequestWrapper wrap : products){
        for (ProductRequestWrapper wrap : deletedWrappers){
        try {
            upsert ProductsRequested;
        } catch(System.DMLException e) {
            return null;
        delete productsDeleted;
        return recordPage;

I know I ask a lot but I have been searching all this informations for 3 days straight and I cnt find anyone with a similar problem to mine. I will gladly accept any help that you offer to me

Thank you very much


Your Answer

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

Browse other questions tagged or ask your own question.