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
Sandra WicketSandra Wicket 

Apex Controller: get id of parent record

Hello Guys,

i have created a simple custom controller to create multipe junction records.  The master object ist the opportunity object. Here is my Code

public class AddingBoostsController {

    public List<BoostOpp__c > BoostList {get;set;}
    public Integer rowNum{get;set;}

    public AddingBoostsController(){
        BoostList = new List<BoostOpp__c>();  
        BoostList.add(new BoostOpp__c()); 
            
    }
    
    public void insertBoost(){
        insert BoostList; 
    }
 
    public void insertRow(){
        BoostList.add(new BoostOpp__c()); 
    }
    
    
    public void delRow(){
        rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get('index'));
        BoostList.remove(rowNum);   
    }
}

A Javascript Button is calling the visualforce Page.  Now, i am looking for a solution to get the record id of the opportunity record to 

1. assign it each record in the list 
2. return to the master record, after the list is inserted 

Is there a way to use a javascript variable in the apex code ? 


Greetings Sandra
 
Best Answer chosen by Sandra Wicket
Sampath SuranjiSampath Suranji

Pass the Opportunity Id too when you click on javascript button to call the VF page
Then access the opportunity Id in the query string as you have used in delRow method
string opportunityId =  ApexPages.currentPage().getparameters().get('oppId');
Best regards
Sampath
 

All Answers

Sampath SuranjiSampath Suranji

Pass the Opportunity Id too when you click on javascript button to call the VF page
Then access the opportunity Id in the query string as you have used in delRow method
string opportunityId =  ApexPages.currentPage().getparameters().get('oppId');
Best regards
Sampath
 
This was selected as the best answer
Sandra WicketSandra Wicket
Thanks sampath. It works ! I defined the ' oppId' variable in my javascript button.