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
Timothy SmithTimothy Smith 

Trigger Code error - Expression cannot be assigned and Illegl assignment

Please help me solve the reason for the two errors:

Line 8: Expression cannot be assigned
Line 17: Illegal assignment from List to Id
 
trigger SelectVacationPackage on Vacation_Package__c (after insert, after update) {
	List<Vacation_Package__c> PackagesToUpdate = new List<Vacation_Package__c>();
    
    List<Vacation_Package__c> WorkingPackages = [SELECT Id, Package_Type__c, Sales_Company__c, Package_Status__c 
												  FROM Vacation_Package__c WHERE Id In :Trigger.New];
    
    for(Vacation_Package__c vp: WorkingPackages){        
            if(vp.Package_Type__c = 'Select' && vp.Package_Status__c = 'Active'){
      			 PackagesToUpdate.add(vp);
       		 }
	}

    for (Vacation_Package__c vsp : PackagesToUpdate){
        
        //Sales_Company__c is a Lookup field requiring an ID
        
        vsp.Sales_Company__c = [Select ID from Account WHERE Name = 'Upgrade Sales'];
    }

    
    if(PackagesToUpdate.size() > 0){
        update PackagesToUpdate;       
    }   
}

Thank you
Best Answer chosen by Timothy Smith
Ajeet Singh 259Ajeet Singh 259
vsp.Sales_Company__c = [Select ID from Account WHERE Name = 'Upgrade Sales'];

Query return list object. Here require an id of record. used instead of :-

vsp.Sales_Company__c = [Select ID from Account WHERE Name = 'Upgrade Sales'].Id;