• Patrick C Mayer 91
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 3
    Replies
I can't figure out how to check the RecordType in the rerender.
public class SubmitCaseController {
	
	public Case c { get; set; }
	
	public String acctNum { get; set; }
	
	public SubmitCaseController() {
		c = new Case();
	}
    
	public PageReference submitCase() {
		List<Account> accts = [SELECT Id FROM Account WHERE AccountNumber = :acctNum];
		if (accts.size() != 1) {
			ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Invalid account number');
			ApexPages.addMessage(msg);
			return null;
		} else {
			try {
				c.AccountId = accts.get(0).Id;
				
				// now look for an associated contact with the same email
				Contact cnt = [SELECT Id FROM Contact WHERE AccountId = :c.AccountId AND Email = :c.SuppliedEmail LIMIT 1];
				if (cnt != null) 
					c.ContactId = cnt.Id;
					
				// Specify DML options to ensure the assignment rules are executed
				Database.DMLOptions dmlOpts = new Database.DMLOptions();
				dmlOpts.assignmentRuleHeader.useDefaultRule = true;
				c.setOptions(dmlOpts);

				// Insert the case
				INSERT c;
				return new PageReference('/thanks');
			} catch (Exception e) {
				ApexPages.addMessages(e);
				return null;
			}
		}
	}
<apex:page controller="SubmitCaseController">    
    <apex:form >
        <apex:pageBlock title="New Case" id="thePageBlock" mode="edit">
        <table>
            <tr>
                <th>
                    Type:
                </th>
                <td>
                    <apex:inputField value="{!c.recordTypeId}">
                    <apex:actionSupport event="onchange" rerender="thePageBlock" status="status"/>
                    </apex:inputField>
                </td>
            </tr>
            <tr>
                <th>
                    <apex:pageBlockSection rendered="{!c.recordType.name == 'Auto Notification'}">
                    TEST
                    TEST
                    TEST
                    </apex:pageBlockSection>
                </th>
            </tr>
        </table>
        </apex:pageBlock>
    </apex:form>

</apex:page>



trigger TaskCompletionMailerTrigger on Task (after update) {
	Task[] tasks = trigger.new;
    for (Task t : tasks) {
        if (t.Status.equals('Completed') && !t.OwnerId.equals(UserInfo.getUserId())) {
            User[] user = [SELECT Id, Email
                           FROM User
                           WHERE Id =: (t.OwnerId)]; 
            String userEmail;
            if (user.size() > 0) {
                userEmail = user[0].Email;
            } else {
                System.debug('User Lookup Failed on Task OwnerId: ' + t.OwnerId);
            }

			Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
			String[] toAddresses = new String[] { userEmail }; 
     
			mail.setToAddresses(toAddresses); 
            
			mail.setSubject('Automated Task Completion email: ' + t.Subject); 
            String rel = '';
			Account[] acct = [SELECT Id, Name
                 			  FROM Account
                			  WHERE Id =: t.AccountId];
            if (acct.size() > 0) {
                rel = 'Account - ' + acct[0].Name;
            }
            
			String body = 'Task: ' + t.Subject + '\nCompleted by ' + UserInfo.getName()
                + '\nRelated To: ' + rel + '\nComments: ' + t.Description; 
			mail.setPlainTextBody(body); 
            
			Messaging.sendEmail(new Messaging.SingleEMailMessage[]{mail});
        }
    }
}


@isTest (seeAllData=true)
public class TaskCompletionMailerTest{
    static testMethod void test() {
        Account acct = new Account(Name = 'Test Account');
        insert acct;
        User creator = new User(alias = 'crtr', email='patrick@eatstreet.com',
                                emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
                                localesidkey='en_US', profileid = UserInfo.getProfileId(),
                                timezonesidkey='America/Los_Angeles', username='creator@testorg.com');
        User completer = new User(alias = 'cmpltr', email='completer@test.com',
                                  emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
                                  localesidkey='en_US', profileid = UserInfo.getProfileId(),
                                  timezonesidkey='America/Los_Angeles', username='completer@testorg.com');
        insert creator;
        insert completer;
        
        Task t = new Task(Ownerid = creator.Id, Subject = 'Test', ActivityDate = Date.today(), 
                          WhatId = acct.Id, Status = 'Pending', Priority = 'Low', 
                	      Description = 'Test');
        insert t;
        
        Integer emailbefore = Limits.getEmailInvocations();
        System.runAs(completer) {
            t.Status = 'Completed';
            update t;
        }
        System.assertNotEquals(emailbefore,Limits.getEmailInvocations(),'should have decreased');
        
        emailbefore = Limits.getEmailInvocations();
        System.runAs(creator) {
            t.Status = 'Completed';
            update t;
        }
        System.assertEquals(emailbefore,Limits.getEmailInvocations(),'should remained constant');
    }
}


I am having touble deploying this. It keeps returning "Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []", Failure Stack Trace: "Class.IdleCaseTriggerTest.test: line 16, column 1"" 

 

I don't even have any code on line 16.
 

I know I can use Visualforce to invoke apex, but can it go the other way around?
I made some updates to fix other errors and this code stopped working properly. When it calls openPopup() from the commandButton it works normally, but when it is automatically called from the actionStatus I am getting nothing. I have checked my pop-up setting in the browser. Not realy sure what happened.
<apex:page controller="IdleCasePopUp">
    <apex:form >  
    <apex:pageBlock id="myPageId">
        <apex:actionPoller reRender="myPageId" interval="10" status="renderMeStatus"/>
        <apex:actionStatus id="renderMeStatus" onstop="openPopup()"/>
         <apex:commandButton title="Test" value="Show Queue" onclick="openPopup()"/>
         <apex:outputText value="{!dP}"/>
         
<script id="script">
    var newWin=null;
    function openPopup() {
        var url="/apex/autoOpen";
       
        if ({!dP}) {
            newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
            IdleCasePopUp.closePopup();
        }
        
        if (window.focus) {
            newWin.focus();
        }
    }

       
    function closeLookupPopup() {
        if (null!=newWin) {
            newWin.close();
        }  
    }
</script> 
    </apex:pageBlock>
    </apex:form>
</apex:page>


I deleted parts of my code that are not relevant to this question. Essentially this should rerender the page causing it to call openPopup(). Which then opens the pop up and then calls closePopup, which should set displayPopUp to false. However it would seem displayPopUp is not being updated properly at least on the VF side.

<apex:page controller="IdleCasePopUp">
    <apex:form > 
    <apex:pageBlock id="myPageId">
        <apex:actionPoller reRender="myPageId" interval="10" status="renderMeStatus"/>
        <apex:actionStatus id="renderMeStatus" onstop="openPopup()"/>
        
<script id="script">
    var newWin=null;
    function openPopup() {
        var url="/apex/autoOpen";
      
        if ({!displayPopup}) {
           newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
           closePopup();
        }
    }

</script>
    </apex:pageBlock>
    </apex:form>
</apex:page>

global class IdleCasePopUp implements Schedulable {      
    public boolean displayPopup {get; set;}
    
    public IdleCasePopUp() { 
    	displayPopUp = true;
    }
    
    public void closePopup() {  
        displayPopup = false;    
    }     
    
    public void showPopup() {        
        displayPopup = true;    
    }
    
}


I have followed the tutorial linked below for "Receiving Notifications in a Visualforce Page" numerous times and copy/pasted the code verbatim, but I get the same two errors every time.

https://developer.salesforce.com/page/Getting_Started_with_the_Force.com_Streaming_API

These are the error logs in google chromes JavaScript Console.

Refused to set unsafe header "User-Agent"                                                StreamingPage:1
Uncaught TypeError: Cannot read property 'replace' of undefined        StreamingPage:35

Not really sure what to do especially since StreamingPage is only 33 lines long.
I need a custom console window to open automatically when certain things happen. Preferably could be set off by a workflow rule. Any Ideas?
This gives me some type of error, but no message. How do I create a push topic?

PushTopic pushTopic = new PushTopic();
pushTopic.Name = 'IdleCasePushTopic';
pushTopic.Query = 'SELECT Id, Idle_Case_Hidden__c FROM Case';
pushTopic.ApiVersion = 30.0;
pushTopic.NotifyForOperationCreate = true;
pushTopic.NotifyForOperationUpdate = true;
pushTopic.NotifyForOperationUndelete = true;
pushTopic.NotifyForOperationDelete = true;
pushTopic.NotifyForFields = 'Referenced';
insert pushTopic;

I've been looking for a way to do this and haven't really figured out anything great.

Basically, I would like a custom console component to start blinking, open or in some way notify anyone on the service cloud page when a case has been sitting in the general case queue for 15 minutes without being claimed.

Any help or points in the right direction are much appreciated.

trigger TaskCompletionMailerTrigger on Task (after update) {
	Task[] tasks = trigger.new;
    for (Task t : tasks) {
        if (t.Status.equals('Completed') && !t.OwnerId.equals(UserInfo.getUserId())) {
            User[] user = [SELECT Id, Email
                           FROM User
                           WHERE Id =: (t.OwnerId)]; 
            String userEmail;
            if (user.size() > 0) {
                userEmail = user[0].Email;
            } else {
                System.debug('User Lookup Failed on Task OwnerId: ' + t.OwnerId);
            }

			Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
			String[] toAddresses = new String[] { userEmail }; 
     
			mail.setToAddresses(toAddresses); 
            
			mail.setSubject('Automated Task Completion email: ' + t.Subject); 
            String rel = '';
			Account[] acct = [SELECT Id, Name
                 			  FROM Account
                			  WHERE Id =: t.AccountId];
            if (acct.size() > 0) {
                rel = 'Account - ' + acct[0].Name;
            }
            
			String body = 'Task: ' + t.Subject + '\nCompleted by ' + UserInfo.getName()
                + '\nRelated To: ' + rel + '\nComments: ' + t.Description; 
			mail.setPlainTextBody(body); 
            
			Messaging.sendEmail(new Messaging.SingleEMailMessage[]{mail});
        }
    }
}


@isTest (seeAllData=true)
public class TaskCompletionMailerTest{
    static testMethod void test() {
        Account acct = new Account(Name = 'Test Account');
        insert acct;
        User creator = new User(alias = 'crtr', email='patrick@eatstreet.com',
                                emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
                                localesidkey='en_US', profileid = UserInfo.getProfileId(),
                                timezonesidkey='America/Los_Angeles', username='creator@testorg.com');
        User completer = new User(alias = 'cmpltr', email='completer@test.com',
                                  emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
                                  localesidkey='en_US', profileid = UserInfo.getProfileId(),
                                  timezonesidkey='America/Los_Angeles', username='completer@testorg.com');
        insert creator;
        insert completer;
        
        Task t = new Task(Ownerid = creator.Id, Subject = 'Test', ActivityDate = Date.today(), 
                          WhatId = acct.Id, Status = 'Pending', Priority = 'Low', 
                	      Description = 'Test');
        insert t;
        
        Integer emailbefore = Limits.getEmailInvocations();
        System.runAs(completer) {
            t.Status = 'Completed';
            update t;
        }
        System.assertNotEquals(emailbefore,Limits.getEmailInvocations(),'should have decreased');
        
        emailbefore = Limits.getEmailInvocations();
        System.runAs(creator) {
            t.Status = 'Completed';
            update t;
        }
        System.assertEquals(emailbefore,Limits.getEmailInvocations(),'should remained constant');
    }
}


I am having touble deploying this. It keeps returning "Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []", Failure Stack Trace: "Class.IdleCaseTriggerTest.test: line 16, column 1"" 

 

I don't even have any code on line 16.
 

I have followed the tutorial linked below for "Receiving Notifications in a Visualforce Page" numerous times and copy/pasted the code verbatim, but I get the same two errors every time.

https://developer.salesforce.com/page/Getting_Started_with_the_Force.com_Streaming_API

These are the error logs in google chromes JavaScript Console.

Refused to set unsafe header "User-Agent"                                                StreamingPage:1
Uncaught TypeError: Cannot read property 'replace' of undefined        StreamingPage:35

Not really sure what to do especially since StreamingPage is only 33 lines long.
Hello Salesforcians,

Can somebody please help me. I am extremely confused. I work strictly in the service console and I cannot figure out the "stock" push notifications feature for the life of me.

According to the documention (link posted below) two users working simultaneously on the same list or detail page will be informed of any updates. However, I CANNOT duplicate this. I even tried duplicating the issue in a stock salesforce list and still no luck.

I literally open two seperate browsers on the same case, make a change, nothing happens. I have the objects and fields properly selected.

Worst case scenario, I can set up my own streaming API. But why? When it's built it!

Please help! Kudos are waiting :-)
Thanks in advance!

Push Notifications: https://help.salesforce.com/HTViewHelpDoc?id=console2_push_notifications.htm&language=en_US