Saturday, 27 February 2016

Sending an email notification to Admin whenever a field is created or deleted for a custom object in salesforce

S.No Component
1 Create New Object
Singular Label: ObjectsExistingFieldsInfo
Plural Label: ObjectsExistingFieldsInfos
Object Name: ObjectsExistingFieldsInfo
Standard Field
Field Label: ObjectsExistingFieldsInfo
Data Type: Auto Number
Display Format: ObjInfo-{000}
2 Create New Field
Object Name: ObjectsExistingFieldsInfo
Field Label: Field API Name
Field Name: Field_API_Name
Data Type: Text (255)
3 Create New Field
Object Name: ObjectsExistingFieldsInfo
Field Label: Fields Count
Field Name: Fields_Count
Data Type: Number (18,0)
4 Create New Field
Object Name: ObjectsExistingFieldsInfo
Field Label: Fields Info
Field Name: Fields_Info
Data Type: Long Text Area
Notes-
  • We cannot create trigger on 'Object' or 'Field'.
  • Alternative is creating a Batch Class and schedule it as per the requirement.
  • To store the history of the fields we can user either list custom settings or custom object.
  • List Custom Settings is not supporting Text Area Long.
  • To store the history of the fields we need Text Area Long (255 character for text area data type is not sufficient.) field which is possible with the custom object.

8 comments:

  1. I had executed above code in my developer instance without any errors but i didn't get mail notification when field is create and field is delete.. please help me

    ReplyDelete
    Replies
    1. 1. Please populate your email address in 'system.label.Dev_Admin'.
      2. Execute once (you don't receive email).
      3. 2nd time please create/delete a field and execute one more time.
      4. If your email address is valid you should get an email.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. I populated my email even then I didn't receive any email. How is this batch apex getting triggered first of all?

      Delete
  2. Great work. good scenario ... thank you very much.

    ReplyDelete
  3. your post vry helpful i m fresher
    when i m trying this code i m getting this errorError "Error: Compile Error: unexpected token: '@' at line 74 column 52" actually i m replced mailid in place of "system.label.Dev_Admin" if i did not replace i m getting this error "Error Error: Compile Error: Invalid external string name: dev_admin at line 74 column 46
    "

    ReplyDelete
  4. please i m waiting your response i hope i will get ASAP
    THANK YOU

    ReplyDelete


  5. Hai Author, Very Good informative blog post,
    Thanks for Sharing

    ReplyDelete