function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PaladyrPaladyr 

How to check if sforce object contact has nothing filled in for the account information?

I'm getting an error, object reference not set to an instance of an object when I reference the sforce contact object and the Account object inside the contact is not set to anything. So basically the contact info is filled into the object, but there is no account object attached to it. I've tried: If not sfContact.Account is nothing If not sfContact.Account.custom_field__c is nothing Neither catches when the Account object is set to nothing. How do I prevent code from being run when the Account object on a contact has not been filled in? I know I could change my query to prevent it from downloading a contact not linked to an account but I would like to know how to do this for future reference. Thanks!
SimplySfdcSimplySfdc

Hi, you could check array size return from queryresult.

 

String groupByQuery = "SELECT Account.Name n, " +
"MAX(Amount) max, MIN(Amount) min " +
"FROM Opportunity GROUP BY Account.Name";
QueryResult qr = connection.query(groupByQuery);
if (qr.getSize() > 0) {
  // do something
}

_Prasu__Prasu_

Which WSDL you are using? Partner or Enterprize? I guess you must be using Enterprize?

 

SimplySfdcSimplySfdc

Partner WSDL

PaladyrPaladyr
I'm using enterprise. I don't want to use another API call to figure out if the contact doesn't have account information. I've already changed the original query to exclude contacts without account information. I'm surprised this is so difficult, seems like it should be easy to test and see if the account information is empty :-/.
SuperfellSuperfell

In C# you would compare sfCotact.Account to null and then sfContact.Account.custom_field__c to null. Not sure what the equivalent in vb.net is.

PaladyrPaladyr
Yea I tried this: If Not IsDBNull(sfContact.Account) Then 'run code assuming account info is filled in End If The problem is that even if nothing is in the account object, the test says it's not Null. Also this line fails to catch a lack of account information: If sfContact.Account is Nothing Both tests say there is something in the account field, but there is nothing. Any other ideas?
JPClark3JPClark3

I wonder if you can put the sfContact.Account into a string value, then check the length != 0. (should be 18 if it has a value)

in VB.Net the "is nothing" is similar to the C# " == null", but i'm wondering if it is an exact match. Can you try " = nothing" (not sure if that compiles.)