[SalesForce] Apex Describe Field pulling unavailable field for SOQL

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?

Best Answer

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.

Related Topic