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
Héctor Martinez MoltóHéctor Martinez Moltó 

Update managed CustomObjectTranslation with Metadata API (Apex)

I'm trying to update CustomObjectTranslation components with a callout to the Metadata API through Apex and I have been able to accomplish the task for my own custom objects and managed fields from standard objects. The problem is when trying to update those custom objects that come from a managed package. When list the Metadata I can see those components there, but seems like when I try to read them it doesn't returns anything, with or without namespace, I think I've tried everything.

I'm starting to think it's just not possible to read a managed CustomObjectTranslation, although I have no problem when doing the same with CustomObject or CustomField, It's just the translations from managed custom objects that I'm not able to update.
I've been searching the net without success for the last week. Hope somebody knows what I'm doing wrong or just if it can tell me that it's just not possible to do (although if that's the case retrieving that same component with a tool like Ant shouldn't work either and it does).
Petr ChvalaPetr Chvala

Checked it, and its definetly a bug in MDAPI.  Custom Fields related to Custom Object are not returned in the response. Custom fields related to Standard Object are returned correctly.

It might not solve all use cases, but you dont need the fields if you know they exists - just read the CustomObjectTranslation and manually add them and update. It will correctly update translations.

Something like:

                    objectTranslation.fields = new CustomFieldTranslation[]{};
                    CustomFieldTranslation cft = new CustomFieldTranslation();
                    cft.name='Namespace__FieldName__c';
                    cft.label='New Label';
                    objectTranslation.fields.add(cft);

 

Tanmay SoniTanmay Soni
We have followed the above steps @Petr Chvala from your answer, and we can see the updated field label in Translation Workbench in setup. However, the updated field label is not visible on the object's page layout. Do we need to configure any additional settings in Salesforce for this?