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
NikunjVadiNikunjVadi 

Assigning value to field (Field name is stored in string)

i want to assigned a constant value for the field stored in a string . But i am getting an error:Expression cannot be assigned 

What is wrong with :
refOpportunityItem.get(Tierfield) = -1;
Opportunityitem__c refOpportunityItem = new refOpportunityItem();

   public void tierNumbers()
    {
        if(refOpportunityItem.Number_Of_Tier__c != Null)
        {
            NumberOftier=Integer.valueOf(refOpportunityItem.Number_Of_Tier__c);
            TierField ='Upper_Quantity_Tier_2__c';
            refOpportunityItem.Upper_Quantity_Tier_2__c = -1;
------In the next row i am getting error
            refOpportunityItem.get(Tierfield) = 1;
            //refOpportunityItem.get(Tierfield);
       }
{

 
NikunjVadiNikunjVadi
This worked. 
refOpportunityItem.put(TierField,-11);
Asif Ali MAsif Ali M
get method is used to read the property value. Use put method to set the value. The below line only works for String types. If the filed (TierField) can be any Data Type then you have to do the type casting before setting the value.
refOpportunityItem.put(Tierfield, '1');

 
HARSHIL U PARIKHHARSHIL U PARIKH
Can you tell us the requirement in depth?

On line 11, you are assigning the value 1 to the expression thats why.