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
nansi kela 21nansi kela 21 

Can we update records of custom metadata type in Visualforce page

Hi..
I am working with custom meta data type.. now i need to update record of custom  metadata type by edit button in vf page..
so please tell me can we update record of custom metadata  in vf page..

Thanks and regards,
Nansi kela..
 
Best Answer chosen by nansi kela 21
Alan BirchenoughAlan Birchenough
Custom metadata is not updateable using DML, only by using the Metadata API.  (You can query custom metadata via SOQL, but any updates have to go via Metadata API.)

You can attempt to do this via Apex with the aid of something like the FinancialForce Apex Wrapper for Salesforce Metadata API (https://github.com/financialforcedev/apex-mdapi), or your calls to the Metadata API can be performed in Javascript on the VF page.  In either case, a Remote Site definition is needed to provide security clearance to access the Metadata API URL.

All Answers

Krishna SambarajuKrishna Sambaraju
Can you give more details on this custom metadata type you want to update?
nansi kela 21nansi kela 21
Hi krishna..

I want to  update record of custom metadata type object from apex controller.


Thank you,
Nansi kela..
 
Krishna SambarajuKrishna Sambaraju
Can you share the visualforce page and the controller, so I can understand what you are trying to do?
Alan BirchenoughAlan Birchenough
Custom metadata is not updateable using DML, only by using the Metadata API.  (You can query custom metadata via SOQL, but any updates have to go via Metadata API.)

You can attempt to do this via Apex with the aid of something like the FinancialForce Apex Wrapper for Salesforce Metadata API (https://github.com/financialforcedev/apex-mdapi), or your calls to the Metadata API can be performed in Javascript on the VF page.  In either case, a Remote Site definition is needed to provide security clearance to access the Metadata API URL.
This was selected as the best answer
Douglas C. AyersDouglas C. Ayers
You might also be interested in the apex/visualforce Custom Metadata Loader (https://github.com/forcedotcom/CustomMetadataLoader) by Salesforce. It's open source on GitHub and, as Alan mentioned, has to make use of the Metadata API behind the scenes.