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
Zach AckermanZach Ackerman 

Expression cannot be assigned at line -1 column -1

Essentially if the product name is UH I want the plan package name to be set using Ultimate Health a space and the field armada plan package name. 

trigger PlanPackageNames on Plan__c (Before Insert) {
for (Plan__c Plan__c : Trigger.new)
{
IF(Plan__c.Product_Name__c=='UH')
{
Plan__c.Name='Ultimate Health'+' '+Plan__c.Armada_Plan_Package_Name__c;
            }
    }
    
}
Preya VaishnaviPreya Vaishnavi
Please check with the following code:

trigger PlanPackageNames on Plan__c (Before Insert) {
for (Plan__c plan: Trigger.new)
{
IF(plan.Product_Name__c=='UH')
{
plan.Name='Ultimate Health'+' '+plan.Armada_Plan_Package_Name__c;
            }
    }
    
}
Amit Chaudhary 8Amit Chaudhary 8
Please try to avoid the object name as variable name. Try below code
trigger PlanPackageNames on Plan__c (Before Insert) 
{
	for (Plan__c Plan : Trigger.new)
	{
		IF(Plan.Product_Name__c=='UH')
		{
			Plan.Name= 'Ultimate Health'+' '+Plan.Armada_Plan_Package_Name__c;
		}
	}
}
Let us know if this will help you

 
Zach AckermanZach Ackerman
The field I am trying to update is a standard required field. Does before insert allow me to update the field with the trigger? In my testing when I go to save the plan the error appears saying a value must be entered. 
Amit Chaudhary 8Amit Chaudhary 8
Above trigger will work for you.
But if you are trying to create the record from Salesforce UI (Means page layout) then you need to enter the value on page layout And After that your trigger logic will work and will update the Name field value.

NOTE:- When ever you want to update same record then you should use the Before Trigger.
 
Preya VaishnaviPreya Vaishnavi
Hi ,

If a field is required on the api level (you have set value is required in the field  on the custom field) you should enter some value to save it. If its on page layout level, you should not be able to save it while creating a record manually.I would prefer setting the custom field required on page layout level for your requirement