You need to sign in to do that
Don't have an account?
Swetha A 5
how to pass parent objects's id to custom button dynamically
Hi All,
I have a custom button on task related list of Account Object.
The button contains the URL as:/apex/GetDynamoDBTasks?id={!Account.Id} Where GetDynamoDBTasks is a Visualforce page.
I want to pass id dynamically in place of {!Account.Id}. I mean as it is on Account object so I used, Account.Id. If I use this button On opportunity's task related list, it should take opportunity.Id and If I use it for contact, then the Id value should be contact.Id. That means the same custom button for all objects. How can I achieve this? Any solution or idea on this.
I have a custom button on task related list of Account Object.
The button contains the URL as:/apex/GetDynamoDBTasks?id={!Account.Id} Where GetDynamoDBTasks is a Visualforce page.
I want to pass id dynamically in place of {!Account.Id}. I mean as it is on Account object so I used, Account.Id. If I use this button On opportunity's task related list, it should take opportunity.Id and If I use it for contact, then the Id value should be contact.Id. That means the same custom button for all objects. How can I achieve this? Any solution or idea on this.
Hope this helps.
All Answers
yes, you have to create different list buttons on each object. the type of the button is select as url,and by using the merge field selector you can select the account record id.
Regards,
Sai Krishna Tavva.
Hope this helps.
I pasted your code but it is showing error. It is not showing my visualforce code. can you provide me some other solution please.
Thank you.
In the Url of the button you can add the parameters for the page like
/apex/GetDynamoDBTasks?accid={!Account.Id}&oppid={!Opportunity.id}&conid={!contact.id}
in the page controller of the "GetDynamoDBTask" page, you check with the parameter such as
if(apexpages.currentpage().getparameters().get('accid')!=null)
{
//you got the account record id. and assign it to the id of the variable you are using
}
if(apexpages.currentpage().getparameters().get('conid')!=null)
{
//you got the contact record id. and assign it to the id of the variable you are using
}
if(apexpages.currentpage().getparameters().get('oppid')!=null)
{
//you got the account opportunity id. and assign it to the id of the variable you are using.
}
Let me know , if you face any issues.
Regards,
Sai Krishna Tavva.
I am getting this error:
Invalid id: ClientDetail?id=00119000006doek
Error is in expression '{!GetItemRequest}' in component <apex:page> in page getdynamodbtasks: Class.getDynamoDBTaskList.GetItemRequest: line 16, column 1
I hope that is not a big deal. we can create 3 test methods which sets each parameter of the url in each method by using apexpages.currentpage().getparameters.put(string,string), and will call the method as usual.
let me know if i didnt answer to your question.
Regards,
Sai Krishna Tavva.
Please try below java script code on button. I tested below code in my developer org which is working fine
Let us knoow if this will help you
Reading the Id from the URL solution (suggested by Rajiv) will not work if there is any text after the Id in the URL, for example if the user has clicked on a related list link the URL will be something like /apex/GetDynamoDBTasks?id=00Qb000000KASjj#00Qb000000KASjj_RelatedHistoryList_target. You will need to limit the substring to 15 characters. Its still a nasty hack and if the URL format changes this will be broken (not likely i know, but url hacks risk being broken when you least expect it).
For the second approach of using JS (suggeted by Amit), you'll need to be careful on the order of your 'IF' blocks because on a Contact record the Account.Id will also exist - so you'll need to ensure your object if blocks order is tested thoroughly. You will have the same issue with custom objects that have Master-Detail relationships and you could have more that one Id populated that you are looking for. Be carefull of any new or change of object relationships in the future that may break the order of id checks.
Separate buttons is cleanest option, but depending on how many objects you want this on could make it unmanageable.
Just some thoughts!
Richard.
On the surface it appears that the component "ClientDetail" within '{!GetItemRequest}' is expecting someother ID.
@Tavva Sai Krishna, yeah 3 test methods are no big deal, but it is extra code. Right?
obviously , it is extra code but as we can see common code in all 3 methods we can wrap up the code in a single method and can call the method from the three methods.
Also, as @amit , using the same logic written in javascript will work , then we didnt have get chance to work on test class.
Regards,
Sai Krishna Tavva.
"...will not work if there is any text after the Id in the URL, for example if the user has clicked on a related list link the URL will be something like /apex/GetDynamoDBTasks?id=00Qb000000KASjj#00Qb000000KASjj_RelatedHistoryList_target.."
and update your code to: