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
lawlaw 

ave error: Illegal assignment from Schema.SObjectField to Decimal

I receive the following compile error : Description Resource Path Location Type
Save error: Illegal assignment from Schema.SObjectField to Decimal ContactChanges.trigger EAR AFTER REFRESH 3_05_2014/src/triggers line 520 Force.com save problem

Any and all help greatly appreciated!


Code below:

List<Quintile__c> q = [Select Quintile__c, T12_Min__c, T12_Max__c,Los_Min__c,LOS_Max__c,Start_Date__c,End_Date__c
                    from Quintile__c
           where start_date__c <= today  and end_date__c > today];
         
         
            if(!q.isEmpty()){
    if (c.Total_years_as_a_rep__c != 0 &&  c.Total_years_as_a_rep__c != null  && c.Estimated_T_12__c != 0 && c.Estimated_T_12__c != null &&
              c.Estimated_T_12__c >= Quintile__c.T12_Min__c &&
              c.Estimated_T_12__c < Quintile__c.T12_Max__c &&
     c.Total_years_as_a_rep__c >= Quintile__c.LOS_Min__c &&
     c.Total_years_as_a_rep__c < Quintile__c.LOS_Max__c
              ){
              c.Estimated_Quintile__c  = Quintile__c.Quintile__c;
          }
   }else
   {
         //handler code for no matching account 
            }
SeAlVaSeAlVa
Hi there, 

you are trying to compare and assign fields of Quintile__c sObject instead of an instance
Your code
    c.Estimated_T_12__c >= Quintile__c.T12_Min__c &&
    c.Estimated_T_12__c < Quintile__c.T12_Max__c &&
    c.Total_years_as_a_rep__c >= Quintile__c.LOS_Min__c &&
    c.Total_years_as_a_rep__c < Quintile__c.LOS_Max__c){
        c.Estimated_Quintile__c  = Quintile__c.Quintile__c;
    }

instead of something like 
    c.Estimated_T_12__c >= q.get(0).T12_Min__c &&
    c.Estimated_T_12__c < q.get(0).T12_Max__c &&
    c.Total_years_as_a_rep__c >= q.get(0).LOS_Min__c &&
    c.Total_years_as_a_rep__c < q.get(0).LOS_Max__c){
        c.Estimated_Quintile__c  = q.get(0).Quintile__c;
    }
Regards
lawlaw
Thank you ..  than does help.   One more thing.  I am trying to do the following in my trigger. However, I cannot figure out the correct query.  The code above brings back all records...I need to bring back just one record based on the requirements below.

if contact.Total_years_as_a_rep__c != '' and
contact.Estimated_T_12__c != ''
then
contact.Estimated_Quintile__c =


Select Quintile__C from Quintile__c
where
Quintile__c.start_date__c <= today() and
Quintile__c.end_date__c > today() and
contact.Estimated_T_12__c >= Quintile__c.T12_Min__c and
contact.Estimated_T_12__c < Quintile__c.T12_Max__c and
contact.Total_years_as_a_rep__c >= Quintile__c.LOS_Min__c and
contact.Total_years_as_a_rep__c < Quintile__c.LOS_Max__c
SeAlVaSeAlVa
Assuming the following:
  • Quintile__c is, apart from the API name of the Object, the API Name of a field
  • contact is a variable, and you are not trying to make reference to the schema Object
Note that in order to use variables inside the query, you must put ":" before it.
List<Quintile__c> quintilesList = [
  SELECT
    Quintile__c
  FROM
    Quintile__c
  WHERE
    Start_date__c <= today() AND
    End_date__c > today() AND
    T12_Min__c <= :contact.Estimated_T_12__c AND
    T12_Max__c > :contact.Estimated_T_12__c  AND
    LOS_Min__c <= :contact.Total_years_as_a_rep__c AND
    LOS_Max__c > :contact.Total_years_as_a_rep__c
];

if(quintilesList.size() == 1){
  contact.Estimated_Quintile__c = quintilesList.get(0).Quintile__c;
}


if you are trying to point to the Quintile itself, then you should retrieve the ID of the record and put it in the Lookup (or Master-Detail) field.
You would just have to replace "SELECT Quintile__c" with "SELECT ID" and "quintilesList.get(0).Quintile__c" with "quintilesList.get(0).ID"

Hope it helps ;)

lawlaw
Thanks this did help!  Unfortunately, after attempting to deploy .. I receive a  "Too many SOQL queries 101" error in one of my test classes.
When I comment out the code all tests run without error.