• thornk
  • NEWBIE
  • 25 Points
  • Member since 2010

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies

Hello,

   We have a business requirement to send an email to external users whenever a checkbox is checked on an opportunity.  The business needs basic opportunity information but also need any attachment on the opportunity.  For this reason, I need to write an apex trigger to gather up the attachments and create the email.

 

I was hoping to leverage an email template rather than build the email within apex code and thought I would be able to use the setTemplateID parameter on a single Mail message, however it turns out that the email templates only work with Contacts, Leads and Users.

 

I was wondering if anybody has any thoughts on how to leverage a template when creating an email message in an apex trigger.  It would help with maintenance of this process in the future if we don't have to edit the code and redeploy whenever fields are updated.

 

Thank you.

I have an object called Order Request which can have multiple IDs associated with it (through a junction object).  When the Order Request install status is changed to Completed, I have a trigger which loops through the IDs and updates values.  (ie change anythign with Add-Realtime to Enabled-Realtime).  This code is working fine unless there are a large number of IDs on the order request.  I was originally running into a heap error but figured that out.  Now i am running into a "too many script statements" error.  I know whey I am getting the error.  There are approximately 190 picklists on each ID which this code is processing,  and the code about executes at least 2 lines for each picklist value, so at a very basic level, for 25 IDs I have 190*25*5=9750.  Add some overhead to that and I have hit my limit of 10200 scripts.  I was hoping that somebody might have a good way to avoid looping through each one of these picklist values or have another inventive way of getting around this.  Here is the code:

public static void processIDs (Order_Request__c[] orReq){
List<Townsend_User_Login_ID__c> orderRequestIDs = new List<Townsend_User_Login_ID__c>();
List<Townsend_User_Login_ID__c> orderRequestDirectIDs = new List<Townsend_User_Login_ID__c>();
List<Order_Request_Townsend_User_Login_IDs__c> orderIDlinks = new List<Order_Request_Townsend_User_Login_IDs__c>();
List<String> exchanges = new List<String>();
Map<String, Schema.SObjectField> IDfields = Schema.SObjectType.Townsend_User_Login_ID__c.fields.getMap();
String qString = '';
for (String f: IDfields.keyset()){
if(f.substring(0,1) == 'X' ||
f == 'SCB_SWX_SCOACH_BASIC__c' ||
f == 'SCA_SWX_SCOACH_ADVANCED__c' ||
f == 'LSQ_LSE_INTL_L1_NEWS__c' ||
f == 'LSP_LSE_DOM_L1_NEWS__c' ){
qString = qString + ', ' + f + ' ';
exchanges.add(f);
}
}

ID recTypeId = Schema.SObjectType.Order_Request__c.getRecordTypeInfosByName().get('Townsend Submitted').getRecordTypeId();
for (Order_Request__c o : orReq){
if (o.RecordTypeId == recTypeId ){
if(o.Install_Status__c <> 'Completed'){
continue;
}else{
String thisQString1 = 'select id ' + qString + 'from Townsend_User_Login_ID__c where id IN (select Townsend_User_Login_ID__c from Order_Request_Townsend_User_Login_IDs__c where Order_Request__c = \''+o.id+'\')';
List<Townsend_User_Login_ID__c> townList = new List<Townsend_User_Login_ID__c>();
for (Townsend_User_Login_ID__c t : Database.query(thisQString1)){
for(String field: exchanges){
String value = String.valueOf(t.get(field));
if(value <> 'Not Enabled' && value <>'Enabled-Realtime' && value <> 'Enabled-Delayed'){
if (value == 'Add-Realtime'){t.put(field, 'Enabled-Realtime');
}else if(value == 'Add-Delayed'){t.put(field, 'Enabled-Delayed');
}else if(value == 'Delete-Realtime' || value == 'Delete-Delayed'){
t.put(field, 'Not Enabled');
}//end if-else
}
}
townList.add(t);
System.debug('*** Heap Size is '+Limits.getHeapSize());
if (Limits.getLimitHeapSize() - Limits.getHeapSize() < 50000 ){
update(townList);
townList.clear();
}
}//end for loop
update(townList);
townList.clear();
}//end if-else
}
}
}

 


 

 

  • February 12, 2010
  • Like
  • 0

I have an interesting situation which I can't seem to figure out.  I have a page which iterates over a list of Objects.  Each object has some basic data and then a list of fields and values (it is it's own wrapper class).

 

I render the basic data in a repeat loop, then a nested repeat loops through the fields and values.  When I simply use rendered="true" everything looks fine.  However I would like to display only those values which are NOT labeled 'Not Enabled' and are not null.  For some reason when i changed rendered to rendered="{!AND(f.value!='Not Enabled',f.value!=null)} the values I want are printed but sometimes with huge gaps between the lines, ie:

 

Field 1:  Value 1

Field 2:  Value 2

 

 

Field3:  Value 3

Field4:  Value 4

 

Here is the VF code

 

<apex:page controller="printIDscontroller" showHeader="false" sidebar="false" renderas="pdf" title="User IDs"> <apex:panelGrid columns="1" width="100%" > Login IDs for Account:<b>{!accountName}</b> on Order Request <b>{!OrderReqNum}</b><br/><br/> </apex:PanelGrid> <apex:repeat value="{!printIDs}" var="i" id="table"> User ID:<b>{!i.tulid.Name}</b> <apex:panelGrid columns="3" cellspacing="4" width="80%"> <apex:panelGroup > <apex:outputLabel value="Login Location:"/>&nbsp;<apex:outputText value="{!i.tulid.Login_Location__c}" /> </apex:panelGroup> <apex:panelGroup > <apex:outputLabel value="Exchange Type:"/>&nbsp;<apex:outputText value="{!i.tulid.Exchange_Type__c}" /> </apex:panelGroup> </apex:panelGrid> <apex:repeat value="{!i.theList}" var="f" id="fields"> <apex:panelGrid columns="3" width="100%"> <apex:panelGroup rendered="{!AND(f.value!='Not Enabled',f.value!=null)}"> <apex:outputText value="{!f.label}"/><apex:outputText value=": "/><apex:outputText value="{!f.value}"/> </apex:panelGroup> </apex:panelGrid> </apex:repeat> </apex:repeat> </apex:page>

 

 Any insight would be appreciated.

 

  • February 09, 2010
  • Like
  • 0

We have a UserID object which has around 200 picklists on it.  The User ID is tied to an Order Request.  I have a requirement to create a printout which displays all of the User IDs associated with a user request.  I can build the vf page and hard code every field, but that would be a nightmare to maintain.  I would like to create the page dynamically so that if we add new picklists in the future I don't have to go back and edit visualforce pages.  

 

My idea was to create a custom class which held the UserID, a list of fields and a list of values and then render them on the VF page using nested <apex:repeat> tags.  the outer repeat would loop through all of the UserIDs while the inner repeat would loop through the list of fields that I want to dynamically create.

 

I have a class that returns a map of field names and the getDescribe on those fields:

 

public with sharing class getUserIDSchema {
public static Map<String, DescribeFieldResult> fullMapping (){
Map<String, DescribeFieldResult> m = new Map<String, DescribeFieldResult>();
Map<String, Schema.SObjectField> uliFields = Schema.SObjectType.Townsend_User_Login_ID__c.fields.getMap();


for(String s : uliFields.keySet()){
if(s.substring(0,1) == 'X' ||
s == 'SCB_SWX_SCOACH_BASIC__c' ||
s == 'SCA_SWX_SCOACH_ADVANCED__c' ||
s == 'LSQ_LSE_INTL_L1_NEWS__c' ||
s == 'LSP_LSE_DOM_L1_NEWS__c' )
{
m.put(s,uliFields.get(s).getDescribe());
}
}
return m;
}
}

 

  I then create two Lists in my wrapper class, one is a list of strings holding the field Labels, the second list holding the Field value (at least I think it does):

public class wPrintID{
public Townsend_User_Login_ID__c tulid {get; set;}
public List<String> fields = new List<String>();
public List<Object> values = new List<Object>();
public wPrintID (Townsend_User_Login_ID__c a, Map<String, DescribeFieldResult> fMap){
tulid = a;
for(String s : getFields()){
if(fMap.isEmpty() <> false){
fields.add(fMap.get(s).getLabel()); //This is the list of field labels
values.add(tulid.get((fMap.get(s).getSObjectField()))); //This is the list of field values
}
}
}
}

 

I was hoping to render this out using something along the lines of the code below using the first loop to print out some basic info on the ID and the second loop to output the list of fields (and eventually the values):

 

<apex:page controller="printIDscontroller" showHeader="false" sidebar="false" renderas="pdf" title="User IDs">
<apex:repeat value="{!printIDs}" var="i" id="table">
<apex:repeat value="{!i}" var="f" id="fields">
<apex:outputText value="{!f.fields}"/>
</apex:repeat>
</apex:repeat>
</apex:page>

 

I think I ran into a wall here though and am unsure about how to get both the Fields and values printed out since the second repeat loop would need to be seeded with !i.fields to iterate over the list, but then I can't access !i.values.

 

I think I need to start over with a new approach, but I am not quite sure what direction to take.  Any advice, ideas, direction, etc. would be greatly appreciated at this point.

 

 

 


 

Message Edited by thornk on 01-28-2010 12:56 PM
  • January 28, 2010
  • Like
  • 0

Hello,

   We have a business requirement to send an email to external users whenever a checkbox is checked on an opportunity.  The business needs basic opportunity information but also need any attachment on the opportunity.  For this reason, I need to write an apex trigger to gather up the attachments and create the email.

 

I was hoping to leverage an email template rather than build the email within apex code and thought I would be able to use the setTemplateID parameter on a single Mail message, however it turns out that the email templates only work with Contacts, Leads and Users.

 

I was wondering if anybody has any thoughts on how to leverage a template when creating an email message in an apex trigger.  It would help with maintenance of this process in the future if we don't have to edit the code and redeploy whenever fields are updated.

 

Thank you.

http://forums.sforce.com/sforce/board/message?message.uid=168908#U168908

 

I marked this as solved because it stopped happening for my user.  However, they report (and I have confirmed) that this issue is happening again. 

 

The only changes we made today in SalesForce were to add a new profile for a completely different user.  No changes have been made to the server where the i-frames are pointing.

 

The really weird thing is, that when I am accessing this user's account via Login Access, I cannot replicate this issue.   This could point to an issue with access to the sites linked in the i-frames, but the user can access these sites normally via directly linking to them in the main browser window.

 

Any assistance would be appreciated.

We have a UserID object which has around 200 picklists on it.  The User ID is tied to an Order Request.  I have a requirement to create a printout which displays all of the User IDs associated with a user request.  I can build the vf page and hard code every field, but that would be a nightmare to maintain.  I would like to create the page dynamically so that if we add new picklists in the future I don't have to go back and edit visualforce pages.  

 

My idea was to create a custom class which held the UserID, a list of fields and a list of values and then render them on the VF page using nested <apex:repeat> tags.  the outer repeat would loop through all of the UserIDs while the inner repeat would loop through the list of fields that I want to dynamically create.

 

I have a class that returns a map of field names and the getDescribe on those fields:

 

public with sharing class getUserIDSchema {
public static Map<String, DescribeFieldResult> fullMapping (){
Map<String, DescribeFieldResult> m = new Map<String, DescribeFieldResult>();
Map<String, Schema.SObjectField> uliFields = Schema.SObjectType.Townsend_User_Login_ID__c.fields.getMap();


for(String s : uliFields.keySet()){
if(s.substring(0,1) == 'X' ||
s == 'SCB_SWX_SCOACH_BASIC__c' ||
s == 'SCA_SWX_SCOACH_ADVANCED__c' ||
s == 'LSQ_LSE_INTL_L1_NEWS__c' ||
s == 'LSP_LSE_DOM_L1_NEWS__c' )
{
m.put(s,uliFields.get(s).getDescribe());
}
}
return m;
}
}

 

  I then create two Lists in my wrapper class, one is a list of strings holding the field Labels, the second list holding the Field value (at least I think it does):

public class wPrintID{
public Townsend_User_Login_ID__c tulid {get; set;}
public List<String> fields = new List<String>();
public List<Object> values = new List<Object>();
public wPrintID (Townsend_User_Login_ID__c a, Map<String, DescribeFieldResult> fMap){
tulid = a;
for(String s : getFields()){
if(fMap.isEmpty() <> false){
fields.add(fMap.get(s).getLabel()); //This is the list of field labels
values.add(tulid.get((fMap.get(s).getSObjectField()))); //This is the list of field values
}
}
}
}

 

I was hoping to render this out using something along the lines of the code below using the first loop to print out some basic info on the ID and the second loop to output the list of fields (and eventually the values):

 

<apex:page controller="printIDscontroller" showHeader="false" sidebar="false" renderas="pdf" title="User IDs">
<apex:repeat value="{!printIDs}" var="i" id="table">
<apex:repeat value="{!i}" var="f" id="fields">
<apex:outputText value="{!f.fields}"/>
</apex:repeat>
</apex:repeat>
</apex:page>

 

I think I ran into a wall here though and am unsure about how to get both the Fields and values printed out since the second repeat loop would need to be seeded with !i.fields to iterate over the list, but then I can't access !i.values.

 

I think I need to start over with a new approach, but I am not quite sure what direction to take.  Any advice, ideas, direction, etc. would be greatly appreciated at this point.

 

 

 


 

Message Edited by thornk on 01-28-2010 12:56 PM
  • January 28, 2010
  • Like
  • 0

I've just started working in the Force development platform and need to have a Workflow rule run on all contact records once a day to send an email reminder to sales people when a date matches the frequency they want to re-contact the prospect.

 

I want to have this date field checked daily on all prospects and if it matches today's date send the salesperson an email with basic conact info and then update the date field by adding the number of days specified in the frequency field to todays date.

I can get all of that done in the Force platform if I change the date field manually to today's date, but I want it to check all the Prospect records automatically and compare the Trigger date to Today().

I downloaded Cronkit but I don't have any experience with Apex (I have done some programming in ASP in the past) and don't know how to construct the custom batch job that Cronkit requires.

If someone has a sample of code that works in a similar way, or can tell me how it might be done without an add on like CronKit, I would really appreciate, I would really appreciate the info.

 

Thanks

  • August 18, 2009
  • Like
  • 0