function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CKNCKN 

Display an alert box from a trigger

I need to implement the following; Based on the below criteria for case creatorID and case owner id, I want to display a message ( not a error message) stating " This case was created by a CAS agent. It will get reassigned to the case creator"). Right now my code displays an error message but the user has to go back to the case and change owner. 

 

Is there a way to display a message and change the ownerid automatically via the trigger?

 

if ((a.STATUS == 'Awaiting Internal Response'&& a.RecordTypeID == '012300000004rDZ')&&  
                     (casecreatoriwdalias =='CAS' ||casecreatoriwdalias =='TASR/P1')&&  
                       (iWdAliasCaseOwner == 'DISP'|| iWdAliasCaseOwner == 'RCC'))     {
                         a.IWD_Testing__c = 'trigger 2 enter the loop';    
                         a.iwd_check__c    = true;                        
                                }// status
                                
            if (a.iwd_check__c){
                   err_msg = 'Case opened by TASR/P1 or CAS Agent: Please assign it to:';
                   err_msg += casecreatoriwdalias + ' ' + a.CreatedById + '<br>';
                   a.addError(err_msg);

                   a.ownerid  = caseowner;
                             } 

 

 

Thanks

Chitra

Best Answer chosen by Admin (Salesforce Developers) 
TrueCloudTrueCloud

I don;t know what happened but my code got deleted in the second option during the post. Here you go:

 

 

<apex:page standardController="Case">
<apex:includeScript value="/soap/ajax/13.0/connection.js"/>
<script langauge = "JavaScript"> 
alert('Case opened by TASR/P1 or CAS Agent: It will be automatically reassigned to: ' + '{!$User.FirstName}' + ' {$User.LastName}');
if ('{!Case.Additional_Emails_adds__c}' != "") //Replace this with your conditions 
{
var CaseObj = new sforce.SObject("Case"); 
CaseObj.Id = '{!Case.Id}'; 
Case.Ownerid = '{!$User.Id}'; //Not sure if this is correct according to your logic.
var result = sforce.connection.update([ContactNoteObj]); 
if (result[0].success=='false') { 
alert(result[0].errors.message); 
else { 
 alert('This contact note is emailed to' + email1 + '\n' + email2 + '\n' + email3); 
}
var result = sforce.connection.update([ContactNoteObj]); if (result[0].success=='false') { alert(result[0].errors.message); } else {  alert('Success'); }} location.reload(true);  </script> </apex:page>

 

 

All Answers

hisrinuhisrinu

No you can't display an alert messag with the help of triggers

 

However you can show an error message and ask user to select yes from an picklist if user is okay to change the owner else no... I know it looks odd, but only this is the way we can overcome with trigger

CKNCKN

Srini,

Thanks for the posting. I will test it out and let you know.

Regards

Chitra

TrueCloudTrueCloud

I would recommend putting a JavaScript with an alert  to pop-up when the status changes...

CKNCKN

Thanks for your response. Where should I put the JavaScript?

 

Our original design was to put javascript on the save and close button on the case edit page.Apparently we can not put any code behind this standard button and we would like to avoid making a visual force page to override the case edit page.

TrueCloudTrueCloud

Create a new VF Page and hide on the page layout with your Javascript. Let me know if you need an example for the same.

TrueCloudTrueCloud

Also, can you accept my post as a solution if it resolves your issue.

CKNCKN

would be great if you can send me the example.

 

Thanks so much

 

Chitra

TrueCloudTrueCloud

 


CKN wrote:

I need to implement the following; Based on the below criteria for case creatorID and case owner id, I want to display a message ( not a error message) stating " This case was created by a CAS agent. It will get reassigned to the case creator"). Right now my code displays an error message but the user has to go back to the case and change owner. 

 

Is there a way to display a message and change the ownerid automatically via the trigger?

 

if ((a.STATUS == 'Awaiting Internal Response'&& a.RecordTypeID == '012300000004rDZ')&&  
                     (casecreatoriwdalias =='CAS' ||casecreatoriwdalias =='TASR/P1')&&  
                       (iWdAliasCaseOwner == 'DISP'|| iWdAliasCaseOwner == 'RCC'))     {
                         a.IWD_Testing__c = 'trigger 2 enter the loop';    
                         a.iwd_check__c    = true;                        
                                }// status
                                
            if (a.iwd_check__c){
                   err_msg = 'Case opened by TASR/P1 or CAS Agent: Please assign it to:';
                   err_msg += casecreatoriwdalias + ' ' + a.CreatedById + '<br>';
                   a.addError(err_msg);

                   a.ownerid  = caseowner;
                   } 

Thanks

Chitra


 

Chitra,

 

I am assuming that a.iwd_check__c field is a checkbox field that is set to true whenever the trigger runs. If that is the case and if the a.iwd_check__c condition is true than you want to display the message in a standard JavaScript alert window.

 

Here is an example of how you can possible resolve this issue. The first option shows you a way to only display the alert message based on the value of the form. The second option requires you to get rid of the trigger and process the record from the page directly.

 

 

First Option:

 

Step1: Create a new VF Page

 

<apex:page standardController="Case">
 <script language = "JavaScript">
   var msg = '{!Case.casecreatoriwdalias} ' + '{!Case.CreatedById}'


 if ('{!Case.iwd_check__c}' == "True") {
alert ('Case opened by TASR/P1 or CAS Agent: Please assign it to: ' + msg);
}
 </script>
</apex:page>

 

Step 2:

 

Edit the page Layout and drag the newly created VF page and save it with only 5px height.

 

Step 3: Click Save and Continue.

 

This should simply display the check box. This will only display the Alerts.... 

 

if you want to display the Message and then also changed the owner, you will have to do the following. I will leave the final decision to you on which option you want to implement.

 

Second Option:

 

Step 1: Disable the TriggerCase opened by TASR/P1 or CAS Agent: Please assign it to:

 

Step 2: Create a VF Page with as follows

 

 

<apex:page standardController="Case">
<apex:includeScript value="/soap/ajax/13.0/connection.js"/>
<script langauge = "JavaScript"> 
alert('Case opened by TASR/P1 or CAS Agent: It will be automatically reassigned to: ' + '{!$User.FirstName}' + ' {$User.LastName}');
if ('{!Case.Additional_Emails_adds__c}' != "") //Replace this with your conditions 
{
var CaseObj = new sforce.SObject("Case"); 
CaseObj.Id = '{!Case.Id}'; 
Case.Ownerid = '{!$User.Id}'; //Not sure if this is correct according to your logic.
var result = sforce.connection.update([ContactNoteObj]); 
if (result[0].success=='false') { 
alert(result[0].errors.message); 
else { 
 alert('This contact note is emailed to' + email1 + '\n' + email2 + '\n' + email3); 
}

var result = sforce.connection.update([ContactNoteObj]); if (result[0].success=='false') { alert(result[0].errors.message); } else {  alert('Success'); }} location.reload(true);  </script> </apex:page>

 

Step 3: Add the Page to your case page layout.

 

Let me know if this helps...

TrueCloudTrueCloud

I don;t know what happened but my code got deleted in the second option during the post. Here you go:

 

 

<apex:page standardController="Case">
<apex:includeScript value="/soap/ajax/13.0/connection.js"/>
<script langauge = "JavaScript"> 
alert('Case opened by TASR/P1 or CAS Agent: It will be automatically reassigned to: ' + '{!$User.FirstName}' + ' {$User.LastName}');
if ('{!Case.Additional_Emails_adds__c}' != "") //Replace this with your conditions 
{
var CaseObj = new sforce.SObject("Case"); 
CaseObj.Id = '{!Case.Id}'; 
Case.Ownerid = '{!$User.Id}'; //Not sure if this is correct according to your logic.
var result = sforce.connection.update([ContactNoteObj]); 
if (result[0].success=='false') { 
alert(result[0].errors.message); 
else { 
 alert('This contact note is emailed to' + email1 + '\n' + email2 + '\n' + email3); 
}
var result = sforce.connection.update([ContactNoteObj]); if (result[0].success=='false') { alert(result[0].errors.message); } else {  alert('Success'); }} location.reload(true);  </script> </apex:page>

 

 

This was selected as the best answer
CKNCKN

THANKS SOO MUCH!!!

 

Chitra

TrueCloudTrueCloud

I am glad it worked for you. Can you put your modified code for benefit of others.

 

Thanks.