You need to sign in to do that
Don't have an account?
Lewis Blau
Related List Button To Select existing records
The scenario is as follows. On an Opportunity, I have a lookup to a custom object. The corresponding related list on the custom object has a 'New' button to create new Opportunities from the custom object. Users want to click a button on the related list that displays a screen to select an existing Opportunity and associate a selected Opportunity to the related list on the custom object.
Not sure if I got it right but here's one way to do it:
I based my example on Account object as I don't have your custom object. Replace Account by your custom object.
1-) Create a custom related list button in Opportunity as shown below:
2-) Add the url below to your button:
/apex/AssociateOpportunity?id={!Account.Id}
3-) Add the button to the Opportunity's related list in Account's page layout:
4-) Create a custom lookup field for Opportunity in Account (this is a trick to get the lookup field of Opportunity working in the Visualforce). This button won't be visible and will not be added to any layouts and won't include any related list.
5-) Create a controller class (I named it AssociateOpportunityExtController):
6-) Create a Visualforce (I named it AssociateOpportunity):
Access a account record and try the button to see if it works. That will do the magic. Let me know if you need further assistance and if it's worked.
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
All Answers
Not sure if I got it right but here's one way to do it:
I based my example on Account object as I don't have your custom object. Replace Account by your custom object.
1-) Create a custom related list button in Opportunity as shown below:
2-) Add the url below to your button:
/apex/AssociateOpportunity?id={!Account.Id}
3-) Add the button to the Opportunity's related list in Account's page layout:
4-) Create a custom lookup field for Opportunity in Account (this is a trick to get the lookup field of Opportunity working in the Visualforce). This button won't be visible and will not be added to any layouts and won't include any related list.
5-) Create a controller class (I named it AssociateOpportunityExtController):
6-) Create a Visualforce (I named it AssociateOpportunity):
Access a account record and try the button to see if it works. That will do the magic. Let me know if you need further assistance and if it's worked.
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
iam facing a similar issue. I already tried to customize your idea to solve my problems but somehow it is now working. I Hope somebody can help me out:
Iam trying to Add (existing) contacts on my object "Classes" i already have the releated list "CONTACTS" on this object but i cant figure out how to add existing contacts i only can create new contacts from list ...:(
Best regards
Sebastian
Sebastian,
Not sure where you are in the process, but if you follow step by step, you will create a page like this one below:
The custom list button on the Contact related list on Classes will display this page. The active Class record is defaulted and a lookup to contacts field allows a user to select and then 'Associate' existing contacts. The downside of the page is you can only associate one record at a time which was fine for my process. You could create a page that allows you to select more than one.
Hope this helps.
Lewis
Hello, i used the code provided by Zuinglio Lopes Ribeiro Júnior but i have an issue.
When I click on Assosiate button page just reloads without adding a record. I have two objects: ECS__eCommSource_Order__c and Vehicle__c. Can anybody help me?
Is there any way to use Lightning Aura pages instead of VF page in the above scenario. Please confirm.
Thanks