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

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 48
    Questions
  • 51
    Replies
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 have an email alert being sent by a trigger with the sethtmlbody()
I am trying to get a linebreak in the body but It is not working
This is how I set the body
mail.setSubject('New Document Added');
          String body = 'Please note: A new document has been added to '+a[0].Name+' \n  ';
        body += 'File name: '+ newdoc.title+'.\n\r' ;
        body += 'Created By: '+ username+ '.\n\r';
        body += 'Created Date: '+ newdoc.CreatedDate+ '.\n\r';
        body += 'link to file: '+ System.URL.getSalesforceBaseUrl().getHost()+'/'+newdoc.Id;
          mail.setHtmlBody(body);

I tried \r
I tried </BR>
And I still cant get a line break in the email, its all one long line
How can I get a line break?
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();
    }

}

 
I have the following trigger I wrote for ContentDocument
I want to send an email alert to various users when a file is uploaded 
This is the code and I would like to know how to test it
Also I need a way to get the account name the file is associated with

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');
    
      // (Optional) Set list of people who should be CC'ed
      //List<String> ccTo = new List<String>();
      //ccTo.add('business@bankofnigeria.com');
      //mail.setCcAddresses(ccTo);

      // 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);
}

Thanks!
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 am working on optimizing code that I didn't originally write. 
Each object has multiple triggers, and each trigger has soql queries.
There is a trigger that is hitting the limit for soql queries. Is there an easy way to pinpoint where these queries are?

Hi, 
I am trying to delploy a trigger. This trigger has been successfully tested in the sandbox, But when I deploy to production I hit the govern limit. 
The sandbox I am working with and the production instance both have the same triggers set up. 
How can this be happening, 
All the best, 
Aidel

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>
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?
I have a custom object X I need to updated through the dataloader. When updated I need the related account to be updated for each custom object. 
Obviously, my trigger uses a Soql query on each instance of the custom object to find the related account. 
When I run the dataloader update I reach the limit and I am stuck. 
​Any ideas?