I needed to first create some Record Types for some custom objects using Metadata. After doing those, I was to upsert the records on those custom objects using the RecordTypeId.
I noticed one thing that one needs to set the visibility of the Record Types from Profile otherwise the Error comes - something like Invalide RecordTypeId for the User.
So, I have the flow of my application set from Java as
First create the Record Types, thereafter fetch the RecordTypeID and then upsert the records on the custom object I need to target.
So, I need to update the Profile using Metadata API itself to set the visibility of Record Types as:
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("System_Administrator");
ut.setMetadata(pr);
So, I'm getting the Error like
com.sforce.ws.SoapFaultException: INVALID_CROSS_REFERENCE_KEY: In field: fullName - no Profile named System_Administrator found.
I have even tried System Administrator, Profile, Profile.System_Administrator but none worked for me.
The Salesforce doc says for the Profile object's fullName field: It must be specified when creating, updating, or deleting
.
Please let me know what I'm doing wrong or is there anything else I can go for.
Thanks