function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kristi GrayKristi Gray 

Help with Apex

When a project manager puts together a proposal, they can click on a button to create a pdf document of that proposal. We have Services as an object which contains all services that are available to project managers to add to proposals. The Services have a short description that is included on the proposal. The proposal has Selected Services where the PM has selected specific Services for their proposal. Sometimes the PM wants to change the short description to customize their proposal. So instead of the pdf document displaying the Services' short description, I need it to display the custom description on the Selected Service. They have requested that this custom description be displayed in a separate table on the pdf below the table with the normal short description. However, when I change the code on the pdf document to use the custom description field, I get an error. Here is the code. What am I doing wrong? The part that I have in bold I have changed to !NoPhases.Custom_Description__c but then the pdf no longer works.

<apex:outputPanel rendered="{!Opportunity.Total_Phase_1_Sel_Services__c = 0}"> <table width="100%" style="border-collapse:collapse;"> <tr style="page-break-inside:avoid;"> <td width="40%" style="background:#808080;border: thin black solid;text-align:center;"><b>Services</b></td> <td width="60%" style="background:#808080;border: thin black solid;text-align:center;"><b>Deliverables</b></td> </tr> <apex:repeat var="NoPhases" value="{!selectedServices}"> <tr style="page-break-inside:avoid;"> <td style="background:#D9D9D9;border: thin black solid;text-align:left;padding-left:10px;">{!NoPhases.Service__r.Name}</td> <td style="background:#D9D9D9;border: thin black solid;text-align:left;padding-left:10px;"><apex:outputfield value="{!NoPhases.Service__r.Deliverables__c}"/></td> </tr> </apex:repeat> </table> </apex:outputPanel>
Best Answer chosen by Kristi Gray
Alain CabonAlain Cabon
Hello,

You should post the controller or the extension used by the apex page (first line). 

A common error is a missing field inside the SOQL query (here NoPhases.Service__r.Deliverables__c ) but the error is clear during the compilation.

What is the error?

All Answers

Alain CabonAlain Cabon
Hello,

You should post the controller or the extension used by the apex page (first line). 

A common error is a missing field inside the SOQL query (here NoPhases.Service__r.Deliverables__c ) but the error is clear during the compilation.

What is the error?
This was selected as the best answer
Kristi GrayKristi Gray
Here is the first line in the document

<apex:page standardController="Opportunity" extensions="PDFDocumentController" showHeader="false" sidebar="false" renderAs="pdf">

Here is the error I get

SObject row was retrieved via SOQL without querying the requested field: Selected_Service__c.Custom_Description__c 

 
Kristi GrayKristi Gray
I apologize as I am REALLY new to this! Does this mean that within the controller I need to add this field (Custom_Description__c) within the Selected Services. Here is where I found the fields listed within the controller

 @TestVisible private List<Selected_Service__c> getRelatedSelectedServices(){
    List<Selected_Service__c> relatedSelectedServices = new List<Selected_Service__c>();

    try{
      relatedSelectedServices = [select Id, Name, Total_Price__c, Service_Billing_Description__c, Service__c, Service__r.Name, Discount__c, Discounted_Price__c, Service__r.Deliverables__c, Service__r.Full_Description__c, Service__r.Summary_Description__c, Start_Date__c, End_Date__c, Phase__c, Quantity_Term__c from Selected_Service__c where Project__c = :property.Id];
    }
    catch(QueryException qe){
      system.debug(qe.getMessage());
    }

    return relatedSelectedServices;
  }

  @TestVisible private List<Selected_Service__c> getServicesByPhase(String phase){
    List<Selected_Service__c> relatedSelectedServices = new List<Selected_Service__c>();

    try{
      relatedSelectedServices = [select Id, Name, Total_Price__c, Service_Billing_Description__c, Service__c, Service__r.Name, Discount__c, Discounted_Price__c, Service__r.Deliverables__c, Service__r.Full_Description__c, Service__r.Summary_Description__c, Start_Date__c, End_Date__c, Phase__c, Quantity_Term__c from Selected_Service__c where Project__c = :property.Id AND Phase__c = :phase];
    }
    catch(QueryException qe){
      system.debug(qe.getMessage());
    }

    return relatedSelectedServices;
  }
Alain CabonAlain Cabon
"Does this mean that within the controller I need to add this field (Custom_Description__c) within the Selected Services."
Yes. Correct.

Service__r.Deliverables__c is resolved.
Custom_Description__c is not resolved because it is missing in the queries.
  1)  relatedSelectedServices = [select Id, Name, Total_Price__c, Service_Billing_Description__c, Service__c, Service__r.Name, Discount__c, Discounted_Price__c, Service__r.Deliverables__c, Service__r.Full_Description__c, Service__r.Summary_Description__c, Start_Date__c, End_Date__c, Phase__c, Quantity_Term__c, Custom_Description__c from Selected_Service__c where Project__c = :property.Id];

   2)  relatedSelectedServices = [select Id, Name, Total_Price__c, Service_Billing_Description__c, Service__c, Service__r.Name, Discount__c, Discounted_Price__c, Service__r.Deliverables__c, Service__r.Full_Description__c, Service__r.Summary_Description__c, Start_Date__c, End_Date__c, Phase__c, Quantity_Term__c, Custom_Description__c from Selected_Service__c where Project__c = :property.Id AND Phase__c = :phase];

Regards
Kristi GrayKristi Gray
There is not an edit for the controller. How do I add this in there then?
Alain CabonAlain Cabon
1) Open the Developer Console

User-added image


2) File > Open ( CTRL+O )
3) Copy/paste the name of your controller (apex class) in the field "Filter" + button "Open"
4) Modify the queries
5) Save ( CTRL+S )

That's all.
Alain CabonAlain Cabon
or  simpler : Setup > Apex Class > [your controller] > button "Edit"

but it seems that you don't have access to this option for your profile (?)
Kristi GrayKristi Gray
I do not have the Edit button where my controller is located. I only see "Download", "Security", "Show Dependencies". When I went to the Developer console and tried to edit the controller, every time I entered anything on the page it gave me the message "Deployment Failed. Can't alter metadata in an active org". It did finally get all typed in there but then when I try to save it, it gives me the same message. What do I need to do to be able to save this? Thanks so much for all the help!
Kristi GrayKristi Gray
Am I able to add the Edit button within Setup > Apex Class > [your controller] > 
Alain CabonAlain Cabon
  1. You can’t modify Apex using the Salesforce user interface in a Salesforce production org
  2. Permission to Write Apex Code: "Author Apex" under "Administrative Permissions" for the associated profile of the user.
  3. https://salesforce.stackexchange.com/questions/88687/permission-to-write-apex-code
Regards
Kristi GrayKristi Gray
I have the Author Apex checked under my profile but I still do not see an Edit button in Setup > Apex Class > [your controller] >
Is this because it is a production org? How do I go about being able to make the change on this controller then?