I am trying to figure out how to make a new comment required when the record owner is changed. I assume it is an 'after update' trigger. I do not see how to integrate the existing comment related list.
Should I create a new comment page via visualforce and redirect the user after they change the owner of the record?
The scenario goes like this:
After closing a case, the user is sent a customer survey. The customer survey is a custom object. After the user is done filling out the survey they submit it. On the customer survey record is a field which totals the values chosen in the survey. For example, if the user selects all 5s, the value of this custom formula field on the customer survey record is 25. This rollup value field is the field I want populated back to the original case from which the survey was sent.
How do I update the value of the rollup field on the survey object to a field on the case object. These values should always be the same.
Thank you in advance for your help.
This is the first trigger i am trying. I wanted to create a workflow or something by which i could populate a custom field in Account with some profile info from a field from the User Info page. It seems there is no way to get the user info for the person who created the record using workflow and triggers are the only choice.
So i have been reading up on it and trying to come up with a solution. I will post my attempts here, hopefully you guys can help me so that i can archive my goal and also learn about triggers.
trigger updateProfile on Account (after update)
Account.Profile__c = User.Division;
Here i am trying to get the Division name for the user and input it into the custom field called Profile in the Account object. This is not working for me, can someone tell me what i am doing wrong?
I have a requirement where i need to check the Owner Territory, and User Title Before Update,
The Previous owner can transfer the particualr opportuntiy to a new Owner if the Parent Territory of both (New Owner, Previous Owner) are same and the new user has title as "Special" . A particular user can sit on more then one territory. so only those users can be new owner which satisfy this condition.
I am new to Apex, i wrote something based on S-Control i saw on the community.
trigger NewOwner on Opportunity (before update, after update)
//string profileid =UserInfo.getProfileId();
ID oppsid = Trigger.old.Id;
User PreviousOwner = [select id, profileid from User where id=:Trigger.old.OwnerId Limit 1];
//String OwnerId = user.Id;
// Territory of the Owner
UserTerritory OwnerTerritory = [select Id, TerritoryId, IsActive from UserTerritory where UserId=:Trigger.old.OwnerId and IsActive = TRUE];
for(Integer i=0; i<OwnerTerritory.size(); i++)
// Parent Territory of the Owner
Territory OwnerParentTerritory = [select Id, Name, ParentTerritoryID from Territory where Id=:OwnerTerritory[i].TerritoryId];
for (Integer j=0; j<OwnerParentTerritory.size(); j++)
// Get the New User's Id and Title.
User NewOwner = [select Id, Title from User where id=:Trigger.new.OwnerId Limit 1];
// To get the New User's Territory
UserTerritory NewOwnerTerritory = [select Id, TerritoryId, IsActive from UserTerritory where UserId =:Trigger.new.OwnerId and IsActive = TRUE];
Territory NewOwnerParentTerritory = [select Id, Name, ParentTerritoryID from Territory where Id=:NewOwnerTerritory.TerritoryId];
for(Integer k=0; k<NewOwnerParentTerritory.size(); k++)
if(NewOwner.Title == 'Special' && NewOwnerParentTerritory[k].ParentTerritoryID == OwnerParentTerritory[j].ParentTerritoryID)
UserTerritory OldOwner = [select TerritoryId, UserId from UserTerritory where UserId=:Trigger.old.OwnerId and IsActive = TRUE];
for(Integer l=0; l<OldOwner.size(); l++)
for(UserTerritory OldOwnerTerritoryUsers:[select UserId from UserTerritory where TerritoryId=:OldOwner[l].TerritoryId and IsActive = TRUE])
OpportunityShare oppsshare = new OpportunityShare();
oppsshare.OpportunityId = oppsid ;
oppsshare.UserOrGroupId = OldOwnerTerritoryUsers.UserId;
oppsshare.OpportunityAccessLevel = 'Read';
insert oppsshare ;
catch (Exception e)
Trigger.new.OwnerId.addError('Deal can only be assigned to User in your parent territory and with title as Special');
The trigger saved and also is valid but at the time of Operation, i recieve this error message.
Error - Apex trigger: NewOwner caused an unexpected exception, contact your administrator: NewOwner: execution of BeforeUpdate caused by: System.ListException: List index out of bounds: 0: Trigger.NewOwner
Error: Apex trigger NewOwner caused an unexpected exception, contact your administrator: NewOwner: execution of AfterUpdate caused by: System.Exception: Too many SOQL queries: 21: Trigger.NewOwner: line 18, column 19
If someone can please help me with this, would be great help.
Many Thanks in Advance.
Message Edited by Developer118 on 02-12-2008 02:16 PM
Message Edited by Developer118 on 02-12-2008 02:17 PM