4

My describe call is pulling some of these fields

(accountname,islocked,middlenamelocal,personkeyid,mayedit) on Contact object.

There are few more.And my Dynamic SOQL is complaining that those fields are not available.

I have all the classes,trigger that falls in the execution path in same version.I updated it to 33.But still getting the same issue.But when I do my describe call from developer console those fields are not showing up.It's also using version 33.

I looked at different version for those fields and couldn't find any of those fields at all.

Any help?

Adding additional information. Did a describe field and isAccessible() is returning true but the SOQL says field not available.

Field Result Schema.DescribeFieldResult[getByteLength=0;getCalculatedFormula=null;getController=null;getDefaultValue=null;getDefaultValueFormula=null; getDigits=0;getFilteredLookupInfo=null;getInlineHelpText=null;getLabel=Is Locked;getLength=0;getLocalName=IsLocked;getMask=null; getMaskType=null;getName=IsLocked;getPrecision=0;getReferenceTargetField=null;getRelationshipName=null;getRelationshipOrder=null; getScale=0;getSoapType=BOOLEAN;getSobjectField=IsLocked;getType=BOOLEAN;isAccessible=true;isAutoNumber=false;isCalculated=false; isCascadeDelete=false;isCaseSensitive=false;isCreateable=false;isCustom=false;isDefaultedOnCreate=true;isDependentPicklist=false; isDeprecatedAndHidden=false;isDisplayLocationInDecimal=false;isExternalId=false;isFilterable=true;isGroupable=true;isHighScaleNumber=false; isHtmlFormatted=false;isIdLookup=false; isNameField=false;isNamePointing=false;isNillable=false; isPermissionable=false;isQueryByDistance=false; isRestrictedDelete=false;isSortable=true;isUnique=false;isUpdateable=false;isWriteRequiresMasterRead=false;]

How am I getting isLocked field for Contact?

Contact Query with Standard field:

16:06:01:366 USER_DEBUG [71]|DEBUG|Contact Query SELECT accountname, mailinglatitude, jigsaw, leadsource, createdbyid, connectionsentid, connectionsentdate, otherphone, isdeleted, recordtypeid, systemmodstamp, assistantphone, isemailbounced, otherstreet, hasoptedoutofemail, firstnamelocal, createddate, ownerid, reportstoname, canallowportalselfreg, lastvieweddate, jigsawcontactid, cleanstatus, othercity, lastmodifiedbyid, reportstoid, photourl, lastname, lastcurequestdate, informalnamelocal, mobilephone, mailinglongitude, mailingcountry, title, mailingaddress, division, emailbounceddate, mailingstreet, homephone, emailbouncedreason, firstname, assistantname, personkeyid, salutation, phone, otherstate, lastactivitydate, lastnamelocal, islocked, description, fax, otheraddress, hasoptedoutoffax, lastcuupdatedate, connectionreceiveddate, email, donotcall, mayedit, mailingstate, currencyisocode, connectionreceivedid, department, otherlongitude, ispersonaccount, lastmodifieddate, usesalesforce, lastreferenceddate, otherlatitude, name, birthdate, middlenamelocal, accountid, masterrecordid, otherpostalcode, mailingpostalcode, othercountry, mailingcity, Id FROM Contact Where Id IN ('00317000009HmaVAAS')

Some of the fields not recognized by SOQL acountname,islocked,mayedit

Adding more discovery : I am getting bunch of extra fields that the SOQL doesn't recognize only when I perform the Sobject Describe after LeadConversion and Contact gets created. I have been able to reproduce this in fresh developer org.

------------Lead Trigger--------------------------- '

trigger Lead on Lead (after insert) 
{
        Database.LeadConvert lc = new Database.LeadConvert();
        lc.setLeadId(Trigger.new[0].Id);
        lc.setConvertedStatus('Closed - Converted');
        lc.setDoNotCreateOpportunity(true);
        List<Database.LeadConvertResult> lcr = Database.convertLead(new List<Database.LeadConvert>{lc});

}
'
Contact trigger gets fired:
-------------Contact Trigger-----------
'
trigger Contact on Contact (after insert) 
{
    Map<String, Schema.SobjectField> contactFields =  Schema.SobjectType.Contact.fields.getMap();
    String contactQuery = 'SELECT ';
    for (String s : contactFields.keySet())
    {
       if(s != 'Id') contactQuery += s + ', ';
    }
    contactQuery += ' Id FROM Contact Where Id IN (\''+Trigger.new[0].Id+'\')';
    System.debug('Contact Query '+contactQuery);
    List<SObject> theContacts = Database.query(contactQuery);
}

I get the query exception on above.

If I do the LeadConversion in one transaction and put the method to do a describe on different class and make a future call (making a different transaction) , I don't get those extra fields.Version for both trigger is 33.

If I put the Describe in the Lead Trigger itself after the Lead Conversion.That also works.

Can you guys reproduce this?

  • possible duplicate of Finding if a custom field is editable using Apex code – Caspar Harmer Apr 30 '15 at 22:14
  • Have you tried copy-pasting the query into the dev console? – Adrian Larson Apr 30 '15 at 23:46
  • Did that. Same error. System.QueryException : No such column accountname on entity Contact. Seems like a bug that its somehow leaking these fields on describe call and SOQL is enforcing the version rule. Tried on different version still same. Describe Call and SOQL is on the same class. – jimmy7894 May 1 '15 at 0:06
2

I haven't encountered IsLocked and MayEdit as system fields on Contact (or Account) previously.

Are you using the Approval feature in that Org?

From my searching it seems like the problem fields are specifically related to that particular feature.

If that is the case, you may need to explicitly ignore those system fields. It may also indicate a problem with the Apex describe calls.

1

The most probable answer is a difference in versions. For example, if one class generates the list of fields, and a separate class performs the query (or the current version, if using execute anonymous), and there's a mismatch in versions, you're very likely to get this error. The first time I noticed this effect myself was in v28, when LastViewedDate was getting returned to my other classes that were v27, and subsequently crashing with the same error message. You should make sure that all of your classes, pages, components, etc are all running on the same version.

Edit

Thinking of a recent question about the ListViewChartInstance object, I suspect that there may be fields being leaked by the next (or a future) release. Try reducing your API version down a version or two (or probably v28), and see if that fixes things.

  • Yes I have seen that issue with lastVieweddate and understand what you are saying.But in my case the describe call and the SOQL is in the same class.and it is version 33. – jimmy7894 Apr 30 '15 at 23:26
0

Try checking isAccessible() on your DescribeFieldResult instances (documentation).

Schema.SObjectField field = Contact.AccountName;
Schema.DescribeFieldResult describe = field.getDescribe();
if (describe.isAccessible())
{
    myFields.add(describe.getName());
}

Another approach I might try:

Contact dummy = new Contact();
try
{
    dummy.get(describe.getName());
}
catch (SObjectException sOx)
{
    // handle errors
}
  • isAccessible() on the field is returning true.But the SOQL query complains that the field is not there. – jimmy7894 Apr 30 '15 at 22:32
  • You might not believe it but dummy.get(describe..getName()) on islocked field in not throwing exception. I can't believe either. SOQL is still complaining though. – jimmy7894 Apr 30 '15 at 23:02
  • Field level security never applies in Apex Code (e.g. queries). – sfdcfox Apr 30 '15 at 23:20
  • @sfdcfox Agreed.Just gave it a try.Any thoughts on how the describe call is pulling fields like isLocked,accountname,mayedit on Contact. I haven't seen those fields in any version. – jimmy7894 Apr 30 '15 at 23:23
  • This is strange. I think its better to contact Salesforce to understand the root cause for this. Please do let us know the result if you get in touch with them. – the_phantom May 1 '15 at 9:42

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.