5

I have a managed package that creates a custom page layout for the contact object, and I am trying to use the Metadata Api to assign this layout to several profiles. This is a sample of what I have written (in C#)

Login(username, password, token);

var profile = new Profile();
profile.fullName = "Admin";

profile.layoutAssignments = new ProfileLayoutAssignment[1];
profile.layoutAssignments[0] = new ProfileLayoutAssignment();
profile.layoutAssignments[0].layout = "Contact-namespace__New Layout";

var result = metaBinding.updateMetadata(new Metadata[] { profile });

From my understanding, this code should assign the "New Layout" as the Contact object's page layout for the System Administrator profile (assuming there are no record types defined for the Contact object).

At first glance, this appeared to be the case; the result object from the updateMetadata call had its success flag set, and when I checked the Contact page layout assignments for the System Administrator profile, it said that my "New Layout" was the assigned layout. However, when I created a new Contact on a System Administrator user, it was still using the default Contact Layout.

Even stranger, if I manually clicked Edit for the Contact page layout assignment, and immediately clicked save without changing anything, my "New Layout" would take effect. This indicates to me that there is probably an extra step that is performed when manually updating the page layout assignment, that I am not doing through my API calls.

Any suggestions or answers as to what I may be doing incorrectly or what I should do instead would be very much appreciated.

  • I'm having the same issue as you state above. Did you ever figure out what was causing this? – Craig Feb 9 '17 at 18:41
  • Yes I believe I did. It's been a while since I worked on it, and I've left that company since so I don't fully recall the details. I believe the issue I experienced was that some of the characters (not all, such as the space) in the new layout name were being html character encoded (I believe I had a name like "Layout 1.33", and it was being stored as "Layout 1%2E33". What I recommend you do is to try and manually create your layout and assign it in Salesforce, then retrieve the profile through the API and use the layout string returned as the one you use when you're assinging it yourself – Shajesh J Feb 10 '17 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.