0

I wanted to update FLS for the custom fields in Profile level.

@datasert- Thanks for guided me on the right path, I have tried with the code below but after executed the code, changes are not reflecting means FLS is not set as given in code, below is the code I tried

Profile admin = new Profile();
admin.setFullName("Test");
admin.setCustom(false);

ProfileFieldLevelSecurity fieldSec = new ProfileFieldLevelSecurity();
fieldSec.setField("Lead.identitify__TriggerCount__c");
fieldSec.setEditable(false);
fieldSec.setReadable(true);
admin.setFieldPermissions(new ProfileFieldLevelSecurity[]{fieldSec});
System.out.println("dddddddddddddd"+admin);
SaveResult[] results = metadataConnection.updateMetadata(new Metadata[] { admin }); 
for (SaveResult r : results) {
    if (r.isSuccess()) {
        System.out.println("Updated component: " + r.getFullName());
    }
}

Note: I'm seeing the last modified date/time in Profile with my name but field level security is not set for the given fields. Please let me know if I missing anything.

Thanks in Advance!

  • 2
    Why can't you use it? What's the problem? Does it compile? Does it run? Do you get an exception? Please be specific about what's wrong, so we can help you. Please read How to Ask for more information, then edit your question. – sfdcfox Apr 3 '18 at 6:10
  • @sfdcfox - Basically, I need to use metadataservice class through java. For that Do I have to add anything extra to my org wsdl before converting as jar or It comes with default on metadata api wsdl – Arosh Apr 3 '18 at 7:44
  • Do you have the version of wsdlc for the v42.0 release? There is also the force-metadata-api, which may be more appropriate for working with the Metadata API. – Daniel Ballinger Apr 3 '18 at 9:24
1

I think you have taken an example from Apex Metadata API and trying to use it in Java. Go through this ref doc for java example.

Here is the java version (assuming Maven project) in your question.

pom.xml:

<dependency>
      <groupId>com.force.api</groupId>
      <artifactId>force-metadata-api</artifactId>
      <version>41.0.0</version>
</dependency>

Code:

ConnectorConfig config = new ConnectorConfig();
config.setServiceEndpoint(""); // Set metadata url for your org
config.setSessionId(""); // Set the session id you obtained via login call or other means

MetadataConnection api = new MetadataConnection(config);

Profile admin = new Profile();
admin.setFullName("Admin");
admin.setCustom(false);
ProfileFieldLevelSecurity fieldSec = new ProfileFieldLevelSecurity();
fieldSec.setField("Test__c## Heading ##.TestField__c");
fieldSec.setEditable(true);
admin.setFieldPermissions(new ProfileFieldLevelSecurity[] { fieldSec });

api.updateMetadata(new Metadata[] { admin });
|improve this answer|||||
  • Thanks for guided me on the right path, I have tried with the code above but after executed the code, changes are not reflecting means FLS is not setting as given in code, – Arosh Apr 4 '18 at 7:47
  • It was not working due to namespace. We changed it and it got work. Thanks for your guidance. – Arosh Apr 4 '18 at 11:54

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.