You need to sign in to do that
Don't have an account?
Larry D. Dortch
SOQL to filter Child records matched to Account
Hello Group,
I'm trying to create a simple inline VF page but not able to filter just the records I need.
I'm working with 3 objects = Accounts >Customer Visit >Visit Notes.
I just want to display the last 2 or 3 "Visit Notes" records when a new "Customer Visit" is created, so our Reps can more easily follow up on their action items.
Customer Visit is a Lookup to Accounts, and Visit Notes is a Master-Detail to Customer Visit.
Visit Notes also has a Lookup relationship to Accounts.
I've tried several different WHERE clauses but only to produce a variety of compiler errors.
Any help would be greatly appreciated!
I'm trying to create a simple inline VF page but not able to filter just the records I need.
I'm working with 3 objects = Accounts >Customer Visit >Visit Notes.
I just want to display the last 2 or 3 "Visit Notes" records when a new "Customer Visit" is created, so our Reps can more easily follow up on their action items.
Customer Visit is a Lookup to Accounts, and Visit Notes is a Master-Detail to Customer Visit.
Visit Notes also has a Lookup relationship to Accounts.
I've tried several different WHERE clauses but only to produce a variety of compiler errors.
Any help would be greatly appreciated!
I forgot to query the name field. Try it.
All Answers
Follow the steps provided in the below link
http://sfdcsrini.blogspot.com/2014/08/how-to-use-inline-visualforce-page.html.
Thanks,
Vasu
Let me get this right, You have Visit Notes which is the master(parent) to Customer Visit and Customer Visit which is a Parent(lookup) object to Accounts object. You have a lookup relation from Visit Notes to Account object. Am i right?
Now you need an inline VF page in Customer Visit object which will display the latest Visit Notes (2 records). Do you need any particular filter criteria while displaying this Visit notes records?
Please explain a little.
You're close. Everything is correct except Visit Notes is the (Detail) to Customer Visit the (Master).
So the hierarchy is: Accounts 1) Customer Visit 2) Visit Notes 3).
The filter criteria is to return only the Visit Notes records for the related Account.
Here is the code I'm using now that works great to display the 5 most recent Visit Notes records.
But when I try to add a WHERE clause such as, = to the AccountId or IN ('Account') I just get compiler errors.
So what I want to do is, when a new "Customer Visit" is created (display in the visualforce page) the last 2 or 3 "Visit Notes" records (created from the prior Customer Visits) that are specific to the 1 Account.
My reps visit their customers 1 once every week.
I tried the code but producing new errors.
In the WHERE clause: where accountid =: CustomerVisitRecord.accountid - I get compile error: Variable does not exist accountid
I changed accountid with the Lookup field name to Account 'Customer__c' - it compiles and I can Save but the visualforce page displays this error:
Content cannot be displayed: SObject row was retrieved via SOQL without querying the requested field: CustomerVisit__c.Customer__c
I searched around and tried a few things such as adding Customer__c to the SOQL and the VF but still get the same error.
Seems like this is very close to working. Any additional help you can offer is greatly appreciated.
Regards
The new code saved with no errors, but unfortunately - no records display in the visualforce page.
Also debug this formresults after SOQL statement in the apex code and check if you are getting results there.
formResults = [SELECT Id, Name, Visit_Comments__c,
from VisitNotes__c where Customer__c =: CustomerVisitRecordFinal.Customer__c ORDER BY CreatedDate DESC Limit 5];
system.debug('formResults'+formResults); //add this line
Regards
Could you use only the VF and the apex code i shared and see if you are displaying the names you wanted.
What do you meanby StoreVisitRecordFinal variable? Please share the VF and apex code you are using now.
You'll notice I added a line to debug the results of CustomerVisitRecordFinal and it's working well.
It does return the Id's for the Customer Visit (CustomerVisit__c) and related Account (Customer__c) record.
But debug for formResults is returning no data.
But the Account field on VisitNotes is a formula field (Text) using the formula (Customer_Visit__r.Customer__r.Name)
The 2nd SOQL saved but produced VF page error: Content cannot be displayed: SObject row was retrieved via SOQL without querying the requested field: CustomerVisit__c.Customer__r
I really appreciate all your help Eldon and if we get it working I owe you big time! :-)
I forgot to query the name field. Try it.
I also tried Customer__c.name but produced the same error.
I'll add the Visit Comments field to the VF page and let you know. :-)
Thank you so much for all your help!!!