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
Abhilash Gupta 10Abhilash Gupta 10 

How to update the Profile's data with metadata api?

Hi All,

Is it possible  to update the profile's data with metadata api?
If yes, then please share the apex code.
For ex: I want to update the CRUD Permissions,FLS,Tab settings etc for all the objects with metadata api.

Regards
Abhilash 
Pankaj PPankaj P

Answer for your question is properly explained here : https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_profile.htm

Also you can consider following example : 

ProfileRecordTypeVisibility[] prtv = new ProfileRecordTypeVisibility[recordTypes.size()];
prtv[0] = new ProfileRecordTypeVisibility();
prtv[0].setRecordType("abc");
prtv[0].setDefault(true);
prtv[0].setVisible(true);

Profile pr = new Profile();
pr.setRecordTypeVisibilities(prtv);
UpdateMetadata ut = new UpdateMetadata();
pr.setFullName("Admin");
ut.setMetadata(pr);
Hope this will help you.

Thanks,
Pankaj.
Abhilash Gupta 10Abhilash Gupta 10
Hi Pankaj,

Thanks for sharing the code.
My requirement is: Suppose in Account we have 1 field which is not visible and read only(Checkbox is not checked).
So i want to update these field data so that visible checkbox and read only checkbox should be checked with the help of metadata api.
Likewise i want to update the whole profile data (FLS,Tab settings,Pagelayout,Apps,Apexclass,VF page).
Can you please share the code.

Regards
Abhilash