• Rob.Rosen
  • NEWBIE
  • 0 Points
  • Member since 2010

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

Hi all,

 

I am very much a newbie at Apex development.  What I'm trying to do is automatically assign cases when they are created by our customers using the Customer Portal.  Case Assignment Rules are just not flexible enough for what I want:  I want the owner to be grabbed from a custom field on the related Account object (that field is named Support_Manager__c, and is a User lookup).

 

Here's what I've got:

 

trigger AddSupportOwnerToPortalCase on Case (before insert) {

	for (Case c : Trigger.new) {
		User u = [Select Id, PortalRole From User where ID = :c.CreatedById];
		if (u.PortalRole.contains('Customer')) {
			Account a = [Select Id, Support_Manager__c From Account where Id = :c.AccountId];
			c.OwnerId = a.Support_Manager__c;			
		}
	}
}

 If I try this using BEFORE insert, I get an error that says "Apex trigger AddSupportOwnerToPortalCase caused an unexpected exception, contact your administrator: AddSupportOwnerToPortalCase: execution of BeforeInsert caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.AddSupportOwnerToPortalCase: line 8, column 1".

 

If I try AFTER INSERT, I get an error on the line c.OwnerId = a.Support_Manager__c saying that the record is read-only.

 

Thanks very much for any help!

Rob

Hi there,

 

I'm trying to create a validation rule for quote line items where the constraints is that if a particular item is present the list, one of several others must also be present.  I've tried a bunch of things and am completely stymied by this so far.  Anyone have an idea for me?


Thanks,

Rob

Hi there,

 

I'm trying to create a validation rule for quote line items where the constraints is that if a particular item is present the list, one of several others must also be present.  I've tried a bunch of things and am completely stymied by this so far.  Anyone have an idea for me?


Thanks,

Rob