+ Start a Discussion
DJP1SDJP1S 

Expression cannot be assigned

I'm trying to assign the date of a project parent object to the maximum date due of related child tasks.

I'm getting a "Save error: Expression cannot be assigned" error message based on the second variable setNewDueDate()

	P1Task__c maxTaskDate = [SELECT  Due__c							
						FROM Page1Task__c
						WHERE Project__c = :this.currentTask.Project__c 
						AND Status__c != '6) Completed'
					        AND Status__c != '5) Deferred'
						AND Seq__c > :this.currentTask.Seq__c
						AND Due_Date_Auto_Calc__c = 'Always'
						AND Lag_Days__c != null
						ORDER BY Seq__c DESC
						LIMIT 1];
    
	public void setNewDueDate(){
		if(P1Project__c.Due__c != maxTaskDate.Due__c){			
			P1Project__c.Due__c = maxTaskDate.Due__c;
			}
		}

 

Now, I've tried this as well and it doesn't like it either.

 

Best Answer chosen by Admin (Salesforce Developers) 
DJP1SDJP1S

Here's what I ended up doing. This seems to do the trick.

 

	public void setNewDueDate(){	
	P1Task__c maxTaskDate = [SELECT  Due__c							
					FROM P1Task__c
					WHERE Project__c = :this.currentTask.Project__c 
					AND Status__c != '6) Completed'
					AND Status__c != '5) Deferred'
					AND Due_Date_Auto_Calc__c = 'Always'
					AND Lag_Days__c != null
					ORDER BY Seq__c DESC
					LIMIT 1];
	P1Project__c project = [SELECT Due__c
					FROM P1Project__c
					WHERE ID = :this.currentTask.Project__c];
		if(project.Due__c != maxTaskDate.Due__c){			
			project.Due__c = maxTaskDate.Due__c;
			update project;
			}
		}

 

All Answers

ShaTShaT

Hi 

 

try this

 

public void setNewDueDate(){
		if(P1Project__c.Due__c != maxTaskDate.Due__c){			
			P1Project__c.Due__c = maxTaskDate[0].Due__c;
			}
		}
DJP1SDJP1S

Thanks, I thought that would hti the nail on the head, but I'm now getting the following error:

Save error: Expression must be a list type: SOBJECT:P1Task__c    

 



mohimohi

Can you post littile more code snippet,so that analyze the what you declaring and what you are assigning

Abhay AroraAbhay Arora
public void setNewDueDate(){
		if(P1Project__c.Due__c != maxTaskDate.get(0).Due__c){			
			P1Project__c.Due__c = maxTaskDate.get(0).Due__c;
			}
		}
Above will solve your issue . Please mark this as solved if this solves your issue
DJP1SDJP1S

Here's what I ended up doing. This seems to do the trick.

 

	public void setNewDueDate(){	
	P1Task__c maxTaskDate = [SELECT  Due__c							
					FROM P1Task__c
					WHERE Project__c = :this.currentTask.Project__c 
					AND Status__c != '6) Completed'
					AND Status__c != '5) Deferred'
					AND Due_Date_Auto_Calc__c = 'Always'
					AND Lag_Days__c != null
					ORDER BY Seq__c DESC
					LIMIT 1];
	P1Project__c project = [SELECT Due__c
					FROM P1Project__c
					WHERE ID = :this.currentTask.Project__c];
		if(project.Due__c != maxTaskDate.Due__c){			
			project.Due__c = maxTaskDate.Due__c;
			update project;
			}
		}

 

This was selected as the best answer