2

I have this simplified code in a test script:

Account acct = new Account();  
acct.Name = 'Test Account';  
acct.managed_package_custom_field__c = '12345';  
insert acct;

system.debug([SELECT Id, managed_package_custom_field__c FROM Account WHERE Id = :acct.Id ]);

The output of the debug shows the Id, but nothing for the other field.

This works fine through the user interface. The field level security for that field is editable by all.

I have to be missing something simple here.

1
  • Just wanted to make sure you are calling the custom field by using name space like this namespace_customfield? Commented Jun 21, 2018 at 21:13

2 Answers 2

1

Debugging isn't a reliable method for checking things in a unit test. Use assertions:

Account reloaded = [SELECT Id, managed_package_custom_field__c FROM Account WHERE Id = :acct.Id ]);
System.assertEquals(acct.managed_package_custom_field__c, reloaded.managed_package_custom_field__c);

Presuming this fails, there may be a trigger on Account by the managed package, or maybe a workflow rule cancelled out the value, there are some missing Custom Settings, or something else happened entirely. You'll have to read more than just a single line of log to figure out what happened.

If you open the debug log in Developer Console, you can type in the custom field's name in the Filter box, and from there, you can see each time it was touched and what happened to it. If you don't find anything there, you might also need to work with the ISV so they can get ISV-enabled log files, or, you might just ask them; they might already know of this problem and have a workaround for you.

1
  • That was it!! The manage package has a trigger that erases that field. Thanks!
    – Jerry
    Commented Jun 21, 2018 at 21:39
0

Please run the soql querry by using the managed package name space prefix.

For Ex: If your package namespace is myNS

system.debug([SELECT Id, myNS_managed_package_custom_field__c FROM Account WHERE Id = :acct.Id ]);
1
  • I am using the full api name. I wanted to make the code I entered here as simple as possible.
    – Jerry
    Commented Jun 21, 2018 at 21:21

You must log in to answer this question.

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