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
Synthia B.Synthia B. 

Apex Class - Compile Error: Didn't understand relationship

I am not sure why I am getting this error when attempting to create this class. 

Error: Compile Error: Didn't understand relationship 'Implementation_Task__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 18 column 26
 
public with sharing class ImplementationTaskReportCtrl 
{
    public String PLAN_YEAR_ID;
    public final String SHOW_IMPTS = 'show';
    
    public List<Implementation__c__c> Implementation{get;set;}
    public List<Implementation_Task__c> ImplementationTasks{get;set;}
    
    public ImplementationTaskReportCtrl ()
    {
        PLAN_YEAR_ID = Apexpages.currentPage().getParameters().get('Id');
        if( PLAN_YEAR_ID instanceof Id  ){intialize();}
        else{Apexpages.addMessage( new Apexpages.Message( ApexPages.Severity.ERROR, Label.Invalid_Id_Error ) );}
    }
    
    private void intialize()
    {
        Implementation = [ SELECT Id, Name, Total_Required_Tasks__c, Plan_Year_1__c, Percent_Complete__c, Completed_Tasks__c, 
                                                        ( SELECT Name, Completed__c, Completed_Date__c, Due_Date__c, Current_Notes__c, Historical_Notes__c FROM Implementation_Task__r WHERE In_Reports__c = :SHOW_IMPTS ORDER BY Due_Date__c ) 
                            FROM Implementation__c 
                            WHERE Plan_Year_1__c = :PLAN_YEAR_ID ];
                                                    
        if( Implementation == NULL || Implementation.isEmpty() )
        {
            Apexpages.addMessage( new Apexpages.Message( ApexPages.Severity.ERROR, Label.No_Plan_Year_Related_IMPs_Error ) );
        }
        else
        {
            ImplementationTask = [ SELECT Name, Implementation__c, Completed__c, Completed_Date__c, Due_Date__c, Current_Notes__c, Historical_Notes__c FROM Implementation_Task__c 
                                        WHERE Implementation__c IN :Implementation AND ( Due_Date__c < TODAY OR Due_Date__c = THIS_WEEK ) AND Completed_Date__c = null 
                                        ORDER BY Due_Date__c ];
        }
    }
    
    public PageReference saveIMPTasksDueThisWeekAndStay ()
    {
        return save( ImplementationTask, false );
    }
    
    public PageReference saveIMPTasksDueThisWeekAndGoBack ()
    {
        return save( ImplementationTask, true );
    }
    
    public PageReference saveIMPTasksAndStay ()
    {
        List<Implementation_Task__c> IMPTasksToBeSaved = getAllIMPTasks();
        return save( IMPTasksToBeSaved, false );
    }
    
    public PageReference saveIMPTasksAndGoBack ()
    {
        List<Implementation_Task__c> IMPTasksToBeSaved = getAllIMPTasks();
        return save( IMPTasksToBeSaved, true );
    }
    
    private List<Implementation_Task__c> getAllIMPTasks ()
    {
        List<Implementation_Task__c> IMPTasksToBeSaved = new List<Implementation_Task__c>();
        for( Implementation__c aIMP : Implementation )
        {
            for( Implementation_Task__c aTask : aIMP.Implementation_Task__r )
            {
                IMPTasksToBeSaved.add( aTask );
            }
        }
        return IMPTasksToBeSaved;
    }
    
    private PageReference save ( List<Implementation_Task__c> IMPTasksToBeUpdated, Boolean goback )
    {
        try
        {
            update IMPTasksToBeUpdated;
        }
        catch ( Exception ex )
        {
            Apexpages.addMessage( new Apexpages.Message( ApexPages.Severity.ERROR, ex.getMessage() ) );
            return NULL;
        }
        return ( goback ?  back () : stay() );
    }
    
    public PageReference back()
    {
        return new PageReference ( '/' + PLAN_YEAR_ID );
    }
    
    private PageReference stay()
    {
        intialize();
        return NULL;
    }


Thanks in advance!
Best Answer chosen by Synthia B.
Neetu_BansalNeetu_Bansal
Hi Synthia,

The error seems that you you have not create the custom label: No_Plan_Year_Related_IMP_Error.

Go to custom labels and create with the same name. It will resolve the issue. Let me know, if you have any other issue.

Thanks,
Neetu

All Answers

Neetu_BansalNeetu_Bansal
Hi Synthia,

At line no. 18, replace your query like this:
Implementation = [ SELECT Id, Name, Total_Required_Tasks__c, Plan_Year_1__c, Percent_Complete__c, Completed_Tasks__c, 
                                                        ( SELECT Name, Completed__c, Completed_Date__c, Due_Date__c, Current_Notes__c, Historical_Notes__c FROM Implementation_Tasks__r WHERE In_Reports__c = :SHOW_IMPTS ORDER BY Due_Date__c ) 
                            FROM Implementation__c 
                            WHERE Plan_Year_1__c = :PLAN_YEAR_ID ];
As you need to use child relationship name.

Let me know, if you need any other help.

Thanks,
Neetu
Gupta.VishalGupta.Vishal
Hi ,

yes Neetu is correct you have to use the child relationship name , while doing parent to child relationship queries . 

Thanks , 
vishal 
Synthia B.Synthia B.
I am getting error Invalid external string name: no_plan_year_related_imp_error
 
public with sharing class ImplementationTaskReportCtrl 
{
    public String PLAN_YEAR_ID;
    public final String SHOW_IMPTS = 'show';
    
    public List<Implementation__c> Implementation{get;set;}
    public List<Implementation_Task__c> ImplementationTasks{get;set;}
    
    public ImplementationTaskReportCtrl ()
    {
        PLAN_YEAR_ID = Apexpages.currentPage().getParameters().get('Id');
        if( PLAN_YEAR_ID instanceof Id  ){intialize();}
        else{Apexpages.addMessage( new Apexpages.Message( ApexPages.Severity.ERROR, Label.Invalid_Id_Error ) );}
    }
    
    private void intialize()
    {
        Implementation = [ SELECT Id, Name, Total_Required_Tasks__c, Plan_Year_1__c, Percent_Complete__c, Completed_Tasks__c, 
                                                        ( SELECT Name, Completed_Date__c, Due_Date__c, Current_Notes__c, Historical_Notes__c FROM Implementation_Tasks__r WHERE In_Reports__c = :SHOW_IMPTS ORDER BY Due_Date__c ) 
                            FROM Implementation__c 
                            WHERE Plan_Year_1__c = :PLAN_YEAR_ID ];
                                                    
        if( Implementation == NULL || Implementation.isEmpty() )
        {
            Apexpages.addMessage( new Apexpages.Message( ApexPages.Severity.ERROR, Label.No_Plan_Year_Related_IMP_Error ) );
        }
        else
        {
            ImplementationTasks = [ SELECT Name, Implementation__c, Completed_Date__c, Due_Date__c, Current_Notes__c, Historical_Notes__c FROM Implementation_Task__c 
                                        WHERE Implementation__c IN :Implementation AND ( Due_Date__c < TODAY OR Due_Date__c = THIS_WEEK ) AND Completed_Date__c = null 
                                        ORDER BY Due_Date__c ];
        }
    }
    
    public PageReference saveIMPTasksDueThisWeekAndStay ()
    {
        return save( ImplementationTasks, false );
    }
    
    public PageReference saveIMPTasksDueThisWeekAndGoBack ()
    {
        return save( ImplementationTasks, true );
    }
    
    public PageReference saveIMPTasksAndStay ()
    {
        List<Implementation_Task__c> IMPTasksToBeSaved = getAllIMPTasks();
        return save( IMPTasksToBeSaved, false );
    }
    
    public PageReference saveIMPTasksAndGoBack ()
    {
        List<Implementation_Task__c> IMPTasksToBeSaved = getAllIMPTasks();
        return save( IMPTasksToBeSaved, true );
    }
    
    private List<Implementation_Task__c> getAllIMPTasks ()
    {
        List<Implementation_Task__c> IMPTasksToBeSaved = new List<Implementation_Task__c>();
        for( Implementation__c aIMP : Implementation )
        {
            for( Implementation_Task__c aTask : aIMP.Implementation_Task__r )
            {
                IMPTasksToBeSaved.add( aTask );
            }
        }
        return IMPTasksToBeSaved;
    }
    
    private PageReference save ( List<Implementation_Task__c> IMPTasksToBeUpdated, Boolean goback )
    {
        try
        {
            update IMPTasksToBeUpdated;
        }
        catch ( Exception ex )
        {
            Apexpages.addMessage( new Apexpages.Message( ApexPages.Severity.ERROR, ex.getMessage() ) );
            return NULL;
        }
        return ( goback ?  back () : stay() );
    }
    
    public PageReference back()
    {
        return new PageReference ( '/' + PLAN_YEAR_ID );
    }
    
    private PageReference stay()
    {
        intialize();
        return NULL;
    }
    }

And Error: Unknown property 'String.ID'


 
<apex:page id="IMPTaskReport" controller="ImplementationTaskReportCtrl" sidebar="True" >

    <style type="text/css">
          div.pbSubheader{
            color:black !important;
            }
          .textArea-currentNotes-pbt { resize: none; width: 85%; }
    </style>
    <script>

        function setFocusOnLoad() {}
    </script>   
    <apex:PageMessages id="msgs"/>


<!-- <apex:includeScript value="{!$Resource.sorttableJS}"/>  -->

<apex:form >
        <apex:pageBlock title="Implementation Tasks Due This Week">
            <apex:PageBlockButtons >
                <apex:commandButton value="Save and Close" action="{!saveIMPTasksDueThisWeekAndGoBack}" rerender="msgs"/>
                <apex:commandButton value="Save and Stay" action="{!saveIMPTasksDueThisWeekAndStay}" rerender="msgs, pb, pbt-1"/>
                <apex:commandButton value="Close" action="{!back}"/>
            </apex:PageBlockButtons>
            <apex:pageBlockTable id="pbt-1" value="{!ImplementationTasks}" var="impTask">
                <apex:column headerValue="{!$ObjectType.Implementation_Task__c.fields.name.label}" width="15%">
                             <apex:outputLink value="/{!IMPTask.ID}" target="_blank"> {!IMPTask.name} </apex:outputLink>
                </apex:column>
                <apex:column value="{!IMPTask.Implementation__c}" width="10%"/>
                <apex:column value="{!IMPTask.Activity__c}" width="10%"/>
                <apex:column headerValue="{!$ObjectType.Implementation__c_Task__c.fields.Completed_Date__c.label}" width="5%">
                    <apex:inputField value="{!IMPTask.Completed_Date__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Implementation__c_Task__c.fields.Due_Date__c.label}"  width="10%">
                    <apex:inputField value="{!impTask.Due_Date__c}" />
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Implementation__c_Task__c.fields.Current_Notes__c.label}" >
                    <apex:inputTextArea rows="3" value="{!IMPTask.Current_Notes__c}"  styleClass="textArea-currentNotes-pbt"/>
                </apex:column>
                <apex:column headerValue="{!$ObjectType.Implementation_Task__c.fields.Historical_Notes__c.label}" >
                    <apex:inputTextArea disabled="true" rows="3" value="{!IMPTask.Historical_Notes__c}" styleClass="textArea-currentNotes-pbt" />
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
        &nbsp;
        &nbsp;
        &nbsp;
        &nbsp;

        <apex:pageBlock id="pb" title="Plan Year Related Implementation Tasks">
            <apex:PageBlockButtons >
                <apex:commandButton value="Save and Close" action="{!saveIMPTasksAndGoBack}"  rerender="msgs"/>
                <apex:commandButton value="Save and Stay" action="{!saveIMPTasksAndStay}" rerender="msgs, pbt-1, pb "/>

                <apex:commandButton value="Close" action="{!back}"/>
            </apex:PageBlockButtons>

             <apex:repeat id="rpt" value="{!Implementation}" var="IMP">
             <apex:pageBlockSection title="Title" collapsible="true" rendered="false"/>
                <apex:pageBlockSection title="{!IMP.Name} : {!$ObjectType.Implementation__c.fields.Completed_Tasks__c.label}: {!IMP.Completed_Tasks__c}, {!$ObjectType.Implementation__c.fields.Total_Required_Tasks__c.label}: {!IMP.Total_Required_Tasks__c}, {!$ObjectType.Implementation__c.fields.Percent_Complete__c.label}: {!IMP.Percent_Complete__c}"
                                            columns="1"  collapsible="true">

                    <apex:pageBlockTable id="IMPtable" value="{!sos.Implementation_Task__r}" var="IMPTask">
                        <apex:column headerValue="{!$ObjectType.Implementation_Task__c.fields.name.label}" width="15%">
                             <apex:outputLink value="/{!IMPTask.ID}" target="_blank"> {!IMPTask.name} </apex:outputLink>
                        </apex:column>
                        <apex:column value="{!IMPTask.Activity__c}" width="15%"/>
                        <apex:column headerValue="{!$ObjectType.Implementation_Task__c.fields.Completed_Date__c.label}"  width="5%">
                            <apex:inputField value="{!IMPTask.Completed_Date__c}" />
                        </apex:column>
                        <apex:column headerValue="{!$ObjectType.Implementation_Tasks__c.fields.Due_Date__c.label}"  width="9%">
                            <apex:inputField value="{!IMPTask.Due_Date__c}" />
                        </apex:column>
                        <apex:column headerValue="{!$ObjectType.Implementation_Tasks__c.fields.Current_Notes__c.label}" width="28%">
                            <apex:inputTextArea rows="3" value="{!IMPTask.Current_Notes__c}"  styleClass="textArea-currentNotes-pbt"/>
                        </apex:column>
                        <apex:column headerValue="{!$ObjectType.Implementation_Task__c.fields.Historical_Notes__c.label}" width="28%">
                            <apex:inputTextArea disabled="true" rows="3" value="{!IMPTask.Historical_Notes__c}" styleClass="textArea-currentNotes-pbt" />
                        </apex:column>
                    </apex:pageBlockTable>
                </apex:pageBlockSection>

             </apex:repeat> 
             </apex:pageBlock>      
   </apex:form> 
 </apex:page>

 
Neetu_BansalNeetu_Bansal
Hi Synthia,

The error seems that you you have not create the custom label: No_Plan_Year_Related_IMP_Error.

Go to custom labels and create with the same name. It will resolve the issue. Let me know, if you have any other issue.

Thanks,
Neetu
This was selected as the best answer