I have requirement to update ProfileLoginIpRange on the profile. Lets say there are 5 IP ranges already added on the profile and I want to add 1 more to it.

Code Used,

MetadataService.MetadataPort metaDataPort = new MetadataService.MetadataPort();
metaDataPort.SessionHeader = new MetadataService.SessionHeader_element();
metaDataPort.SessionHeader.sessionId = UserInfo.getSessionId();
MetadataService.Profile existingProfile = new MetadataService.Profile();
existingProfile.fullName = 'Chatter External User';
MetadataService.ProfileLoginIpRange profileLoginIpRange1 = new MetadataService.ProfileLoginIpRange();
profileLoginIpRange1.startAddress = '';
profileLoginIpRange1.endAddress = '';
existingProfile.loginIpRanges   =  new MetadataService.ProfileLoginIpRange[] {profileLoginIpRange1} ;
List<MetadataService.SaveResult> results  = metaDataPort.updateMetadata(new MetadataService.Metadata[] { existingProfile});

My expectation was that this code will add provided IP range into existing list. But after successful execution of this code, Result can be seen that all old IP ranges are vanished and only one will exist on Profile.

is there any way so that I can achieve this functionality. I have one option to fetch existing IP ranges on Profile first and then add new one to that list. But I am looking for some cleaner solution similar to how we do it on Profile UI where only new IP would be added to list.

  • 2
    I've had to use the read/add/write approach elsewhere in the MDAPI so suspect you may well have to do that. – Keith C Feb 14 at 7:50

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.