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
Saurabh Kulkarni 20Saurabh Kulkarni 20 

Create/Update Profiles Through Metadata API

Hello All,

I was trying to update an exsting profile with few permissions to the custom object but I was getting some errors while doing these...
I also tried creating a new profile throgh APIs but it doesn't worked.

Below is the snippet of my code.. Please let mw know if I'm missing something in this code...
 
ProfileObjectPermissions pObj = new ProfileObjectPermissions();
		
		pObj.setAllowCreate(true);
		pObj.setAllowEdit(true);
		pObj.setAllowDelete(true);
		pObj.setObject("Accounts");
		pObj.setModifyAllRecords(true);
		
Profile p = new Profile();
		
		p.setObjectPermissions(new ProfileObjectPermissions[] {pObj});
		p.setCustom(true);
		p.setUserLicense("Salesforce Platform");
		p.setFullName("TestClient1");

//For Update I used....
SaveResult[] results = metadataConnection.updateMetadata(new Metadata[]{p});

//For Create I used...
SaveResult[] results = metadataConnection.CreateMetadata(new Metadata[]{p});

However, If i try to creat a custom field with same logic, it gets created...
But creating or updating a profile fails everytime...

Please advise with a solution

Thanks in advance!
Saurabh 
 
TomSnyderTomSnyder
include the CustomObject  'Account'  in your package.
TomSnyderTomSnyder
I would also suggest you perform a retrieve first of both the account and profile (if avail) make the changes and then push back both the account and profile.
Saurabh Kulkarni 20Saurabh Kulkarni 20
Thanks Tom for the reply!

I tried retrieving the profile and object information and found that, the object name I used was wrong...
Correcting the name of object name helped me.. 

Thanks
Saurabh