You need to sign in to do that
Don't have an account?
Madhu007
How to Get the parent id from related list button
Hi,
I have a related list button on detail page. I have wriiten some java script code on the button. I want to gett the parent id on this button. Can you please tell me how can i get the id?
I have a related list button on detail page. I have wriiten some java script code on the button. I want to gett the parent id on this button. Can you please tell me how can i get the id?
E.g. if I'm trying to put a button on the Contact related list off the Account page, I'd do this:
alert('{!Account.Id}');
The account.id referenced will be from the parent object.
All Answers
E.g. if I'm trying to put a button on the Contact related list off the Account page, I'd do this:
alert('{!Account.Id}');
The account.id referenced will be from the parent object.
I tested it with three parents (Contact, CONTRACT, Opportunity), all having a Lookup relationship from the Attachment.
Here is what I did:
On the customer “Add Attachment” button, added this URL: {!URLFOR("/apex/PD_CustomAttachment?id=" +Contact.Id + Contract.Id + Opportunity.Id +
"&obj1=" + Contact.Id + "&obj2=" + Contract.Id + "&obj3=" + Opportunity.Id )}
In the controller, check to see which url variable is set and use it as a flag to determine the parent object type:
public PD_CustomAttachmentController(){
String contactId = ApexPages.currentPage().getParameters().get('obj1');
String CONTRACTId = ApexPages.currentPage().getParameters().get('obj2');
String opportunityId = ApexPages.currentPage().getParameters().get('obj3');
if(contactId != ''){
parentId = contactId;
parentType = 1;
}else if(CONTRACTId != ''){
parentId = CONTRACTId;
parentType = 2;
}else if(opportunityId !=''){
parentId = opportunityId;
parentType = 3;
}
}
Then in the code that saves the attachment, add the relationship reference from attachment to correct parent variable:
private Database.SaveResult saveCustomAttachment(){
Custom_Attachment__c obj = new Custom_Attachment__c();
if(parentType == 1){
obj.contact__c = parentId;
}else if(parentType == 2){
obj.CONTRACT__c = parentId;
}else if(parentType == 3){
obj.opportunity__c = parentId;
}
In visualforce page, just use my controller instead of standardController/extentioncontroller.
<apex:page controller="PD_CustomAttachmentController">