+ Start a Discussion
Baguiar2Baguiar2 

Getparameters from current page not working

HI guys,

 

very simple class but it is not capturing the Opportunity__C (which is a master detail field to the Opportunity) id, to macth the Opportunity Line Items I want.  I have the exact same class for another object and it captures the object Id just fine. Not sure whats the issue here..

 

 

public class productsprojects
{
  private List<OpportunityLineItem> products;
  public List<OpportunityLineItem> getproducts()

    {
      products = [ SELECT product_name__c, Design__c, Development__c, Custom_Template_Category__c
                        FROM OpportunityLineItem 
                            WHERE OpportunityId = :System.currentPagereference().getParameters().get('Opportunity__c')  
            ];
            
      return products;
    }
}

 Thanks for the help!

B

 

Best Answer chosen by Admin (Salesforce Developers) 
Baguiar2Baguiar2

Found the issue... 

 

I ahev to query frst the Opportunity__C value as the custom field value can't be passed from the loaded page. here is the solution:

 

public class productsprojects
{
  Projects__C[] myproj = [ Select opportunity__C from Projects__C where id = :System.currentPagereference().getParameters().get('id') ];
  private List<OpportunityLineItem> products;
  public List<OpportunityLineItem> getproducts()

    {
  
      products = [ SELECT product_name__c, of_Tab_Launches__c, Design__c, Development__c, Custom_Template_Category__c, of_Custom_Templates__c 
                        FROM OpportunityLineItem 
                            WHERE OpportunityId = :myproj[0].opportunity__C  
            ];
            
      return products;
      
    }
    
}

 

All Answers

Devendra@SFDCDevendra@SFDC

 

Try,

 

OpportunityId = ApexPages.currentPage().getParameters().get('Id')

Thanks,

Devendra

Baguiar2Baguiar2

Nops.. didn't work.  If I enter the ID value itself, it works, so I'm sure the SOQL is fine. Just not getting the parameter from the page...

Devendra@SFDCDevendra@SFDC

 

What is the name of variable that you are passing as a Id to visualforce page?

 

Thanks,

Devendra

 

 

Baguiar2Baguiar2

It is not from a visualforce page actualy. I have a custom object built that has a field called  Opportunity__C, which is a master-detail to the Opportunity. So, this class is pulling all the Opportunitylineitems from te same opportnity that is on the loaded page for the custom object. 

 

So, I'm really just trying to get the Opportunity ID (which is the field Opportunity__C) from the current custom object , and pass it to the SOQL on the class.

 

Does that make sense. ?

 

Baguiar2Baguiar2

Found the issue... 

 

I ahev to query frst the Opportunity__C value as the custom field value can't be passed from the loaded page. here is the solution:

 

public class productsprojects
{
  Projects__C[] myproj = [ Select opportunity__C from Projects__C where id = :System.currentPagereference().getParameters().get('id') ];
  private List<OpportunityLineItem> products;
  public List<OpportunityLineItem> getproducts()

    {
  
      products = [ SELECT product_name__c, of_Tab_Launches__c, Design__c, Development__c, Custom_Template_Category__c, of_Custom_Templates__c 
                        FROM OpportunityLineItem 
                            WHERE OpportunityId = :myproj[0].opportunity__C  
            ];
            
      return products;
      
    }
    
}

 

This was selected as the best answer
Devendra@SFDCDevendra@SFDC

Great.!!

 

Cheers,

Devendra