Hi ,
please try the following code.
LogisticsLocation contactLogisticsLocation,addressLogisticsLocation;
LogisticsPostalAddress postalAddress;
DirPartyContactInfoView dirPartyContactInfo;
LogisticsContactInfoView contactInfoView;
LogisticsElectronicAddress elecAddress;
;
// find the new address you have added
postalAddress = LogisticsPostalAddress ::findRecId(37262525);
addressLogisticsLocation = LogisticsLocation::find(postalAddress.location);
contactLogisticsLocation.clear();
contactLogisticsLocation.initValue();
contactLogisticsLocation.ParentLocation = LogisticsLocation::findByLocationId (addressLogisticsLocation.LocationId).RecId;
contactLogisticsLocation.IsPostalAddress = NoYes::No;
contactLogisticsLocation.insert();
dirPartyContactInfo.LocationName = "Main email";
dirPartyContactInfo.Locator = "test@mail.com";
dirPartyContactInfo.Type = LogisticsElectronicAddressMethodType::Email;
dirPartyContactInfo.IsPrimary = NoYes::Yes;
dirPartyContactInfo.Location = contactLogisticsLocation.RecId;
// Create electronic address
elecAddress.initValue();
contactInfoView.initFromPartyContactInfoView(dirPartyContactInfo);
elecAddress = LogisticsElectronicAddressEntity::initFromLogisticsContactInfoView(contactInfoView, elecAddress);
// Insert
if (elecAddress.validateWrite())
elecAddress.insert();