• dave23
  • NEWBIE
  • 0 Points
  • Member since 2008

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

Is there any way to add an error to an record being updated in a trigger and send an email. The trigger needs to send an email (one per batch). The email works fine if the processing generates no errors and I do not use the addError method. If I use the addError method to pass a message back to the user then the email is not sent.

 

So is there a way to send an email and use addError in the same trigger code? If not is there another mechanism that can be used to pass a message back to the user interface (standard salesforce UI).

 

Thanks

 

Dave

  • December 08, 2009
  • Like
  • 0

Does anyone know if SF will put multiple web to case records in a single batch? I need to do a fair bit of Apex code in a before insert trigger and it would greatly simplify the work if the trigger did not have to be bulk safe. I can't find anyway to reliably test this although I have fired in a bunch of web cases manually and so far they seem to prcoesses singly.

 

Thanks

Hi,

 

I am trying to set the RecordType in a before insert trigger for web to case input. The trigger code is:      

trigger CaseSetupTrigger on Case (before insert){
for (Case c: Trigger.new) {
c.RecordType = [select Id from RecordType where Name = 'Canada' and SobjectType = 'Case'];
}
}

I know the code above works as I can see the correct RecordTypeID in the debug log for some workflow rules that use the RecordType. The problem is that when the case is finally saved the RecordType has been overwritten with the default RecordType for unassigned cases. There are no workflow rules that set the RecordType. The workflow rules also use $RecordType.Name which is the name of the default recordType and not Canada as would be expected.

 

I have tried changing the case setting for "Choose the desired behavior to use when applying assignment rules to manually created records:" to "Keep existing Record Type" but this has no effect. 

 

I'm guessing that this has something to do with the order that triggers web to case and workflow rules fire but I can't seem to pin it down.

 

Any suggestions on how to get the record type set in a before insert trigger to actually stick for a web to case and not get changed?

 

Thanks

 

I have some javascript code that runs to popup a window with account details as follows. The code needs to get the selected index which is the ID of the account to display.
 
I have not been able to find a way to reference the selectedIndex other than hardcoding the Id generated by Salesforce. Obviously this is not a good method as the field Id will probably change at some point. I'm not a JS expert but I would think there is a better way to do this? Can anyone help?
Code:
  <script type="text/javascript">
  function viewAccount() {
        var acc_select = document.getElementById('j_id0:convertData:j_id4:j_id8:accountName');
         var acc_id = acc_select.options[acc_select.selectedIndex].value;
         if (acc_id == null || acc_id == "" || acc_id == 000000000000000) {
            alert("You can only view existing accounts.");
         } else {
            var AccountWindow = window.open('/' + acc_id + '/p','Account','height=300,width=500,status=yes,scrollbars=yes,resizable=yes');
            AccountWindow.focus();
         }
     }
  </script>
VF code: 
          <apex:panelGroup > 
                  <apex:selectList id="accountName" required="true" size="1" value="{!selectedAccountID}"> 
                      <apex:selectOptions value="{!leadAccountNames}"/>
                  </apex:selectList>
                  <apex:outputLabel value="View" title="View (New Window)" onclick="viewAccount()" id="theLink"></apex:outputLabel>
              </apex:panelGroup>
 
 
Thanks
 
Dave
  • January 15, 2009
  • Like
  • 0

Is there any way to add an error to an record being updated in a trigger and send an email. The trigger needs to send an email (one per batch). The email works fine if the processing generates no errors and I do not use the addError method. If I use the addError method to pass a message back to the user then the email is not sent.

 

So is there a way to send an email and use addError in the same trigger code? If not is there another mechanism that can be used to pass a message back to the user interface (standard salesforce UI).

 

Thanks

 

Dave

  • December 08, 2009
  • Like
  • 0

Hi,

 

How can I distinguish when a trigger is fired from another trigger (cascading) or directly from a database save operation (not fired from another trigger)?

 

I've been looking for this in Apex Help documents without any success.

 

Thanks in advance.

Hi,

 

I am trying to set the RecordType in a before insert trigger for web to case input. The trigger code is:      

trigger CaseSetupTrigger on Case (before insert){
for (Case c: Trigger.new) {
c.RecordType = [select Id from RecordType where Name = 'Canada' and SobjectType = 'Case'];
}
}

I know the code above works as I can see the correct RecordTypeID in the debug log for some workflow rules that use the RecordType. The problem is that when the case is finally saved the RecordType has been overwritten with the default RecordType for unassigned cases. There are no workflow rules that set the RecordType. The workflow rules also use $RecordType.Name which is the name of the default recordType and not Canada as would be expected.

 

I have tried changing the case setting for "Choose the desired behavior to use when applying assignment rules to manually created records:" to "Keep existing Record Type" but this has no effect. 

 

I'm guessing that this has something to do with the order that triggers web to case and workflow rules fire but I can't seem to pin it down.

 

Any suggestions on how to get the record type set in a before insert trigger to actually stick for a web to case and not get changed?

 

Thanks

 

I have some javascript code that runs to popup a window with account details as follows. The code needs to get the selected index which is the ID of the account to display.
 
I have not been able to find a way to reference the selectedIndex other than hardcoding the Id generated by Salesforce. Obviously this is not a good method as the field Id will probably change at some point. I'm not a JS expert but I would think there is a better way to do this? Can anyone help?
Code:
  <script type="text/javascript">
  function viewAccount() {
        var acc_select = document.getElementById('j_id0:convertData:j_id4:j_id8:accountName');
         var acc_id = acc_select.options[acc_select.selectedIndex].value;
         if (acc_id == null || acc_id == "" || acc_id == 000000000000000) {
            alert("You can only view existing accounts.");
         } else {
            var AccountWindow = window.open('/' + acc_id + '/p','Account','height=300,width=500,status=yes,scrollbars=yes,resizable=yes');
            AccountWindow.focus();
         }
     }
  </script>
VF code: 
          <apex:panelGroup > 
                  <apex:selectList id="accountName" required="true" size="1" value="{!selectedAccountID}"> 
                      <apex:selectOptions value="{!leadAccountNames}"/>
                  </apex:selectList>
                  <apex:outputLabel value="View" title="View (New Window)" onclick="viewAccount()" id="theLink"></apex:outputLabel>
              </apex:panelGroup>
 
 
Thanks
 
Dave
  • January 15, 2009
  • Like
  • 0
In a previous post Doug Chasman wrote:
 
... and sometimes you want to combine the 2 concepts, leverage the cool automagic apex:inputField picklist (or date picker is another common request) behavior when you don't have an Sobject. For that you just create a surrogate or proxy, in memory only, SObject instance that you can bind to - basically using the SObject purely as a data transfer object.
 
How do I create a surrogate in memory only Sobject? I've looked through the Apex and VF documentation but can't see anything realted to this. I would think I need to define an object with the relavent fields I want to use in the VF page but I don't see how to associate the object as a SObject or specify the various field attributes (like required).
 
Thanks
 
Dave