2

My requirement needs to change the "from email address" for the welcome mail that is sent from a community after a new user is registered. But this needs to be done dynamically based on some conditions.

For this I have written the following snippet of code.

    network n;
    n=[Select Id, EmailSenderAddress, NewSenderAddress from network limit 1]; // This is working fine
    n.NewSenderAddress='abc@xyz.com';
    update n;//Error on this line

I am not sure why is this throwing error "DML not allowed on Network".

There are no proper examples available.

The documentations available are- https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_network.htm

https://help.salesforce.com/HTViewHelpDoc?id=networks_customize_email.htm&language=en_US

Can someone please help me in understanding and resolving this issue? Thanks!

Edit

I am sharing a dummy code here explaining what I am trying to do:

public class xyz {
public String createUser(String emailAddress, String firstName, String lastName, String phNumber, String accountId){
    User newUser = new User();
    newUser.FirstName = firstName;
    newUser.LastName = lastName;
    newUser.Username = emailAddress;
    newUser.Email = emailAddress;
    newUser.Phone = phNumber;

    network n;
    n=[Select Id, EmailSenderAddress, NewSenderAddress from network limit 1]; // This is working fine
    n.NewSenderAddress='abc@xyz.com';
    update n;//Error on this line

    String userId;
    try{
        userId = Site.createPortalUser(newUser, accountId, null, true);
    }
    catch(Exception e){
        System.debug('error');
    }
    return userId;
  }
}
  • did you check if you or the user under which this code is running have the required permissions to create/setup communities ? – Vamsi Krishna Jun 25 '15 at 11:38
  • I have the permission, so essentially i should be able to save the controller atleast. The controller is not getting saved in the first place. – DebaSen Jun 25 '15 at 11:54
  • can you share your complete controller code.. r u doing this in a constructor ? – Vamsi Krishna Jun 25 '15 at 12:01
  • I have added a demo code block which is similar to what I am trying to do. – DebaSen Jun 25 '15 at 12:32
1

I would say its either a bug in salesforce or a gap in salesforce docs.

I just tried the code in Developer Console - anonymous window and getting the same error.

Network n =[Select Id, EmailSenderAddress, NewSenderAddress from Network limit 1];
n.NewSenderAddress='abc@xyz.com';
update n;

enter image description here

The Object specification says update is possible and the list of SObjects not supporting DML is not listing Network object which means DML / Update is possible on Network object.

You should raise a case with salesforce and see what they can do with this.

  • Thanks. And can you suggest me any other workaround? – DebaSen Jun 25 '15 at 13:41

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.