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
BrandonLBrandonL 

Custom button to pull object records to a custom object

Hello all,

First, I will describe the objects I'm working with.

Custom Object (EDS)
Custom Object (Plans)
Standard Object - Opportunity

We have the EDS and Plans objects master detailed to the Opportunity object and a lookup relationship between Plans and EDS. I am attemping to build a button on the EDS object for the lookup to Plans so when a user clicks the button, all the Plans related to the opportunity will pull into the EDS related list. Has anyone worked on a similar project or know if this is even possible?  Please advise if any more info is needed, thanks!
James LoghryJames Loghry
Yes, this is possible.

What you would need is:
  • A Visualforce page, which uses the EDS object as a standard controller
  • An Apex class as an extension controller.  
  • The class would read the current EDS record, and then query for the Opportunity and related Plans records.
  • After querying for the plans records, it would update the lookup field(s).
The VF page either could be a simple form with a save button, or use the action attribute of <apex:page> to redirect back to the EDS detail page.

For more info, see here: http://andyinthecloud.com/2013/07/16/how-to-call-apex-code-from-a-custom-button/
Vivek_PatelVivek_Patel
Hi Brandon

You can create a Detail page button with execute Javascript option and put following code to execute the method from you class where you can perform any operation you want.

Code on execute javascript button -

{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}
sforce.apex.execute("YourClassName","YourMethodName",{});


Code for you class -

global class YourClassName{
    webservice static void YourMethodName(){
        // operation which you want to perform
    }
}

for step by step tutorial please refer -http://blog.shivanathd.com/2014/07/call-apex-class-from-custom-button-salesforce.html


Regards,
Vivek Patel.

Please like or mark as best answer if this answers you query to help others find the correct answer and improve the quality on the developer forum.
BrandonLBrandonL
So the reason why I've added a lookup is to pull in the "Plans" related list to the EDS object page layout.  An opportunity might contain multiple plans so my main objective is to click on the "Pull Plans" custom button on the EDS to populate any plans associated to the opportunity to the related list.  Does this change these recommendations?  Thanks.
BrandonLBrandonL
Can anyone provide a starting point for code? We may ask a developer to provide this button but I'll like to take a stab at it. Even if we don't use a button, I'd like to have a visualforce section in our EDS object to pull the plans associated to the opportunity. Thanks!