• Edward Vazquez
  • NEWBIE
  • 30 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 8
    Replies
Here is my class below:

global class scheduleLatestCampaigns implements Schedulable {

    global void execute(SchedulableContext SC) {
        //make a map of all accounts to their presentations
        Map<Id, List<Campaign>> accountToCampaigns = new Map<Id, List<Campaign>>();
        List<Campaign> cs = [SELECT Id, Account__c, Date_Time_of_Presentation_Schdeuled__c,Frequency__c,Meeting_Summary__c, Presenter__r.Name FROM Campaign WHERE Date_Time_of_Presentation_Schdeuled__c <= TODAY AND RecordType.Name = 'Presentation' ORDER BY Date_Time_of_Presentation_Schdeuled__c DESC];
        
        for (Campaign c : cs) {
            if (accountToCampaigns.containsKey(c.Account__c)) {
                List<Campaign> currentList = accountToCampaigns.get(c.Account__c);   
                currentList.add(c);
                accountToCampaigns.put(c.Account__c, currentList);
            } else {
                accountToCampaigns.put(c.Account__c, new List<Campaign> { c });
            }
        }
        
        List<Account> updateAccts = new List<Account>();
        //Find the latest campaign on the account that it is attached to and update the account
        for (Account acct : [SELECT Id FROM Account WHERE Id IN :accountToCampaigns.keySet()]) {
            //find all presentations that have already occured
            List<Campaign> campaigns = new List<Campaign>();
            Campaign latestCampaign=null;

            if (accountToCampaigns.containsKey(acct.Id)) {
                latestCampaign = accountToCampaigns.get(acct.Id)[0];
            }

            
            if (latestCampaign != null) {
                acct.Frequency__c = latestCampaign.Frequency__c;
                acct.Last_Presentation__c = date.newinstance(latestCampaign.Date_Time_of_Presentation_Schdeuled__c.year(),
                                                             latestCampaign.Date_Time_of_Presentation_Schdeuled__c.month(),
                                                             latestCampaign.Date_Time_of_Presentation_Schdeuled__c.day());
                acct.Meeting_Summary__c = latestCampaign.Meeting_Summary__c;
                acct.Presenter__c = latestCampaign.Presenter__r.Name;
                updateAccts.add(acct);
            }
        }
        
        update updateAccts;
    }
}


The code is breaking within this loop:
    List<Campaign> cs = [SELECT Id, Account__c, Date_Time_of_Presentation_Schdeuled__c,Frequency__c,Meeting_Summary__c, Presenter__r.Name FROM Campaign WHERE Date_Time_of_Presentation_Schdeuled__c <= TODAY AND RecordType.Name = 'Presentation' ORDER BY Date_Time_of_Presentation_Schdeuled__c DESC]

Any ideas on how to go about fixing this.  
 
The button works fine 90% of the time. When it doesn't work the users are prompted an error message that says "unable to display this envelope either because the user has insufficient access or the envelope does not exist." Any ideas how to solve this issue?
Hello,

Creating an Apex Class is new to me. I would like to share a class and I would really appreciate it if someone  walked me thorugh it so I understand what the class is doing. Here is the code. Thanks for your help in advance.

public with sharing class ResalesAttachment {

  public void CreateResalesAttachment(list<Attachment> aListForResales){
    set<id> resalesIdSet = new set<id>();
    for(Attachment a : aListForResales){
      resalesIdSet.add(a.ParentId);
    }
    map<id,Resales__c> resalesMap = new map<id,Resales__c>();
    resalesMap.putall([select Resident_Name__c
      from Resales__c 
      where id in :resalesIdSet]);
    map<id,Resales_Documents__c> attachmentToResalesDoc = new map<id,Resales_Documents__c>();
    for(Attachment a : aListForResales){
      Resales_Documents__c rd = new Resales_Documents__c();
        rd.name = a.name;
        rd.ID_Of_Original_Attachment__c = a.id;
        rd.Resales__c = resalesMap.get(a.ParentId).id;
        

      attachmentToResalesDoc.put(a.id,rd);
    }
    insert attachmentToResalesDoc.values();
    list<Attachment> newAListForResales = new list<Attachment>();
    for(Attachment a : aListForResales){
      Attachment newA = new Attachment();
        newA.Body = a.Body;
        newA.ContentType = a.ContentType;
        newA.Description = a.Description;
        newA.IsPrivate = a.IsPrivate;
        newA.Name = a.Name;
        newA.OwnerId = a.OwnerId;
        newA.ParentId = attachmentToResalesDoc.get(a.id).id;
      newAListForResales.add(newA);
    }
    insert newAListForResales;

  }
I will explain what the script below achieves. We have a custom "Properties" object. On a properties record we have buttons that users select to generate documents. For example, "generate document". Once they select this button the document is generated through conga and automatically a new record is created in a new custom object called Properties Documents with the attached document. The script below was created by a team before my time. I am trying to replicate this process for two new custom objects. Those custom objects being "Resales" and "Resales Documents". Same idea, when users are on a resales record and they select a button to generate a document I want the document to be generated and automatically a new resales documents record is created with the attachment. I'm not familiar with Apex classes so if you could please help it would be greatly appreciated. The api name for Resales is Resales__c and for Resales Documents it is Resales_Documents__c.



public with sharing class AttachmentTriggerHandler {

  //public void OnBeforeInsert(Attachment[] newObjects){
    
  //}
  
  public void OnAfterInsert(Attachment[] newObjects){
    //creates new properties documents and copies the attachment to it.
      list<Attachment> aList = new list<Attachment>();
      for(Attachment a : newObjects){
        if(a.ParentId.getSobjectType() == Schema.Properties__c.SObjectType){
          aList.add(a);
        }
      }
      if(aList.size() > 0){
        PropertiesAttachment pa = new PropertiesAttachment();
        pa.CreateNewPropertiesAttatchment(aList); 
      }
  }
  
/*  public void OnBeforeUpdate(Attachment[] oldObjects, Attachment[] updatedObjects, map<id,Attachment> MapNewMap, map<id,Attachment> MapOldMap){

  }
  
  public void OnAfterUpdate(Attachment[] oldObjects, Attachment[] updatedObjects, map<id,Attachment> MapNewMap, map<id,Attachment> MapOldMap){
  
  }
  
  public void OnBeforeDelete(Attachment[] ObjectsToDelete, map<id,Attachment> MapNewMap, map<id,Attachment> MapOldMap){
  
  }
  
  public void OnAfterDelete(Attachment[] deletedObjects, map<id,Attachment> MapNewMap, map<id,Attachment> MapOldMap){
  
  }
  
  public void OnUndelete(Attachment[] restoredObjects){
  
  }
*/
}
I recently installed Salesforce for outlook for a new user in our company. For some reason she is constantly being logged out and having to log back in. She uses Google Chrome as her browser. Any ideas?? Please help!!
I want to automatically create a new record in custom Object B when a specific record type is selected in  custom Object A. How would I go about doing this? Please help
User-added image

This is some of the html for my email template that shoots out automatically.The applicant names are not always all filled out it just depends on the specific contact record. Some may have 1 applicant, some may have 2, and some may have all 6. My Question is how do I add commas to seperate the applicant names only when needed. I don't just want to have commas with blank spaces. Any ideas?
Here is the error message I am recieveing:

Here's the error message

Here is my code for the button:

{!REQUIRESCRIPT("/apex/dsfs__DocuSign_JavaScript")}
DocuSign_CreateEnvelope();

//********* Option Declarations *********//
var
RC = '',
RSL = '',
RSRO = '',
RROS = '',
CCRM = '',
CCTM = 'Signer 2~Carbon Copy',
CCNM = '',
CRCL = '',
CRL = 'Email~{!JSENCODE(Contact.Email)};FirstName~{!JSENCODE(Contact.FirstName)};LastName~{!JSENCODE(Contact.LastName)};Role~Signer 1;RoutingOrder~1;RecipientNote~,Email~{!JSENCODE(Contact.Hidden_Real_Estate_Agent_Email__c)};FirstName~{!JSENCODE(Contact.Hidden_Real_Estate_Agent_First_Name__c)};Role~Signer 2;RoutingOrder~2;RecipientNote~{!JSENCODE(Contact.FirstName)} {!JSENCODE(Contact.LastName)} has signed the pre-approval letter.;LastName~{!JSENCODE(Contact.Hidden_Real_Estate_Agent_Last_Name__c)}',
OCO = 'Tag',
DST = '',
LA = '1',
CEM = '',
CES = 'xxxxxxxxxxxxxxxxx {!JSENCODE(Contact.FirstName)} {!JSENCODE(Contact.LastName)}',
STB = '0',
SSB = '1',
SES = '1',
SEM = '1',
SRS = '0',
SCS = '0',
RES = '1,0,0,1,90,1';

//********* Page Callout (Do not modify) *********//
window.location.href =
"/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!Contact.Id}&RC="+RC+
"&RSL="+RSL+"&RSRO="+RSRO+"&RROS="+RROS+"&CCRM="+CCRM+"&CCTM="+CCTM+"&CRCL="+CRCL+"&CRL="+CRL+"&OCO="+OCO+"&DST="+DST+"&CCNM="+CCNM+"&LA="+LA+"&CEM="+CEM+"&CES="+CES+"&SRS="+SRS+"&STB="+STB+"&SSB="+SSB+"&SES="+SES+"&SEM="+SEM+"&SRS="+SRS+"&SCS="+SCS+"&RES="+RES;
//*******************************************//
 
The button works fine 90% of the time. When it doesn't work the users are prompted an error message that says "unable to display this envelope either because the user has insufficient access or the envelope does not exist." Any ideas how to solve this issue?
Hello,

Creating an Apex Class is new to me. I would like to share a class and I would really appreciate it if someone  walked me thorugh it so I understand what the class is doing. Here is the code. Thanks for your help in advance.

public with sharing class ResalesAttachment {

  public void CreateResalesAttachment(list<Attachment> aListForResales){
    set<id> resalesIdSet = new set<id>();
    for(Attachment a : aListForResales){
      resalesIdSet.add(a.ParentId);
    }
    map<id,Resales__c> resalesMap = new map<id,Resales__c>();
    resalesMap.putall([select Resident_Name__c
      from Resales__c 
      where id in :resalesIdSet]);
    map<id,Resales_Documents__c> attachmentToResalesDoc = new map<id,Resales_Documents__c>();
    for(Attachment a : aListForResales){
      Resales_Documents__c rd = new Resales_Documents__c();
        rd.name = a.name;
        rd.ID_Of_Original_Attachment__c = a.id;
        rd.Resales__c = resalesMap.get(a.ParentId).id;
        

      attachmentToResalesDoc.put(a.id,rd);
    }
    insert attachmentToResalesDoc.values();
    list<Attachment> newAListForResales = new list<Attachment>();
    for(Attachment a : aListForResales){
      Attachment newA = new Attachment();
        newA.Body = a.Body;
        newA.ContentType = a.ContentType;
        newA.Description = a.Description;
        newA.IsPrivate = a.IsPrivate;
        newA.Name = a.Name;
        newA.OwnerId = a.OwnerId;
        newA.ParentId = attachmentToResalesDoc.get(a.id).id;
      newAListForResales.add(newA);
    }
    insert newAListForResales;

  }
I want to automatically create a new record in custom Object B when a specific record type is selected in  custom Object A. How would I go about doing this? Please help
User-added image

This is some of the html for my email template that shoots out automatically.The applicant names are not always all filled out it just depends on the specific contact record. Some may have 1 applicant, some may have 2, and some may have all 6. My Question is how do I add commas to seperate the applicant names only when needed. I don't just want to have commas with blank spaces. Any ideas?