0

To test updating a custom object field via a trigger, I'm executing an update in Execute Anonymous to test the code. My test works on standard objects (Contact), but it doesn't recognize my custom object (Project) which is also in a managed package. Profiles allow me to update the object. The Error msg. is: Invalid Type:(Project). It references the 1st line 'List'. Please advise.

    List<Project> projs = [SELECT Id FROM Project Where   Project.PT_PIPROJ__PI_Outbound_Msg_Sent__c = True];     
for(Project project  :projs){ 
    Project.PT_PIPROJ__PI_Outbound_Msg_Sent__c = False; } 
    update projs; 
1

Custom objects in a managed package org have a namespace prefix (e.g. yourns__) automatically added and the custom object suffix (__c) automatically added.

So if you created an object called "Project", the API name you need to use in Execute Anonymous would be yourns__Project__c.

So if the managed package namespace is "PT_PIPROJ":

List<PT_PIPROJ__Project__c> projs = [
        SELECT Id
        FROM PT_PIPROJ__Project__c
        Where PT_PIPROJ__PI_Outbound_Msg_Sent__c = True
        ];     
for (PT_PIPROJ__Project__c proj : projs) { 
    proj.PT_PIPROJ__PI_Outbound_Msg_Sent__c = False;
} 
update projs; 
0

Please refer this documentation which has details about Custom objects in Salesforce and its naming conventions:

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_custom_objects.htm

In the API, the names of custom objects include a suffix of two underscores followed by a lowercase “c” . For example, a custom object labeled “Issue” in the Salesforce user interface is Issue__c in that organization’s WSDL.

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.