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
sfdc18sfdc18 

Compile Error: unexpected token: '='

Hi,

 

I want to access two child object record on vf page with standard controller of one child object.

Both the child object have same master object.

I want to override this visualforce page on edit button of one of the child.

 

I am getting following error: Error: FollowUpAssEditController Compile Error: unexpected token: '=' at line 20 column 20

 

my controller code is:

 

public class FollowUpAssEditController {

public Questionnaires__c questionnaires;
    public Clinical_History__c clinicalhistory;
    

    public FollowUpAssEditController(ApexPages.StandardController controller) {
    
     String id = ((Questionnaires__c)controller.getRecord()).id;
        this.questionnaires = [Select q.Has_Your_Snoring_Resolved_On_Treatment__c, q.Has_Your_Level_Of_Daytime_Sleepiness_Dec__c, q.Witnessed_Apnoeas__c,q.Any_Reports_Of_Mouth_Breathing_ByPartner__c, q.Dry_Mouth_Sore_Throat_In_The_Morning__c from Questionnaires__c q where q.id=:id];


    }
    
    String parent_id=Clinical_History__c.ParentId;
    
   // Id parentId = Clinical_History__c.Account__c;
    
   
    clinicalhistory = [Select c.Severity__c from Clinical_History__c c where c.id=:parent_id];
    
       public PageReference edit() {
        return null;
    }


    


    public Questionnaires__c getQuestionnaires() {
        return questionnaires;
    }
    
    public Clinical_History__c getclinicalhistory() {
        return clinicalhistory;
    }

    public PageReference save() {
        update questionnaires;
        return null;
    }


}

 

Kindly Help.

Regards,
Mayur

 

 

Sheikh Abrar Ul HaqSheikh Abrar Ul Haq

Mayur,

Please remove these below lines from the code and paste it in a constructor "FollowUpAssEditController" or in a method "edit()".

String parent_id=Clinical_History__c.ParentId;   
 // Id parentId = Clinical_History__c.Account__c;
 clinicalhistory = [Select c.Severity__c from Clinical_History__c c where c.id=:parent_id];


You cannot query something outside of the constructor and method in a class or controller.

Hope this helps.

asish1989asish1989

HI

Try this code

public class FollowUpAssEditController {

    public Questionnaires__c questionnaires{get;set;}
    public Clinical_History__c clinicalhistory{get;set;}
	public String id; 
	public String parent_id; 
    

    public FollowUpAssEditController(ApexPages.StandardController controller) {
    
		 id = ((Questionnaires__c)controller.getRecord()).id;
		 parent_id = Clinical_History__c.ParentId;   
      // Id parentId = Clinical_History__c.Account__c;
         clinicalhistory = [Select c.Severity__c from Clinical_History__c c where c.id=:parent_id];
      
    }
    
    public PageReference edit() {
        return null;
    }

    public PageReference save() {
		questionnaires = [Select q.Has_Your_Snoring_Resolved_On_Treatment__c, q.Has_Your_Level_Of_Daytime_Sleepiness_Dec__c, q.Witnessed_Apnoeas__c,q.Any_Reports_Of_Mouth_Breathing_ByPartner__c, q.Dry_Mouth_Sore_Throat_In_The_Morning__c from Questionnaires__c q where q.id=:id];
        update questionnaires;
        return null;
    }

 If this post answers your questions, please mark it as solved and give kudos if this helps you

 

Thanks

sfdc18sfdc18

Hi Asish,

 

I have used ur code

I have following error in the highlighted line.

 

Compile Error: Illegal assignment from Schema.SObjectField to String at line 12 column 10

 

 

my code:

 

public class FollowUpAssEditController {

    public Questionnaires__c questionnaires{get;set;}
    public Clinical_History__c clinicalhistory{get;set;}
    public String id;
    public String parent_id;
    

    public FollowUpAssEditController(ApexPages.StandardController controller) {
    
         id = ((Questionnaires__c)controller.getRecord()).id;
         parent_id = Clinical_History__c.Account__c;   
      // Id parentId = Clinical_History__c.Account__c;
         clinicalhistory = [Select c.Severity__c from Clinical_History__c c where c.id=:parent_id];
      
    }
    
    public PageReference edit() {
        return null;
    }

    public PageReference save() {
        questionnaires = [Select q.Has_Your_Snoring_Resolved_On_Treatment__c, q.Has_Your_Level_Of_Daytime_Sleepiness_Dec__c, q.Witnessed_Apnoeas__c,q.Any_Reports_Of_Mouth_Breathing_ByPartner__c, q.Dry_Mouth_Sore_Throat_In_The_Morning__c from Questionnaires__c q where q.id=:id];
        update questionnaires;
        return null;
    }
    
    }

 

 

Please Help.

 

Regards,

Mayur

sfdc18sfdc18

And my standard controller is Questionnaires__c.

Sheikh Abrar Ul HaqSheikh Abrar Ul Haq

Use this code:

 

parent_id = String.ValueOf (Clinical_History__c.Account__c);

 

asish1989asish1989

HI

Error is on this line

parent_id = Clinical_History__c.Account__c; 

Account__c is field of Clinical_History__c object, you are assigning that value to a string,

 

You need to make a query to fatch paerticular Clinical_History__c record  then you can assign value of Account__c  of that paerticular  Clinical_History__c 's record.

 

For example

Clinical_History__c clinichistory = [SELECT id, ...... FROM Clinical_History__c  WHERE some codition];

parent_id = clinichistory.Account__c; 

 

 If this post answers your questions, please mark it as solved and give kudos if this helps you

Thanks

 

sfdc18sfdc18

Hi Abrar,Asish,

 

I tried using ValueOf suggested by abrar.

Now that error is solved.

But i am getting System.QueryException: List has no rows for assignment to SObject  this error.

But problem is I can see record id in the url still i am getting this error.

 

Asish, Account__c is child relationship name.

Clinical History is child of Account obj.


My scenario is

 

                                                    Account.................................(Master Object)

                                                            |

                                                            |

                                                           / \

                                                          /    \

                                 Questionnaire    Clinical History..........(Child Objects)

 

I have vf page which is overridden on edit button of Questionnaire obj.


I want to fetch fields of both Questionnaire and Clinical History on this visualforce page.

That is why I tried to fetch parent account record id through String parent_id= String.ValueOf(Clinical_History__c.Account__c);  this statement.

 

Please Help.

 

Regards,

Mayur

asish1989asish1989

You said , you can see recordid in the url then whose object of reordoid it is?

you can get recordid by using 

 

 

Id = ApexPages.currentPage().getParameters().get('Id');

then make a query,

sfdc18sfdc18

Hi Asish,

 

I have modified my code as below but still it is giving same error on highlighted line.

 

public class FollowUpAssEditController {

    public Questionnaires__c questionnaires{get;set;}
    public Clinical_History__c clinicalhistory{get;set;}
    public String id;
    public String parent_id;
  //  public Id pid;
    

    public FollowUpAssEditController(ApexPages.StandardController controller) {
    
         id = ((Questionnaires__c)controller.getRecord()).id;
         questionnaires = [Select q.Has_Your_Snoring_Resolved_On_Treatment__c, q.Has_Your_Level_Of_Daytime_Sleepiness_Dec__c, q.Witnessed_Apnoeas__c,q.Any_Reports_Of_Mouth_Breathing_ByPartner__c, q.Dry_Mouth_Sore_Throat_In_The_Morning__c from Questionnaires__c q where q.id=:id];
      //   parent_id = String.ValueOf (Clinical_History__c.Account__c);
      //   pid = ApexPages.currentPage().getParameters().get('Id');
      // Id parentId = Clinical_History__c.Account__c;
       //  clinicalhistory = [Select c.Severity__c from Clinical_History__c c where c.id=:pid];
       clinicalhistory = [select Id ,Severity__c from Clinical_History__c where Id=:ApexPages.CurrentPage().getParameters().get('id')];
      
    }
    
    public PageReference edit() {
        return null;
    }

    public PageReference save() {
        
        update questionnaires;
        update clinicalhistory;
        return null;
    }
    
    }

 

 

 

asish1989asish1989

In the URL recordid must be Questionnaires__c type.

make sure before writing this line URL contains recordid of Clinical_History__c object.

I think recordid is not the valid one that's why non of records are fetched.

 

clinicalhistory = [select Id ,Severity__c from Clinical_History__c where Id=:ApexPages.CurrentPage().getParameters().get('id')];

 

 If this post answers your questions, please mark it as solved and give kudos if this helps you

 

  Thanks

 

 

 

Puja_mfsiPuja_mfsi

HI Mayur,

The Id in url is for "Questionnaires__c" and you put a query on "Clinical_History__c" 

as

clinicalhistory = [select Id ,Severity__c from Clinical_History__c where Id=:ApexPages.CurrentPage().getParameters().get('id')];

 

this query never gives any record because you match the id of "Clinical_History__c" with the current URL Id which is of "Questionnaires__c".

And the error "But i am getting System.QueryException: List has no rows for assignment to SObject  this error." is comes when you try to assign a query result to an Sobject variable in run time if the quesry is not returned any result.

To avoid the unexpected error in run time use "List<SObject>" to store the query result,Because if the query didn't give any result then it not give run time error.

like

List<Clinical_History__cclinicalhistory = [select Id ,Severity__c from Clinical_History__c where Id=:ApexPages.CurrentPage().getParameters().get('id')];

 

But first you need to check the ids of matching type in where condition.