1

I am getting an "Illegal assignment from object to string" on an Aggregate Result trigger.

Here is the code snipped;

List<AggregateResult> uniqueCountries = ([SELECT Country_Operational_Date__c FROM SBQQ__QuoteLine__c WHERE SBQQ__Quote__c IN:quoteIds 
                                                        AND country_code__c <> null AND Employee_CountFormula__c <> null GROUP BY Country_Operational_Date__c]);


            if(uniqueCountries.Size()>0 ){

                SBQQ__Quote__c quote = new SBQQ__Quote__c();

                for (AggregateResult uniqueCountry : uniqueCountries){

                    quote.Operational_Start_Date__c = uniqueCountry.get('Country_Operational_Date__c');

This is the line that's causing the exception,

quote.Operational_Start_Date__c = uniqueCountry.get('Country_Operational_Date__c');

How do I go about solving this?

1

try this lines

quote.Operational_Start_Date__c = String.valueOf(uniqueCountry.get('Country_Operational_Date__c'));

NOTE: Please handle Null Pointer case in your code as well.

0

Try this code , you made need field aliasing as well:

List<AggregateResult> uniqueCountries = ([SELECT Country_Operational_Date__c countryDate FROM SBQQ__QuoteLine__c WHERE SBQQ__Quote__c IN:quoteIds 
                                                        AND country_code__c <> null AND Employee_CountFormula__c <> null GROUP BY Country_Operational_Date__c]);


            if(uniqueCountries.Size()>0 ){

                SBQQ__Quote__c quote = new SBQQ__Quote__c();

                for (AggregateResult uniqueCountry : uniqueCountries){

                    quote.Operational_Start_Date__c = String.valueOf(uniqueCountry.get('countryDate '));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.