1

I have a custom object that users can access to make updates and create new entries. One of the field the users are allowed to update is a pick list field. I need to map each field of the Master object to the Staging Object but I get a compile error below. How do I resolve this? Thanks

public Void GO()
{
    mainKey=1;        
    stagingwrappers=new List<StagingKey1Wrapper>();

    List<Catalog_Master__c> Master_Data=[select ID, OPN__c, AQ_Qty__c from Catalog_Master__c Where OPN__c =:OPN_v and  Business_Unit__c=:BU_v and  Root_Part_Number__c=:Root_v Limit 5];
    for (Catalog_Master__c Master : Master_Data)
    {
        Catalog__c staging_obj = new Catalog__c();

        staging_obj.MasterID__c =  Master.ID;            
        staging_obj.AQ_Qty__c =  Master.AQ_Qty__c; //Compile Error: Illegal assignment from Decimal to String

        Stagingwrappers.add(new StagingKey1Wrapper(mainKey++, staging_obj));
    }          
}
1

It appears that the field Catalog__c.AQ_Qty__c is of type String (e.g. Text) and Catalog_Master__c .AQ_Qty__c is of type Decimal (e.g. Number). The cleanest way to fix this is to change the type of Catalog__c.AQ_Qty__c to Decimal too (choosing exactly the same Data Type, Length and Decimal Places values too). If you presently have no data in that column there are no data migration issues, and you can make the change by using Edit on the field and then Change Field Type.

If for some reason you choose not to change the type, you can make the above code work by converting the Decimal to a String using e.g.:

staging_obj.AQ_Qty__c = Master.AQ_Qty__c != null ? String.valueOf(Master.AQ_Qty__c) : null;

assuming the staging_obj.AQ_Qty__c is long enough. But that is not ideal.

A picklist field would be of type String in Apex code like this; if AQ_Qty__c is a picklist field then the change would be to make both fields of type String.

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.