0

i have a problem with populating field with data from different Object. I tried something like this, but it say "Incompatible types since an instance of Schema.SObjectField is never an instance of String" in this row

newTransaction.CC_Account_Number__c = (String) Case.Currency__c;

Here is whole method

@AuraEnabled
    public static List<Transaction__c> addNewTransaction(String dataJson) {
        List<Transaction__c> dataList = (List<Transaction__c>) JSON.deserialize(dataJson, List<Transaction__c>.class);

        Transaction__c oldTransaction = dataList.get(0);
        Transaction__c newTransaction = new Transaction__c();
        newTransaction.KLIP_Subcase__c = oldTransaction.KLIP_Subcase__c;

        newTransaction.CC_Account_Number__c = (String) Case.Currency__c;

        insert newTransaction;
        dataList.add(newTransaction);

        return dataList;
    }
1

Case.Currency__c is a reference to a field on the Case sObject. Its value is, as the error message suggests, a Schema.SObjectField, used as part of the Describe API.

It's not clear what you're trying to do here. If you're pulling data out of the incoming Transaction__c, you need to use a reference into that object. If your Transaction__c has a lookup to Case, you'll likely need to be performing a query here to get the value of Currency__c from that specific Case record.

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.