You need to sign in to do that
Don't have an account?
Tanvi Kakkar
need to show data from unrelated objects on visualforce page .
Hi
I need to show data from unrelated object on visualforce page .
I have a standard object Opportunity and its related to custom object Unit Via Look up . Unit has a child objects - Other charges .
There is a custom button on Opportunity. On click of the button I need to show Other Charges Information .
Please Help .
Thanks in advance .
I need to show data from unrelated object on visualforce page .
I have a standard object Opportunity and its related to custom object Unit Via Look up . Unit has a child objects - Other charges .
There is a custom button on Opportunity. On click of the button I need to show Other Charges Information .
Please Help .
Thanks in advance .
You can fetch the details using SOQL
As per my understanding Both Opportunity and Other Charges are childs of UNIT.
In case I am wrong let me know.
In that case you can fetch the records as follows.
Assuming object name as Other_Charges__c
Relationship name from Other_Charges__c to Unit__c as chargeUnit__c
Relationship name from Opportunity to Unit as oppUnit__c
Select Id,Name from Other_Charges__c where chargeUnit__c =: oppUnit__r .Id
Thanks,
Mudasir
You can use this SOQL to get the results of the Other changes records.Select appropriate according to your object model.
//Use this when Opportunity is the Child, ie Opportunity has a lookup of Unit__c
list<Other_charges__C> otherChangesRecords = new list<Other_charges__C>();
for(Unit__c unit : [select Id,(Select Id from Other_charges__r) where Id =:Opportunity.Unit__c]){
otherChangesRecords.addAll(unit.Other_charges__r);
}
//Use this when Unit__c has the lookup of the Opportunity and Unit__c is the child
list<Other_charges__C> otherChangesRecords = new list<Other_charges__C>();
for(Unit__c unit : [select Id,(Select Id from Other_charges__r) where Opportunity__c =:Opportunity.Id]){
otherChangesRecords.addAll(unit.Other_charges__r);
}
Use appropriate relationshipNames in the above query .
I hope this solves your problem.
Thanks
Nitin