+ Start a Discussion
RockyDrakeMRockyDrakeM 

ERROR:Expression cannot be assigned

Hello,

I want to assign  like line 3, i have error
sObject sObj = new QuoteLineItem();
sObject s = new ContractLineItem();

s.get(fieldToCompare) = sObj.get(fieldToCompare);   //ERROR:Expression cannot be assigned
Can someone help me to achieve this use case ?

thanks in advance
 
PawanKumarPawanKumar
Hi,
Please try like below.

sObject sObj = new QuoteLineItem();
sObject s = new ContractLineItem();

// from your below line; what i understood is: you want to set value.
//s.get(fieldToCompare) = sObj.get(fieldToCompare);
s.put(fieldToCompare, sObj.get(fieldToCompare));

// if you want to compare
// Assumption 'fieldToCompare' type is String.
String contractLineItemVal = (String)s.get(fieldToCompare);
String quoteLineItemVal = (String)sObj.get(fieldToCompare);

if(contractLineItemVal.equalsIgnoreCase(quoteLineItemVal)){
// equals
}else{
//not equals
}
 
Regards,
Pawan Kumar
Glyn Anderson 3Glyn Anderson 3
You can do it the way you're doing it - just use the comparison operator (==) rather than the assignment operator (=):

<pre>
sObject sObj = new QuoteLineItem();
sObject s = new ContractLineItem();
 
s.get(fieldToCompare) == sObj.get(fieldToCompare);   //NOTE: "=="
</pre>
Glyn Anderson 3Glyn Anderson 3
If you're trying to assign one value to the other:

<pre>
sObject sObj = new QuoteLineItem();
sObject s = new ContractLineItem();
 
s.put(fieldToCompare, sObj.get(fieldToCompare);   // copy one field value into another field
</pre>
Glyn Anderson 3Glyn Anderson 3
I left out a ')' on line 4.

<pre>
sObject sObj = new QuoteLineItem();
sObject s = new ContractLineItem();
  
s.put(fieldToCompare, sObj.get(fieldToCompare));   // copy one field value into another field
</pre>
Glyn Anderson 3Glyn Anderson 3
RockyDrakeM,  Did any of these answers solve your problem?  If so, please mark the question as "Solved".  If not, let us know.  If you solved the problam another way, please post your solution for everyone's benefit.  Thanks!
Glyn Anderson 3Glyn Anderson 3
Rocky,  We're all hoping there was a Best Answer in here somewhere.  If you found a different solution, please post it for everyone's benefit.  Thank you!