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
JennMJennM 

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

I am adding a bit of code to an existing Apex class and it won't compile.  Any thought on what is wrong and why I am getting the error message: Error: Compile Error: Expression cannot be assigned at line -1 column -1 ?

 

OpportunityLineItem newoppprod = new OpportunityLineItem(

 opportunityId = newopp.id,
  Quantity = 1,
  ServiceDate = l.Donation_Close_Date__c,
  TotalPrice = l.Donation_Amount__c);
 
  if(l.Product_Information__c != null)
      {
      if(l.Product_Information__c == 'Donate')
          {
          OpportunityLineItem.ID = '01tS0000000kI02';
          }
      if(l.Product_Information__c == 'ticket-individual')
          {
          OpportunityLineItem.ID = '01tS0000000kFsk';
          } 
      if(l.Product_Information__c =='sponsorship-mentor')
          {
          OpportunityLineItem.ID = '01tS0000000kFsV';
          }   
      }
  insert newoppprod;

Tim__mTim__m

First, you can not set a property on a none static class, OpportunityLineItem.ID = 'blabla' can't be done. You need to set the property on an instance of the OpportunityLineItem class. In your case newoppprod is the object to work with. But, your second problem is you can't set the ID property on the newoppprod object. ID can only be set by the database backend. It looks like you need a developer to write this for you.

 

What is your use case?

 

If you are a non-profit I wouldn't mind helping you out a little.

 

 

JennMJennM

Thanks Tim and, yes, it is for a nonprofit organization so I would really appreciate the help as I am a bit lost with this! 

 

A previous developer wrote an Apex class to automatically convert a web-to-lead which is used on our website to capture purchases of publications and donations.  The Apex class basically creates the appropriate Account/Contact records and then adds the Opportunity. We are expanding to also include purchasing tickets for a fundraising event this fall so have changed the Opportunity to use Opportunity Products so that in one transaction a person could order multiple tickets, publications and give a donation.  We want there to be one opportunity with the multiple opportunity products detailed (and we have a custom object to handle the payment details which works fine). 

 

In order to accomplish this, the web designer is sending a serialized string of the items purchased in a Product Information field (ticket-individual, sponsor-champion, donation).  I was hoping I could create a loop (hadn't tried it yet though) that would find each value in the string and then add the appropriate opportunity product after adding the opportunity.  At some point we have to also deal with quantity of each opp product as well and were thinking we could do something like this in the string: (2 ticket-individual, 1 sponsor-champion, 1 donation) and parse it out that way.

 

Do you think you could help with this?

 

Jenn

JennMJennM

I think I figured out one problem, I was trying to add data to the wrong field.  I guess the Product ID would get added to the PricebookEntryID field?