To generate a PDF with all related contacts of an Account record, you can create a Visualforce page with a controller that queries the related contacts and renders the output as a PDF. Then, you can add a custom button to the Account record page that navigates to the Visualforce page and generates the PDF.
public with sharing class AccountController {
public List<Contact> contacts { get; set; }
public Account account { get; set; }
public AccountController() {
// get the current Account record
account = [SELECT Id, Name FROM Account WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
// query the related contacts of the Account record
contacts = [SELECT Id, Name, Phone, Email FROM Contact WHERE AccountId = :account.Id];
}
}
Now Go to the Account object in Salesforce Setup> click on "Buttons, Links, and Actions"> Create a new custom button, and select "Visualforce Page" as the content source.
Choose the above created VF page you created and set the behavior to "Display in existing window without sidebar or header".
If this information helps, please mark the answer as best. Thank you
To generate a PDF with all related contacts of an Account record, you can create a Visualforce page with a controller that queries the related contacts and renders the output as a PDF. Then, you can add a custom button to the Account record page that navigates to the Visualforce page and generates the PDF.
Try below code
VF Page:
Controller class Now Go to the Account object in Salesforce Setup> click on "Buttons, Links, and Actions"> Create a new custom button, and select "Visualforce Page" as the content source.
Choose the above created VF page you created and set the behavior to "Display in existing window without sidebar or header".
If this information helps, please mark the answer as best. Thank you