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

Cross object
Hello,
I have a custom object 'fattura__c' that has a look up relationship with a standard object 'quote' ;
'quote' has a master detail relationship with 'opportunity' and opportunity has a look up relationship with 'account'.
These are the steps: I select an opportunity, then in the opportunity's related list I select a quote, and in the quote's related list i select a fattura.
I have a visualforce page on 'fattura__c' and I want some of fattura's fields must be automatically populated, taking them directly from the account (fattura__c doesn't have any kind of link with Account).
How can i write this in an apex class?
Thanks a lot!
I have a custom object 'fattura__c' that has a look up relationship with a standard object 'quote' ;
'quote' has a master detail relationship with 'opportunity' and opportunity has a look up relationship with 'account'.
These are the steps: I select an opportunity, then in the opportunity's related list I select a quote, and in the quote's related list i select a fattura.
I have a visualforce page on 'fattura__c' and I want some of fattura's fields must be automatically populated, taking them directly from the account (fattura__c doesn't have any kind of link with Account).
How can i write this in an apex class?
Thanks a lot!
You could query and get all the fields from Account that you want and then use these fields on your visualforce page.
You need to query something like this :
Select id,name,quote__r.Opportunity__r.account.name from fattura__c
Here '__r' represent relationship, so if your lookup field api name is 'quote__c' then use 'quote__r' to access any field of Quote, similarly if quote has a lookup field whose API name is 'Opportunity__c', then you can access any field on Opportunity like 'quote__r.Opportunity__r' and similarly to access any 'Account' field you could traverse like : quote__r.Opportunity__r.account.anyfieldApiName.
Please let me know if this helps you!
Thanks,
Apoorv
All Answers
You could query and get all the fields from Account that you want and then use these fields on your visualforce page.
You need to query something like this :
Select id,name,quote__r.Opportunity__r.account.name from fattura__c
Here '__r' represent relationship, so if your lookup field api name is 'quote__c' then use 'quote__r' to access any field of Quote, similarly if quote has a lookup field whose API name is 'Opportunity__c', then you can access any field on Opportunity like 'quote__r.Opportunity__r' and similarly to access any 'Account' field you could traverse like : quote__r.Opportunity__r.account.anyfieldApiName.
Please let me know if this helps you!
Thanks,
Apoorv
I have written this query in my apex class:
List<fattura__c> fattlist = [SELECT Preventivo__r.Opportunity.Account.Percentuale_IVA_def__c, Preventivo__r.Opportunity.Account.Codice_IVA__c, Preventivo__r.Opportunity.Account.Note_esenzione_IVA__c FROM Fattura__c];
How can I write this in the visualforce page?
This is my section:
<apex:pageBlockSection title="Informazioni pagamento e IVA" collapsible="FALSE" >
<apex:inputField value="{!Fattura__c.Modalit_di_pagamento__c}"/>
<apex:inputField value="{!Fattura__c.Annotazioni__c}"/>
<apex:inputField value="{!Fattura__c.IVA__c }" required="true"/>
</apex:pageblockSection>
I want that custom fields 'Annotazioni__c' and 'IVA__c' are equal to account's fields 'Note_esenzione_IVA__c' and 'Percentuale_IVA_def__c'.
Thanks!
You will need to declare this 'fattlist' as an {get;set;} auto-property like:
public List<fattura__c> fattlist{get;set;}
then query the records and use this list on visualforce page through pageblockTable.
Below is the link that shows how to display data on visuaforce page using pageBlockTable:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_iteration_components.htm
Hope this helps!