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
ckellieckellie 

Error: Compile Error: Illegal assignment from SOBJECT:Opportunity to String at line 9 column 5

I am trying to create an auto number to each Opportunity Line Item within an opportunity. The number will be the Opportunity id number with .001 concetenated at the end. With each subsequent Opportunity Line Item, the number will increase by .001. I am recieving the following error:

 

Error: Compile Error: Illegal assignment from SOBJECT:Opportunity to String at line 9 column 5

 

Below is my trigger.

 

//Loop through all locations and collect the current numbers. trigger ProductNumber on OpportunityLineItem (before insert) { /*Loop every new location you enter*/ for(OpportunityLineItem l:trigger.new) { if(l.Product_Line_Item_ID__c==null){ String cname = l.Opportunity; /* This writes to the debug log*/ //System.debug('location data: '+l); /*This looks up all of the location numbers for the specific account*/ List <OpportunityLineItem> a = [select Product_Line_Item_ID__c from OpportunityLineItem where ACCOUNT__C= :cname ]; /*If the list results are empty*/ system.debug(a); if(a.isEmpty()){ l.OpportunityLineItem=1; }Else { List <Decimal> b = new List<Decimal>(); for (OpportunityLineItem tempLocation:a) { b.add(tempLocation.OpportunityLineItem); } Decimal highest = 0; b.sort(); highest = b[b.size()-1]; l.OpportunityLineItem=highest + 1; } } } }

 

How can I  solve this problem?

Best Answer chosen by Admin (Salesforce Developers) 
ckellieckellie
Changed Opportunity to OpportunityId

All Answers

ckellieckellie
Changed Opportunity to OpportunityId
This was selected as the best answer
SsuazoSsuazo

I need help.... I am tryin to create a trigger that auto populates the state field when a zip code is entered... here is what i have so far...

 

trigger zipTrig on Lead(After insert, After update) {
  
If (Trigger.new.PostalCode.startsWith('100')){
Trigger.new.Province = 'NY';           
}}
    

Im getting this error message...

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Lead> at line 4 column 1