+ Start a Discussion
cribiscribis 

Compile Error: Expression cannot be assigned at line -1 column -1

I am trying to write a trigger that will check the opportunity ownerid and returns fields from the owner's user record. but I am recieving the following error.

 

Compile Error: Expression cannot be assigned at line -1 column -1  

 

Here is my code:

 

trigger OpportunityOwnersAddress on Opportunity (before insert, before update) {

    Set<Id> UserIds = new Set<Id>();
    for (Opportunity oppo: Trigger.new){
    System.debug('**** 0 userids id : '+oppo.ownerid);
    
        UserIds.add(oppo.Id);
     System.debug('**** 1 oppo id : '+oppo.id);
     
     }
    
    Map<Id, User> entries = new Map<Id, User>( 
        [select Id, Street from User where id in :UserIds limit 1]);
  
    for(Opportunity unity: Trigger.new) {
       opportunity.Opp_Owner_Address__c = user.street;
    }
}

 

How can this be solved?

 

Thank you,

 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

Its saying that the list 'us' is empty, i.e. your query against User returned no rows, which will be a result of you adding the opportunity Id (i.e. oppo.id) to the UserIds set, rather than oppo.ownerId

All Answers

SuperfellSuperfell

the last loop is wrong, you have unity as the loop variable in the for, but opportunity as the variable inside the loop. Also you reference user.street, and user isn't defined.

cribiscribis

Thank you for your help. A follow-up question:

 

I have changed the code to:

trigger OpportunityOwnersAddress on Opportunity (before insert, before update) {

    Set<Id> UserIds = new Set<Id>();
    for (Opportunity oppo: Trigger.new){
    System.debug('**** 0 userids id : '+oppo.ownerid);
    
        UserIds.add(oppo.Id);
     System.debug('**** 1 oppo id : '+oppo.id);
     
     }
    
    Map<Id, User> entries = new Map<Id, User>();
    List<user> us = [select Id, Street from User where id in :UserIds];
  
    for(Opportunity unity: Trigger.new) {
       unity.Opp_Owner_Address__c = us[0].street;
    }
}

 And I am getting a new error:

System.ListException: List index out of bounds: 0

Trigger.OpportunityOwnersAddress: line 16, column 40

 

 

The problem is still with the final line

unity.Opp_Owner_Address__c = us[0].street;

 From what I can figure out, is that the trigger is not finding a record to process. I am intending to set this up to pull from any user record in the system.

 

What am I missing?

Thanks,

SuperfellSuperfell

Its saying that the list 'us' is empty, i.e. your query against User returned no rows, which will be a result of you adding the opportunity Id (i.e. oppo.id) to the UserIds set, rather than oppo.ownerId

This was selected as the best answer
cribiscribis

This solved the errors. Thank you