• Sam Satterfield
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
I was initially, and still am, trying to schedule an Apex class to send this; but quickly realised that ".getContent()" wouldn't let me. I changed tactics to have it send via trigger, that called the class, and would then send the email w/ csv attached. I would then either schedule a class to update the object tied to the trigger, or a workflow to update it.

unfortunatly, the report it send looks like this:
Messed up report

I've figured that something about going through a trigger does this; as a button works just fine.

I will include my code below, and I appreciate any help. Thanks.

Trigger:
trigger Call4Health_Export on Analytics__c (before Update)
{ 
For(Analytics__c Ana: Trigger.new)
{Call4Health_Export.Call4Health_Export(Ana.Id);}
}
Class:
global class Call4Health_Export implements Database.AllowsCallouts{
    @future(callout=true)
    webservice static void Call4Health_Export(Id recId){    
        if(recId!=null)
        {
        ApexPages.PageReference report = new ApexPages.PageReference('/00O19000000VSV2?csv=1');     
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        attachment.setFileName('report.csv');
        attachment.setBody(Blob.valueof(report.getContent().toString()));
        attachment.setContentType('text/csv');
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setSubject('Lead Report');
        message.setPlainTextBody('The report is attached.');
        message.setToAddresses( new String[] { 'ssatterfield@femwell.com' } );
        message.setCcAddresses(new String[] { 'ssatterfield@femwell.com'});
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
        }}}


 
The Trigger is supposed to run after another trigger has created the record. When the record is inserted, the trigger is called; but nothing happens. The trigger gives no errors and I have no idea why it doesn't work. Any help is greatly appreciated.
trigger TAMOCon_AssociatedChildUpdate on Topline_Account_Management__c (after insert) 
{
      
   for (Topline_Account_Management__c Tamo : Trigger.New)
   {
		List<contact> conToUpdate = new list <Contact>();

   for(contact Con : [select Id,D_T_TAMO_ID__c,LLC_AgreementNew__c
                      from Contact where D_T_TAMO_ID__c=:TAMO.Topline_Account_Management_Record_ID__c]) 
{ 

						Con.LLC_AgreementNew__c = 'Signed';
 						conToUpdate.ADD(Con);
                        update conToUpdate;
}}}
Hello Y'all

I am new to APEX and Salesforce in general; but I've been tasked with creating a trigger, like what is described in the title. I've been working on this for a couple days now and can't seem to get this to work. Any and all advice would be appreciated.

I am trying to have the field: Data_Conversion_Task_List_If_Needed__c on Object: New_Office_Setup__c update itself to match the field: Status__c on Object: Analytics__c whenever Analytics__c is updated.

What I have so far, is copied from old post that I have subbed the objects and field from my salesforce into:
===========================================================================

trigger UpdateTriggerTest on Analytics__c (before insert, before update) 
{
  //get a list of all the object 2 ID's contained in the records
  //to be updated.
  List<New_Office_Setup__c> NOSIDs = new list<New_Office_Setup__c>();
  //List<List<Analytics__c>> AnaIDs = new List<list<Analytics__c>> ([select id, Open_Projects_Analytics__c from Analytics__c]);
  for (Analytics__c Ana: trigger.new)  
      
  {
   NOSIDs.add(Ana.Open_Projects_Analytics__c );
  }
    
  //now get a list of all the records for object 2 that contain the
  //above IDs
  List <New_Office_Setup__c> NOS = new List <New_Office_Setup__c> ([select id, Data_Conversion_Task_List_If_Needed__c from New_Office_Setup__c where id in: NOSIDs]);

  //now loop again for all the records being updated and then for each
  //one loop through all the object 2 records retrieved above.
  for (Analytics__c Ana: trigger.new){
  
    //we do this for loop differently so that it has an inherent check
    //to ensure that our query above returned some records
    for (integer i = 0; i < NOS.size(); i++){

      //now we make sure the record IDs match
      if (Ana.Open_Projects_Analytics__c == NOS[i].id){

        NOS[i].Data_Conversion_Task_List_If_Needed__c = Ana.Status__c;
      }
    }
  }
  //update all the object 2 records
  update NOS;
}
======================================================================

I would also appreciate any advice on how to construct the test class for this. The test class seems to be the hardest code for me to write so far. At least for the handful of codes I've written before this.

Best,
Sam. S.
I was initially, and still am, trying to schedule an Apex class to send this; but quickly realised that ".getContent()" wouldn't let me. I changed tactics to have it send via trigger, that called the class, and would then send the email w/ csv attached. I would then either schedule a class to update the object tied to the trigger, or a workflow to update it.

unfortunatly, the report it send looks like this:
Messed up report

I've figured that something about going through a trigger does this; as a button works just fine.

I will include my code below, and I appreciate any help. Thanks.

Trigger:
trigger Call4Health_Export on Analytics__c (before Update)
{ 
For(Analytics__c Ana: Trigger.new)
{Call4Health_Export.Call4Health_Export(Ana.Id);}
}
Class:
global class Call4Health_Export implements Database.AllowsCallouts{
    @future(callout=true)
    webservice static void Call4Health_Export(Id recId){    
        if(recId!=null)
        {
        ApexPages.PageReference report = new ApexPages.PageReference('/00O19000000VSV2?csv=1');     
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        attachment.setFileName('report.csv');
        attachment.setBody(Blob.valueof(report.getContent().toString()));
        attachment.setContentType('text/csv');
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setSubject('Lead Report');
        message.setPlainTextBody('The report is attached.');
        message.setToAddresses( new String[] { 'ssatterfield@femwell.com' } );
        message.setCcAddresses(new String[] { 'ssatterfield@femwell.com'});
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
        }}}


 
The Trigger is supposed to run after another trigger has created the record. When the record is inserted, the trigger is called; but nothing happens. The trigger gives no errors and I have no idea why it doesn't work. Any help is greatly appreciated.
trigger TAMOCon_AssociatedChildUpdate on Topline_Account_Management__c (after insert) 
{
      
   for (Topline_Account_Management__c Tamo : Trigger.New)
   {
		List<contact> conToUpdate = new list <Contact>();

   for(contact Con : [select Id,D_T_TAMO_ID__c,LLC_AgreementNew__c
                      from Contact where D_T_TAMO_ID__c=:TAMO.Topline_Account_Management_Record_ID__c]) 
{ 

						Con.LLC_AgreementNew__c = 'Signed';
 						conToUpdate.ADD(Con);
                        update conToUpdate;
}}}
Hello Y'all

I am new to APEX and Salesforce in general; but I've been tasked with creating a trigger, like what is described in the title. I've been working on this for a couple days now and can't seem to get this to work. Any and all advice would be appreciated.

I am trying to have the field: Data_Conversion_Task_List_If_Needed__c on Object: New_Office_Setup__c update itself to match the field: Status__c on Object: Analytics__c whenever Analytics__c is updated.

What I have so far, is copied from old post that I have subbed the objects and field from my salesforce into:
===========================================================================

trigger UpdateTriggerTest on Analytics__c (before insert, before update) 
{
  //get a list of all the object 2 ID's contained in the records
  //to be updated.
  List<New_Office_Setup__c> NOSIDs = new list<New_Office_Setup__c>();
  //List<List<Analytics__c>> AnaIDs = new List<list<Analytics__c>> ([select id, Open_Projects_Analytics__c from Analytics__c]);
  for (Analytics__c Ana: trigger.new)  
      
  {
   NOSIDs.add(Ana.Open_Projects_Analytics__c );
  }
    
  //now get a list of all the records for object 2 that contain the
  //above IDs
  List <New_Office_Setup__c> NOS = new List <New_Office_Setup__c> ([select id, Data_Conversion_Task_List_If_Needed__c from New_Office_Setup__c where id in: NOSIDs]);

  //now loop again for all the records being updated and then for each
  //one loop through all the object 2 records retrieved above.
  for (Analytics__c Ana: trigger.new){
  
    //we do this for loop differently so that it has an inherent check
    //to ensure that our query above returned some records
    for (integer i = 0; i < NOS.size(); i++){

      //now we make sure the record IDs match
      if (Ana.Open_Projects_Analytics__c == NOS[i].id){

        NOS[i].Data_Conversion_Task_List_If_Needed__c = Ana.Status__c;
      }
    }
  }
  //update all the object 2 records
  update NOS;
}
======================================================================

I would also appreciate any advice on how to construct the test class for this. The test class seems to be the hardest code for me to write so far. At least for the handful of codes I've written before this.

Best,
Sam. S.

I need to export a report as a CSV to an FTP site or email it on a daily or weekly basis.

 

I have a Report.  I need to get the report out of Salesforce somehow into CSV format.

 

Ideally, this would be scheduled.


I'm a developer so I can do developer stuff.  However, I don't know APEX and I don't know VisualForce.  I can get someone to do that stuff if we need to.


Thanks!

  • July 26, 2011
  • Like
  • 2