0

I've created a tool that takes loan data from one system and attempts to insert it into SalesForce. It assigns a Loan Officer by performing a query to find the NMLS # (which is an indexed field) for a Contact object and setting the Loan_Officer__r property of the loan object to that id. This worked just fine until about a month ago when I added 2 new required fields to the Contact Object. Here's the main code block (in C#):

foreach (var r in erdbQuery)
{
    try
    {
        Loan__c newLoan = new Loan__c();
        newLoan.BorrowerFirstName__c = r.F4000;
        newLoan.BorrowerLastName__c = r.F4002;
        newLoan.LoanOfficerName__c = r.F317;
        newLoan.LoanType__c = r.F1172;
        newLoan.LoanRate__c = (double)r.F3;
        newLoan.LoanRate__cSpecified = true;
        newLoan.LoanAmount__c = (double)r.F2;
        newLoan.LoanAmount__cSpecified = true;
        newLoan.LoanPurpose__c = r.F19;
        newLoan.Address1__c = r.F11;
        newLoan.City__c = r.F12;
        newLoan.State__c = r.F14;
        newLoan.BorrowerEmail__c = r.F1240;
        newLoan.Zip__c = r.F15;
        newLoan.LoanNumber__c = r.F364;
        newLoan.Name = r.F364;

        Contact contactReference = new Contact();


        contactReference.NMLS__c = Retrieve_LO_ID(r.F3238);
        newLoan.Loan_Officer__r = contactReference;

        try
        {
            SaveResult[] results = SfdcBinding.create(new sObject[] { newLoan });
            if (results[0].errors != null)
            {
                add_to_error_log(results[0].errors[0].message, newLoan.LoanNumber__c);
            }
        }
        catch (Exception ex)
        {
            add_to_error_log(ex.ToString(), newLoan.LoanNumber__c);
        }
    }
    catch (Exception ex)
    {
        add_to_error_log(ex.ToString(), r.F364);
        continue;
    }
}

Initially, I got the error message

Required fields are missing: [Bonus_Pay__c, Classification__c] on Loan Removed

So, I had a co-worker back-fill those fields on all records that were missing values. However, even on loans with a Loan Officer that has those fields filled in on their Contact object, I still get the error message. This is very strange, as the Contact object has a number of required fields that are not explicitly set in my code, and I'm not getting errors for them.

Does anyone have any insight on why this might be happening?

  • Are these contact fields related to the loan in any manner? It sounds like the loan officer is a look-up to contact and your code is expecting the required fields to be populated in your query when the record is inserted. If you've requeried at some point in your code without including the fields (or dropped/lost them in wrapper), that could cause the error you're seeing. – crmprogdev Mar 24 '17 at 15:13
  • @crmprogdev The Loan Officer field is a Master-Detail relationship. That's why I'm only giving it the indexed "NMLS__c" field. Shouldn't it not need anymore information, since the record already exists in SalesForce? – Inagnikai Mar 24 '17 at 17:34
  • Contact has to be a look-up from the Loan Officer Object. Are you trying to say that you've renamed Contact to Loan Officer? If you've renamed the Contact Object to Loan Officer, it cannot be the Detail object in a M-D relationship. What I was trying to convey above is that if you've run a query in your code at one point, then requeried later or used other code without also using those fields, the references to those fields may have been lost which could be causing the error you're seeing. – crmprogdev Mar 24 '17 at 17:46
  • Loan Officer is a relationship under the loan Object. This relationship is between the Loan(Detail) object and a Contact(Master) object. The Contact object has the 2 required fields listed above, but I know for a fact that the Contact for the loans for which the exception is thrown has these fields filled in. It's my understanding that all a relationship field needs is an indexed field to associate to the correct object (in this case, the Contact), which is why I don't understand why this error is being thrown. – Inagnikai Mar 24 '17 at 17:54
  • Is the Loan Officer a look-up to another contact record that also contains these required fields or do you have a separate object for Loan Officer that isn't related to a different Contact Record for the Loan Officer? Do the two contacts have different record types might be another way of putting it? – crmprogdev Mar 24 '17 at 18:00
0

I'm pretty confident your issue is caused by the Loan Officer also being a look-up to a contact. I strongly suspect that your code is expecting your Loan Officer to also have the new fields populated in the officer's record as well. When it doesn't find it, the error is being thrown.

To solve this, you'll need to use a different record type for your Loan Officer than the contact the loan is related to. Doing that will allow you to make those fields optional for the loan officer.

  • Here's the kicker: This code worked just fine before the 2 fields - Bonus_Pay__c and Classification__c were added. – Inagnikai Mar 24 '17 at 18:13
  • Makes perfect sense to me that if your loan officer doesn't have those fields populated and they're required for the loan officer too, then your code is going to throw an error message. They're both contacts and it sounds as though you've made the fields required for all of your contacts. – crmprogdev Mar 24 '17 at 18:58

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.