0

I have a C# application that was meant to upload invoices to salesforce financials. All other functions of the application works fine except the uploading module. During the upload process, I have to create a new Transaction record using the ForceClient.CreateAsync() method. As seen below. Please note that I have created the Transaction object and set it's properties in a lengthy chunk of code.

SuccessResponse createTransResponse = await client.CreateAsync("s2cor__Sage_INV_Trade_Document__c", transactionObj);

When the application reaches the above line, it always crashes with the error below

SObject row was retrieved via SOQL without querying the requested field: s2cor__Sage_INV_Trade_Document_Type__c.s2cor__Use_Company_Shipping__c

The transaction class itself looks line this;

public class Transaction
    {
        public string Name { get; set; }
        public String Id { get; set; }
        public string s2cor__Reference__c { get; set; }
        public String s2cor__Account__c { get; set; }
        public String s2cor__Date__c { get; set; }
        public string s2cor__Trade_Document_Type__c = "a211v0000022YBpAAM"; 
        //public string s2cor__Net_Amount__c { get; set; }
        public string s2cor__Currency__c { get; set; }
        public string s2cor__Exchange_Rate__c { get; set; }
    }

After researching, I found that this new field s2cor__Use_Company_Shipping__c was added to Transaction_Type record in the 2019 release of salesforce. Some one said this error is related to a data trigger on the Transaction record. How do i stop it from occurring so that the transaction record can be created successfully? Does anyone have an idea of what I'm doing wrong?

1
  • What package does the namespace s2cor correspond to? If you attempt to manually insert a record matching this structure through Workbench or Anonymous Apex, can you reproduce the error and get a stack track? It sounds like there's a trigger with a bug in it.
    – David Reed
    Jun 6, 2019 at 15:37

1 Answer 1

0

Looks like either something is querying the SObject in question (my guess being s2cor__Sage_INV_Trade_Document__c) and not also querying the field (which appears to actually be a relationship, s2cor__Sage_INV_Trade_Document_Type__r.s2cor__Use_Company_Shipping__c), or your class there isn't filling it out, with s2cor__Sage_INV_Trade_Document_Type__c only providing the id, not the associated complex class with an ID and s2cor__Use_Company_Shipping__c value.

public class Transaction
    {
        public string Name { get; set; }
        public String Id { get; set; }
        public string s2cor__Reference__c { get; set; }
        public String s2cor__Account__c { get; set; }
        public String s2cor__Date__c { get; set; }
        public TradeDocumentType s2cor__Trade_Document_Type__c = new TradeDocumentType(); 
        //public string s2cor__Net_Amount__c { get; set; }
        public string s2cor__Currency__c { get; set; }
        public string s2cor__Exchange_Rate__c { get; set; }
    }
public class TradeDocumentType
{
    public String Id "a211v0000022YBpAAM";
    public String Name { get; set; }
    public boolean s2cor__Use_Company_Shipping__c = { get; set; }; 
}
8
  • How do you suggest I fix it? I added the s2cor__Use_Company_Shipping__c field to my class but didn't get any positive result
    – Ken Janka
    Jun 5, 2019 at 19:47
  • Well, I can't see the rest of your code. But if there's anything querying s2cor__Sage_INV_Trade_Document_Type__c, make sure that it's also querying s2cor__Sage_INV_Trade_Document_Type__r.s2cor__Use_Company_Shipping__c before proceeding. For adding to your class there (I assume that's the C# side), based on the error, s2cor__Trade_Document_Type__c is no longer a simple String, but a complex class consisting of at least a String ID, and that new field. I don't think this was a Salesforce update (these are all custom objects), but rather a Sage Update.
    – pmiller3
    Jun 5, 2019 at 22:03
  • Sage Update
    – pmiller3
    Jun 5, 2019 at 22:03
  • That's the thing. The querying seems to happen within ForceClient.CreateAsync() method. So i have no way of editing the method to ensure that it also queries for s2cor__Sage_INV_Trade_Document_Type__r.s2cor__Use_Company_Shipping__c and there's very little documentation on how to create a transaction record
    – Ken Janka
    Jun 6, 2019 at 3:59
  • Hmm... Sounds like the ForceClient is doing something dynamic then based on your object. I edited my answer to show how you could make that s2cor__Sage_INV_Trade_Document_Type__c complex... can you try that?
    – pmiller3
    Jun 6, 2019 at 15:28

You must log in to answer this question.

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