• Aidel Bruck
  • NEWBIE
  • 65 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 57
    Questions
  • 55
    Replies
Hi, 
I would like a visualforce page to display an alert and then update a field on the record. 
I am probably missing something here. 
Right now I am getting an error DML currently not allowed.

This is the VF page

<apex:page standardController="Other_Grant__c" extensions="MedicaidAlertController" >

  <script>
  window.onload = function()
  {
      var alertDisplayed="{!alertDisplayed}";
      
        if('{!Other_Grant__c.Medicaid_policies_count__c}'> 0 && alertDisplayed)
            alert('Patient has a medicaid insurance plan, please verify elibility for rides through insurance.');
            
            }
    </script>
</apex:page>

This is the extension

public with sharing class MedicaidAlertController {

    Public id otherGrantid;
    Public Other_Grant__c otherGrantrec{get;set;}
    public boolean alertDisplayed{get;set;}
    Public Other_Grant__C OtherGrantToUpdate= new Other_Grant__C();

    public MedicaidAlertController (ApexPages.StandardController controller)     
    {     
     System.debug(' '+ alertDisplayed);
     otherGrantid = ApexPages.currentPage().getParameters().get('id');
     System.debug('Got ID: ' + otherGrantid);
        if(otherGrantid != null)
      {
      
          otherGrantrec= [select id,Medicaid_Alert_Displayed__c from Other_Grant__C where id =:otherGrantid];
          alertDisplayed=otherGrantrec.Medicaid_Alert_Displayed__c;
               System.debug(' '+ alertDisplayed);
          if(alertDisplayed== false)
              UpdateAlertDisplayed(AlertDisplayed);             
          }
        
    }
   
   Public void updateAlertDisplayed(Boolean AlertDisplayed)
          {
             if(alertDisplayed== false)
                OtherGrantToUpdate.id= othergrantrec.Id;
                OtherGrantToUpdate.Medicaid_Alert_Displayed__c=true;
                Update OtherGrantToUpdate;
          }
}
I have a collection of a custom object 'payments' that stores all the payments with a certain status. 
Then these payments are displayed in a datatable and users can select multiple payments. 
As a result I now have another collection with the selected record Ids. 
How can I get a third collection of only payments with Ids that do not appear in the selected collection without using multiple loops- I keep on hitting limits.
I tried creating an apex class but it seems like invocable methods cannot get and return lists.
I need to a way to have a field on custom objects for an alert that will popup when the record is opened.
What is the best way to go about this?
I need a field on a parent object that summarizes a child object based on dates.
Since Rollup summary fields cannot use dates I am assuming I have to create some sort of custom component. 
For example, accounts is the parent. Custom object 'payments' is the child. 
I want a field on the account that counts how many payments there are with the status paid and check date within the last 6 months 
I would appreciate being pointed in the right direction.
Thank you
Hi, 
I have a trigger that has the following assignment service.Service_Termination_Date__c = comReview.Final_Approval_End_Date__c;
when Final_Approval_End_Date__c;= 12/31/21
the service.Service_Termination_Date__c= 1/1/22
Why does this happen?
 
I wrote the following page and controller. 
The page displays an alert when field equals a specific value.
I want the alert to display when the value is changed to that value.

Here is the page

<apex:page standardController="Opportunity" extensions="OpportunityController"> <script> window.onload = function() { var servicestatus= "{!servstatus}"; var servicename = "{!servname}"; var hasprcomment= "{!hasprcomments}"; if(typeof(servicestatus) != "undefined" && typeof(servicename) != "undefined") { if( hasprcomment== 'false') { alert('Please be aware that you are closing a service that does not have any pr comments in the related account'); } } }; </script> </apex:page>

This is the controller
public with sharing class OpportunityController 
{
  public id serviceID;
    
  
    Public opportunity servRec{get;set;}
    Public account accountRec{get;set;}
    public string Servname{get; set;}
    public string ServStatus{get;set;}
    public boolean hasprcomments{get;set;}
    
    public OpportunityController(ApexPages.StandardController controller) 
    {     
     Serviceid = ApexPages.currentPage().getParameters().get('id');
      if(serviceid != null)
      {
          ServRec= [select id, account_name__c, stagename, Service_status__C from Opportunity where id =:serviceId];
 
         if(servrec.account_name__c!= null)  
       {
         accountRec = [select id,pr_comment__C from account where id =:servrec.account_name__C];
         if(accountrec.pr_comment__C==null&& (servrec.StageName== 'closed'|| servrec.Service_Status__c== 'closed'))
           hasprcomments= false;
         else
           hasprcomments= true;
    
       }  
     }
    
    }

}
Hi, 
I have a trigger that triggers after a file is uploaded. 
I recently installed a button from the app exchange that allows multiple files to be uploaded at once. 
When uploaded files using this button my trigger does not execute. 
 I looked in the log and it seems like as soon the file is uploaded the installed package takes over completely. 
Any way to get around this and have my trigger execute too?
Hi,  
This is my use case- 
When a file is uploaded I would like it to be shared automatically with a few users. 
I don't want the uploader to do it manually. 
Is there any way to right code that will take of this?
I have a picklist field on a flow that is displaying a record choice set of all accounts. 
The user will choose the account that he needs. 
The list is too long and the picklist is not showing all the accounts. 
I would like the user to be able to type the beggining of the account name and the list will jump to the right one. 
(Pretty standard functionality in other forms) 
Is there any way to do this is in flows?
Is there any way I can setup the email fields that they are clickable?
I would like to be able to click on the email address and to be redirected to a blank email with the said email address  
Hello all, 
My org specializes in referrals. 
We have many contact records. Each record has a speciality, location, and other such critiria.
When I want to make a refferal I need an easy way to enter the requested critiria and the relevant contact should come up. 
Can anybody point me in the right direction?
Hello, 
My org specializes in referrals. 
We have many contact records. Each record has a speciality, location, and other such critiria.
When I want to make a refferal I need an easy way to enter the requested critiria and the relevant contact should come up. 
Can anybody point me in the right direction?
How to create an alert with input fields
I need a way to have an alert that comes up only if a certain field is true. 
I need this alert to have input fields. 
I created the following visual force page, but it is not an alert. 
I need a way to create such an alert.

<apex:page standardController="Comment__c" rendered="{!if(Comment__c.Care_Management_Related2__c==true,true,false)}">
<apex:form >
        <apex:pageBlock title="Enter Care Management Call Details">
            <apex:pageBlockSection title="Next Suggested Call" columns="1">
                <apex:inputField value="{!Comment__c.Next_Suggested_Call_Date__c}"
                label="next suggested call date"/>
                <apex:inputText value="{!Comment__c.Next_Suggested_Call_Description__c}"
                    label="Next Suggested Call Description"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
I need a way to have an alert that comes up only if a certain field is true. 
I need this alert to have input fields. 
I created the following visual force page, but it is not an alert. 
I need a way to create such an alert.

<apex:page standardController="Comment__c" rendered="{!if(Comment__c.Care_Management_Related2__c==true,true,false)}">
<apex:form >
        <apex:pageBlock title="Enter Care Management Call Details">
            <apex:pageBlockSection title="Next Suggested Call" columns="1">
                <apex:inputField value="{!Comment__c.Next_Suggested_Call_Date__c}"
                label="next suggested call date"/>
                <apex:inputText value="{!Comment__c.Next_Suggested_Call_Description__c}"
                    label="Next Suggested Call Description"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
I am assuming that what I trying to do is pretty basic, I am just fairly new to visual force

I would like an alert to show if a certain condition is met. In this alert I would like to have input fields that can be saved to the record. 

I created this visual force page, but it is not an alert. 
How can I make it into an alert?

<apex:page standardController="Comment__c" rendered="{!if(Comment__c.Care_Management_Related2__c==true,true,false)}">
<apex:form >
        <apex:pageBlock title="Enter Care Management Call Details">
            <apex:pageBlockSection title="Next Suggested Call" columns="1">
                <apex:inputField value="{!Comment__c.Next_Suggested_Call_Date__c}"
                label="next suggested call date"/>
                <apex:inputText value="{!Comment__c.Next_Suggested_Call_Description__c}"
                    label="Next Suggested Call Description"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
I need to have a custom onclick java button on the opportunity record to open a new case AND to update a field on the opportunity. 

Here is what I have so far. 

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} 
var Opportunity = new sforce.SObject("Opportunity"); 
Opportunity.ID = '{!Opportunity.Id}'; 
Opportunity.case_created__C = 1; 

result = sforce.connection.update([Opportunity]); 

How do I add the new case?
 
I am trying to get the list of all the opportunity record types by using the following code

 Map<String,Schema.RecordTypeInfo> opprecordTypeMapByName= new Map<String,Schema.RecordTypeInfo>();
opprecordTypeMapByName = Schema.SObjectType.Opportunity.getRecordTypeInfosByName();
But the opprecordtypemapbyname only contains a few record types and not everything. 
Any ideas why?
 
I have a trigger and and a test class. 
In the sandbox the code coverage is 96% 
But in production only 37%
The thing is, Total coverage in production is 88%, so I  have no idea what the issue could be.
This is the trigger and test class

trigger DoubleAccountName on Account (after insert, after update) 
{

    decimal i=0;
    list<account> accountstoupdate= new list<account>();
    account accounttoupdate= new account();
    set<string> accountnames= new set<string>();
    set<id> accountids= new set<id>();
    system.debug('new trigger '+trigger.new);
        for(account a: trigger.new)
        {
            if(a.FirstName== '')
                accountnames.add(a.LastName);
            else
                accountnames.add(a.firstname+' '+a.lastname);
            accountids.add(a.id);
        }
            
    //system.debug(accountnames);
    //system.debug(accountids);
        

    list<account> allaccountswithname= [select original_last_name__C, firstname, lastname, name, namecount__C from account where original_last_name__c in: accountnames and id not in: accountids];
    //stem.debug('all accounts with names .'+allaccountswithname);
    
    if(trigger.isinsert)
    {
       
            if(!allaccountswithname.isEmpty())
            {
                
                for(account a: trigger.new)
                {
                    for(account matchingaccount: allaccountswithname)
                    {
                        //stem.debug('a in loop '+ a);
                        i=0;
                        if(a.FirstName+' '+a.LastName== matchingaccount.Original_last_name__c)
                            if(i<matchingaccount.namecount__C)
                                i= matchingaccount.namecount__C;
                    }  
                        
                        accounttoupdate.id = a.id;
                        //stem.debug('account name insert '+ accounttoupdate.LastName);
                        accounttoupdate.namecount__c= i+1;
                        accounttoupdate.FirstName= a.FirstName;
                        accounttoupdate.Lastname=a.lastname+(i+1);
                        accounttoupdate.Check_for_account_duplicate__c= true;    
                        accounttoupdate.Original_last_name__c= a.FirstName+' '+ a.Last_Name__c;
                        accountstoupdate.add(accounttoupdate);
                }
                
                
                
             if(!accountstoupdate.isEmpty())
                update accountstoupdate;   
                
            }
             
           
        }
        
    
        
    
    
    
    if(trigger.isupdate)
    {
        for(account a: trigger.new)
            for(account aold: trigger.old)
            if((a.firstname!= aold.firstname || a.lastname!= aold.lastname )&& aold.Check_for_account_duplicate__c== false)
            {
                
                if(!allaccountswithname.isEmpty())
                {
                    for(account matchingaccount: allaccountswithname)
                    {
                        i=0;
                        if(a.FirstName+' '+a.LastName== matchingaccount.Original_last_name__c)
                            if(i<matchingaccount.namecount__C)
                                i= matchingaccount.namecount__C;
                    }
                        //stem.debug('update last name '+accounttoupdate.Lastname);
                        accounttoupdate.id = a.id;
                        accounttoupdate.namecount__c= i+1;
                        accounttoupdate.FirstName= a.FirstName;
                        accounttoupdate.Lastname=a.LastName+(i+1);
                        accounttoupdate.Check_for_account_duplicate__c= true;    
                        accounttoupdate.Original_last_name__c= a.FirstName+' '+ a.Last_Name__c;
                        accountstoupdate.add(accounttoupdate);
                }
            } 
                
                
             if(!accountstoupdate.isEmpty())
             {
                 update accountstoupdate;  
                 //stem.debug('accountstoupdate '+accountstoupdate);
             }
                 
        }
                
       
    


}


@isTest
public class TestDoubleAccountName 
{
    public static testmethod void MyUnitTest()
    {
        
       test.startTest();
        
        account a= testdatafactory.createPersonAccount('test');
        insert a;
        
        print('firsta', a);
        
        account a2= testdatafactory.createpersonaccount('test');
        insert a2;
        print('seconda', a2);
        
        a.LastName= 'patient1';
        a.Check_for_account_duplicate__c= false;
        update a;
        print('update a', a);
        
        account a3= testdatafactory.createpersonaccount('alligator');
        a3.LastName= 'bumbelbie';
        insert a3;
        
        a3.FirstName= 'test';
        a3.Lastname= 'patient';
        update a3;
            
        print('update a3', a3);
      
        test.stopTest();
        
    }
    
    public static void print(string message, account a)
    {
        list<account> atoprint= [select id, name, Check_for_account_duplicate__c, namecount__C from account where id=: a.id];
        system.Debug(message);
        system.debug(atoprint);
    }

}
I am uploading a document throught the account object. 
When I query the linkedEntityId through the contentdocument link I get the user ID and not the account ID. 
How can I get to the account ID?
I am having trouble with a query on contentdocumentlink.
I upload a document to an account. Then I query the contentdocumentlink to get the linkentityid and I get a different id.
Any idea why this is happening. 
Here is the test class and the query.

query from trigger:

list<account> a= new list<account>();
 list<ContentDocumentlink> doc= [select id, LinkedEntityId from contentdocumentlink where contentdocumentid=: newdoc.ContentDocumentId];
      System.debug(doc);
  if(!doc.isempty())
            A= [select name, id from account where id=: doc[0].LinkedEntityId];
      system.debug(a);

This is the test code
@isTest
public class TestNewFileAlert 
{

    public static testmethod void MyUnitTest()
    {
           Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
        User futureUser = new User(firstname = 'Future', lastname = 'User',
                                   alias = 'future', defaultgroupnotificationfrequency = 'N',
                                   digestfrequency = 'N', email = 'test@test.org',
                                   emailencodingkey = 'UTF-8', languagelocalekey='en_US', 
                                   localesidkey='en_US', profileid = p.Id, 
                                   timezonesidkey = 'America/Los_Angeles',
                                   username = 'futureasdasdasuser@test.org',
                                   userpermissionsmarketinguser = false,
                                   userpermissionsofflineuser = false, userroleid= null);
        insert(futureUser);
        System.runAs(futureUser)
        {
            
            Account acct = new Account(Name='TEST_ACCT');
            insert acct;
            system.debug(acct);
            
            ContentVersion contentVersion = new ContentVersion
            (
                Title = 'Penguins',
                PathOnClient = 'Penguins.jpg',
                VersionData = Blob.valueOf('Test Content'),
                IsMajorVersion = true
            );
            insert contentVersion; 
            Test.setCreatedDate(contentVersion.Id, DateTime.now());
            
            List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];
            
            //create ContentDocumentLink  record 
            ContentDocumentLink cdl = New ContentDocumentLink();
            cdl.LinkedEntityId = acct.id;
            cdl.ContentDocumentId = documents[0].Id;
            cdl.shareType = 'V';
            insert cdl;
            Test.setCreatedDate(cdl.Id, DateTime.now());
        }

    }
}
I am assuming that what I trying to do is pretty basic, I am just fairly new to visual force

I would like an alert to show if a certain condition is met. In this alert I would like to have input fields that can be saved to the record. 

I created this visual force page, but it is not an alert. 
How can I make it into an alert?

<apex:page standardController="Comment__c" rendered="{!if(Comment__c.Care_Management_Related2__c==true,true,false)}">
<apex:form >
        <apex:pageBlock title="Enter Care Management Call Details">
            <apex:pageBlockSection title="Next Suggested Call" columns="1">
                <apex:inputField value="{!Comment__c.Next_Suggested_Call_Date__c}"
                label="next suggested call date"/>
                <apex:inputText value="{!Comment__c.Next_Suggested_Call_Description__c}"
                    label="Next Suggested Call Description"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Hi, 
I would like a visualforce page to display an alert and then update a field on the record. 
I am probably missing something here. 
Right now I am getting an error DML currently not allowed.

This is the VF page

<apex:page standardController="Other_Grant__c" extensions="MedicaidAlertController" >

  <script>
  window.onload = function()
  {
      var alertDisplayed="{!alertDisplayed}";
      
        if('{!Other_Grant__c.Medicaid_policies_count__c}'> 0 && alertDisplayed)
            alert('Patient has a medicaid insurance plan, please verify elibility for rides through insurance.');
            
            }
    </script>
</apex:page>

This is the extension

public with sharing class MedicaidAlertController {

    Public id otherGrantid;
    Public Other_Grant__c otherGrantrec{get;set;}
    public boolean alertDisplayed{get;set;}
    Public Other_Grant__C OtherGrantToUpdate= new Other_Grant__C();

    public MedicaidAlertController (ApexPages.StandardController controller)     
    {     
     System.debug(' '+ alertDisplayed);
     otherGrantid = ApexPages.currentPage().getParameters().get('id');
     System.debug('Got ID: ' + otherGrantid);
        if(otherGrantid != null)
      {
      
          otherGrantrec= [select id,Medicaid_Alert_Displayed__c from Other_Grant__C where id =:otherGrantid];
          alertDisplayed=otherGrantrec.Medicaid_Alert_Displayed__c;
               System.debug(' '+ alertDisplayed);
          if(alertDisplayed== false)
              UpdateAlertDisplayed(AlertDisplayed);             
          }
        
    }
   
   Public void updateAlertDisplayed(Boolean AlertDisplayed)
          {
             if(alertDisplayed== false)
                OtherGrantToUpdate.id= othergrantrec.Id;
                OtherGrantToUpdate.Medicaid_Alert_Displayed__c=true;
                Update OtherGrantToUpdate;
          }
}
I need to a way to have a field on custom objects for an alert that will popup when the record is opened.
What is the best way to go about this?
Hi, 
I have a trigger that has the following assignment service.Service_Termination_Date__c = comReview.Final_Approval_End_Date__c;
when Final_Approval_End_Date__c;= 12/31/21
the service.Service_Termination_Date__c= 1/1/22
Why does this happen?
 
Is there any way I can setup the email fields that they are clickable?
I would like to be able to click on the email address and to be redirected to a blank email with the said email address  
I need to have a custom onclick java button on the opportunity record to open a new case AND to update a field on the opportunity. 

Here is what I have so far. 

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} 
var Opportunity = new sforce.SObject("Opportunity"); 
Opportunity.ID = '{!Opportunity.Id}'; 
Opportunity.case_created__C = 1; 

result = sforce.connection.update([Opportunity]); 

How do I add the new case?
 
I am having trouble with a query on contentdocumentlink.
I upload a document to an account. Then I query the contentdocumentlink to get the linkentityid and I get a different id.
Any idea why this is happening. 
Here is the test class and the query.

query from trigger:

list<account> a= new list<account>();
 list<ContentDocumentlink> doc= [select id, LinkedEntityId from contentdocumentlink where contentdocumentid=: newdoc.ContentDocumentId];
      System.debug(doc);
  if(!doc.isempty())
            A= [select name, id from account where id=: doc[0].LinkedEntityId];
      system.debug(a);

This is the test code
@isTest
public class TestNewFileAlert 
{

    public static testmethod void MyUnitTest()
    {
           Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
        User futureUser = new User(firstname = 'Future', lastname = 'User',
                                   alias = 'future', defaultgroupnotificationfrequency = 'N',
                                   digestfrequency = 'N', email = 'test@test.org',
                                   emailencodingkey = 'UTF-8', languagelocalekey='en_US', 
                                   localesidkey='en_US', profileid = p.Id, 
                                   timezonesidkey = 'America/Los_Angeles',
                                   username = 'futureasdasdasuser@test.org',
                                   userpermissionsmarketinguser = false,
                                   userpermissionsofflineuser = false, userroleid= null);
        insert(futureUser);
        System.runAs(futureUser)
        {
            
            Account acct = new Account(Name='TEST_ACCT');
            insert acct;
            system.debug(acct);
            
            ContentVersion contentVersion = new ContentVersion
            (
                Title = 'Penguins',
                PathOnClient = 'Penguins.jpg',
                VersionData = Blob.valueOf('Test Content'),
                IsMajorVersion = true
            );
            insert contentVersion; 
            Test.setCreatedDate(contentVersion.Id, DateTime.now());
            
            List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];
            
            //create ContentDocumentLink  record 
            ContentDocumentLink cdl = New ContentDocumentLink();
            cdl.LinkedEntityId = acct.id;
            cdl.ContentDocumentId = documents[0].Id;
            cdl.shareType = 'V';
            insert cdl;
            Test.setCreatedDate(cdl.Id, DateTime.now());
        }

    }
}
Hello all, 
I am really having trouble for the past week and have not gotten any solutions thus far.

I wrote a trigger to send an email every time a file is uploaded, 
It has 100% coverage and from the log it is apparent that the email is sent out
The setting for deliveribilty is set to all emails, and I tested deliveribility with success.
And yet I am not getting the email

Can anybody help me figure out why??

This is the code
trigger NewFileAlert on ContentDocument (after insert) 
{
// Step 0: Create a master list to hold the emails we'll send
  List<Messaging.SingleEmailMessage> mails = 
  new List<Messaging.SingleEmailMessage>();
  
  for (ContentDocument newDoc : Trigger.new) 
  {
     // Step 1: Create a new Email
          Messaging.SingleEmailMessage mail = 
          new Messaging.SingleEmailMessage();
    
          // Step 2: Set list of people who should get the email
          List<String> sendTo = new List<String>();
          sendTo.add('test@gmail.com');
....
          mail.setToAddresses(sendTo);
    
          // Step 3: Set who the email is sent from
          mail.setReplyTo('me@gmail.com');
          mail.setSenderDisplayName('Aidel Bruck');
    
       
          // Step 4. Set email contents - you can use variables!
          mail.setSubject('New Document Added');
          String body = 'Please note: A new document has been added/n  ';
          body += 'File name: '+ newdoc.title+'/n' ;
          body += 'Created By: '+ newdoc.createdbyid+ '/n';
          body += 'Created Date: '+ newdoc.CreatedDate+ '/n';
          body += 'link to file: '+ System.URL.getSalesforceBaseUrl().getHost()+newdoc.id;
          mail.setHtmlBody(body);
    
          // Step 5. Add your email to the master list
          mails.add(mail);
    }
    
  // Step 6: Send all emails in the master list
   Messaging.SendEmailResult[] results = Messaging.sendEmail(mails);
 if (results[0].success) {
    System.debug('The email was sent successfully.');
 } else {
    System.debug('The email failed to send: '
          + results[0].errors[0].message);
 }
  
}


Thanks!
I posted this question yesterday, but didn't really get any solutions, so here goes again:
 have the following trigger that is obviously working (I checked the log), But no email is being sent out.
I check that the deliveribility is set to 'all emails' 
I checked the single email limits and they are fine, 
I piut the messaging.send() into an asycronous function
And still no luck

Please advice

This is the code

trigger NewFileAlert on ContentDocument (after insert) 
{

  List<Messaging.SingleEmailMessage> mails = 
  new List<Messaging.SingleEmailMessage>();
  
  for (ContentDocument newDoc : Trigger.new) 
  {
      
      Messaging.SingleEmailMessage mail = 
      new Messaging.SingleEmailMessage();
    
      
      List<String> sendTo = new List<String>();
      sendTo.add(allthepeople@everybody.com);
       ...
      mail.setToAddresses(sendTo);
    
      mail.setReplyTo('me@gmail.com');
      mail.setSenderDisplayName('Aidel Bruck');
   
      mail.setSubject('New Document Added');
      String body = 'Please note: A new document has been added/n  ';
      body += 'File name: '+ newdoc.title+'/n' ;
      body += 'Created By: '+ newdoc.createdbyid+ '/n';
      body += 'Created Date: '+ newdoc.CreatedDate+ '/n';
      body += 'link to file: '+ System.URL.getSalesforceBaseUrl().getHost()+newdoc.id;
      mail.setHtmlBody(body);

      mails.add(mail);
    }
  Messaging.sendEmail(mails);
I have the following trigger that is obviously working (I checked the log), But no email is being sent out.
I check that the deliveribility is set to 'all emails' 
Please advice

This is the code

trigger NewFileAlert on ContentDocument (after insert) 
{

  List<Messaging.SingleEmailMessage> mails = 
  new List<Messaging.SingleEmailMessage>();
  
  for (ContentDocument newDoc : Trigger.new) 
  {
      
      Messaging.SingleEmailMessage mail = 
      new Messaging.SingleEmailMessage();
    
      
      List<String> sendTo = new List<String>();
      sendTo.add(allthepeople@everybody.com);
       ...
      mail.setToAddresses(sendTo);
    
      mail.setReplyTo('me@gmail.com');
      mail.setSenderDisplayName('Aidel Bruck');
   
      mail.setSubject('New Document Added');
      String body = 'Please note: A new document has been added/n  ';
      body += 'File name: '+ newdoc.title+'/n' ;
      body += 'Created By: '+ newdoc.createdbyid+ '/n';
      body += 'Created Date: '+ newdoc.CreatedDate+ '/n';
      body += 'link to file: '+ System.URL.getSalesforceBaseUrl().getHost()+newdoc.id;
      mail.setHtmlBody(body);

      mails.add(mail);
    }
  Messaging.sendEmail(mails);
}
This is my trigger And the test class
When running the test class I get 100% coverage yet the test fails and I get the following error:

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_ARGUMENT_TYPE, The argument is null or invalid.: []

Trigger

trigger NewFileAlert on ContentDocument (after insert) 
{
// Step 0: Create a master list to hold the emails we'll send
  List<Messaging.SingleEmailMessage> mails = 
  new List<Messaging.SingleEmailMessage>();
  
  for (ContentDocument newDoc : Trigger.new) 
  {
      // Step 1: Create a new Email
      Messaging.SingleEmailMessage mail = 
      new Messaging.SingleEmailMessage();
    
      // Step 2: Set list of people who should get the email
      List<String> sendTo = new List<String>();
      sendTo.add(list of all addresses)
      mail.setToAddresses(sendTo);
    
      // Step 3: Set who the email is sent from
      mail.setReplyTo('myaddress');
      mail.setSenderDisplayName('Aidel Bruck');

      // Step 4. Set email contents - you can use variables!
      mail.setSubject('New Document Added');
      String body = 'Please note: A new document has been added/n  ';
      body += 'File name: '+ newdoc.title+'/n' ;
      body += 'Created By: '+ newdoc.createdbyid+ '/n';
      body += 'Created Date: '+ newdoc.CreatedDate+ '/n';
      body += 'link to file: '+ System.URL.getSalesforceBaseUrl().getHost()+newdoc.id;
      mail.setHtmlBody(body);
    
      // Step 5. Add your email to the master list
      mails.add(mail);
    }
  // Step 6: Send all emails in the master list
  Messaging.sendEmail(mails);
}

Test 
@isTest
public class TestNewFileAlert 
{

    public static testmethod void MyUnitTest()
    {
        test.startTest();
    Account acct = new Account(Name='TEST_ACCT');
    insert acct;
    ContentVersion contentVersionobj = new ContentVersion();
    contentVersionobj.ContentURL='http://www.google.com/';
    contentVersionobj.Title = 'Google.com';            
    insert contentVersionobj;
    
        test.stopTest();
    }

}

 
Hi, 
I need to send an email alert to a couple of users every time a file is uploaded. 
I understand the workflows are not an option for files and I will need to write a trigger. 
I have never written anything like this and I would appreciate some quidance. 
All the best, 
 Aidel
I have many record types for opportunities. I need to run a soql query to get all the record types. 
My opportunity triggers are coded seperately and I don't want to change the whole setup now. 
I am getting the govern limit error and I think its becuase the soql query for the record types is coded seperately in each trigger. 
Is there any way to run the query one time and somehow make it public for all the triggers?
Hi, 
I have suddenly stopped being able to see the system.debug statements in my log. 
Any ideas why this could have happened?