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
MelliottMelliott 

Help with getting a field

I have an object off called release that is a child to the account and to the opportunity.  The button envokes the VF page from the opportunity and passes the opportunityid to the page on the object release.  How the heck can I fill in the account field on release with the opportunity account.  Driving me batty. Here is my custom controller. 

 

public with sharing class RequestController {
    // steps
    public String requesttype {get {return 'Request';}}

    public String requestproduct {get {return 'Request Product';}}
  
    public String step {get; set;}
    public String step2 {get; set;}



    public RFP_Request__c Request {get; set;}
                                        

    // return URL
    private String retUrl;

    public RequestController() {
        step = requesttype;
        step2 = requestproduct;

        
        ID OpportunityId = ApexPages.currentPage().getParameters().get('OpportunityId');


            Request = new RFP_Request__c(Opportunity__c = OpportunityId); // i know it needs to go here but how the heck do I map it...

            if (OpportunityId!= null)
                retUrl = '/' + OpportunityId;
        }
    

    public PageReference cancel() {

        if (retUrl != null)
            return new PageReference(retUrl);
     
        else
            return null;
    }
    
    public PageReference save() {

        upsert request ;
        return null; 
    }

    public PageReference step1() {
        // show step 1 page
       return Page.requesttype;
     
    }
    
   
    
public PageReference step2() { logic here
    
      
    }    
    
    else
    
    return Page.requestproduct;

        
    }
    
public PageReference step3() {//lots of logic here
    
    
        
    }         
    
   
    
    
    

    
    
    
private Boolean isRequestValid() {

        if (Request.RFP_Request__c == false && 
        Request.RFC_Request__c == false && 
        Request.Training_Request__c == false &&  
        Request.Service_Request__c == false )
             
            return false;


        else

            return true;
  }      
    
    
}

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

It should just be a matter of querying the opportunity detail and using that.

 

E.g.

 

   ID OpportunityId = ApexPages.currentPage().getParameters().get('OpportunityId');


   Request = new RFP_Request__c(Opportunity__c = OpportunityId);
   
   if (OpportunityId!= null)
   {
        Opportunity opp=[select id, AccountId from Opportunity where id=:OpportunityId];
        Request.Account__c = opp.AccountId; 

        retUrl = '/' + OpportunityId;
   }

 

All Answers

bob_buzzardbob_buzzard

It should just be a matter of querying the opportunity detail and using that.

 

E.g.

 

   ID OpportunityId = ApexPages.currentPage().getParameters().get('OpportunityId');


   Request = new RFP_Request__c(Opportunity__c = OpportunityId);
   
   if (OpportunityId!= null)
   {
        Opportunity opp=[select id, AccountId from Opportunity where id=:OpportunityId];
        Request.Account__c = opp.AccountId; 

        retUrl = '/' + OpportunityId;
   }

 

This was selected as the best answer
raseshtcsraseshtcs

You just need to query the id of the account from the opportunity whose id you have.

accId=[Select AccountID from Opportunity where Id =: OpportunityId].Id;

Request = new RFP_Request__c(Opportunity__c = OpportunityId,Account__c=accId);



 

raseshtcsraseshtcs

Got it covered Bob....:smileyhappy:

MelliottMelliott

Thank you.  I was a long day.  It worked perfectly.