You need to sign in to do that
Don't have an account?
Kristi 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>
<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>
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
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?
<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
@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;
}
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
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.
but it seems that you don't have access to this option for your profile (?)
- You can’t modify Apex using the Salesforce user interface in a Salesforce production org
- Permission to Write Apex Code: "Author Apex" under "Administrative Permissions" for the associated profile of the user.
- https://salesforce.stackexchange.com/questions/88687/permission-to-write-apex-code
RegardsIs this because it is a production org? How do I go about being able to make the change on this controller then?