-2

Not able to update custom field from Apex class, getting below error:

Illegal assignment from List to List<Rating_Request__c>

Can anyone help where I am doing wrong. If possible provide sample code.

Below is my code :

public void updateflgusertb(string Selected)
{
    
    List<Rating_Request__c> usr = [SELECT ID,Question__c,Order_Sequence__c,User_Ratings__c FROM                     
        Rating_Request__c where User__c=:UserInfo.getUserId() and User_Rating__c = 0 
        group by                           
        ID,Question__c,Order_Sequence__c,User_Ratings__c 
        order by Order_Sequence__c  LIMIT 1];
    List<Rating_Request__c> rateupdate = new List<Rating_Request__c>();  
    for(Rating_Request__c objrating : usr)
    {
        objrating.User_Ratings__c = Selected;
        rateupdate.add(objrating);
    }
    update(rateupdate);
    
}

Thanks in advance

1
  • 1
    Please do not remove all content from a question once you are able to resolve it. Doing so is an abuse of the model here, where members of the community volunteer their valuable time to help you. Removing content after the fact robs future visitors of any ability to gain value from the post, making the interaction entirely one-sided. If you are posting protected intellectual property that you should not, then more care should be taken in the first place to anonymize or scrub that (using Minimum Viable Reproduction). Otherwise, please leave the post intact and accept the answer that helped you.
    – Adrian Larson
    May 5 at 19:07

1 Answer 1

1

The error is complaining because you are trying to iterate an aggregate query result to list of SObject.

Remove group by clause from SOQL to resolve the error:

public void updateflgusertb(string Selected)
{
    
    List<Rating_Request__c> usr = [SELECT ID,Question__c,Order_Sequence__c,User_Ratings__c FROM
        Rating_Request__c where User__c=:UserInfo.getUserId() and User_Rating__c = 0 
        order by Order_Sequence__c  LIMIT 1];
    List<Rating_Request__c> rateupdate = new List<Rating_Request__c>();  
    for(Rating_Request__c objrating : usr)
    {
        objrating.User_Ratings__c = Selected;
        rateupdate.add(objrating);
    }
    update(rateupdate);
}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .