You need to sign in to do that
Don't have an account?

fetch child records in custom button javascript written on parent
Hi All,
Can we write SOQL inside button scripting to fetch child records. I tried something like below.
var reocrds = sforce.connection.query(here parent to child query) but it doesn't seem to be working.
Please help me know how can i do this.
Thanks.
Can we write SOQL inside button scripting to fetch child records. I tried something like below.
var reocrds = sforce.connection.query(here parent to child query) but it doesn't seem to be working.
Please help me know how can i do this.
Thanks.
var dataCheck = sforce.connection.query(here parent to child query);
var reocrds = dataCheck.getArray("records");
I tried below one and receiving error could not identify releationship. Please suggest.
var Products = sforce.connection.query("SELECT id, (SELECT Product_Name__c from Product_Selected__r WHERE Product_Name__c = 'Test') from Opportunity__c");
records = Products.getArray("records");
Here the requirement is if product selected with name =Test found then i need to give some alert message. I have th custom button on parent object.
Parent-> Opportunity__c
Child-> Product_Selected__c
Thanks.
Please click on lookup field on your object Product_Selected__c and then check your child relationship name
Please follow below step :-
1) open Product_Selected__c object
2) Then search for lookup field of opportunity.
3) Copy child relationship name and use that in your SOQL.
var Products = sforce.connection.query("SELECT id, (SELECT Product_Name__c from Product_Selected__r WHERE Product_Name__c = 'Test') from Opportunity__c");
records = Products.getArray("records");
(instead of Product_Selected__r use your child relationship name . For example - 'select id,( SELECT Name from Contacts) from account')
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks and Regards,
Sagar Jogi
I tried the same, since it is custom relationship i appended __r for the relationship name. Still i am receiving the below message when i click on button.
"Did not understand relationship 'Product_Selected' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names".
Any other suggestions?
Thanks.