You need to sign in to do that
Don't have an account?
SFDC n12
Trigger Help needed
Hi,
I am having a following requirement for which i have written a trigger which i need help on it
1) I am having a field called as DOS Approver__c which is a lookup to user object
2) I am having another field called as RVP Approver__c which is a look up to user object
3) I am having a custom field called as New Request__c which is a lookup to account
All these 3 custom fields are present in my custom object called as "Account Exceptions"(Special_Programs_ADR_Exception__c)
My req is when i select a account(New Request__c ) and a DOS Approver__c the RVP Approver__c should be auto populated with the manager of the DOS APPROVER User
This functionality should be applied only for Group Account record type(Based on the account that i select in my custom object)
MY TRIGGER :
trigger AF_RVP on Special_Programs_ADR_Exception__c (after insert, after update) {
List<Id> rvpId = new List<Id>();
Set<Id> adrId = new Set<Id>();
for(Special_Programs_ADR_Exception__c spl:trigger.new)
{
rvpId.add(spl.DOSUser__c);
rvpId.add(spl.NewRequest__c);
adrId.add(spl.Id);
}
RecordType rtypes = [SELECT Name, id FROM RecordType WHERE isActive=true AND SobjectType='Account'AND Name = 'Group Account' limit 1];
User actingUsers =[SELECT Name, ManagerID, Manager.Name, Manager.ManagerID, Manager.Manager.Name FROM User WHERE Id = :rvpId LIMIT 1];
List<Special_Programs_ADR_Exception__c> adrExpList = [Select Id,RVP_Approver__c,NewRequest__c,NewRequest__r.RecordTypeId From Special_Programs_ADR_Exception__c Where Id IN :adrId];
List<Special_Programs_ADR_Exception__c> oppts = new List<Special_Programs_ADR_Exception__c>();
for (Special_Programs_ADR_Exception__c obj : adrExpList)
{
if(obj.NewRequest__r.RecordTypeId = rtypes.Id) {
obj.RVP_Approver__c= actingUsers[0].ManagerID;
}
}
}
I am getting the following error
Error: Compile Error: Expression must be a list type: SOBJECT:User at line 20 column 23
obj.RVP_Approver__c= actingUsers[0].ManagerID;
Kindly help me what do i need to change in my trigger
Thanks in Advance
I am having a following requirement for which i have written a trigger which i need help on it
1) I am having a field called as DOS Approver__c which is a lookup to user object
2) I am having another field called as RVP Approver__c which is a look up to user object
3) I am having a custom field called as New Request__c which is a lookup to account
All these 3 custom fields are present in my custom object called as "Account Exceptions"(Special_Programs_ADR_Exception__c)
My req is when i select a account(New Request__c ) and a DOS Approver__c the RVP Approver__c should be auto populated with the manager of the DOS APPROVER User
This functionality should be applied only for Group Account record type(Based on the account that i select in my custom object)
MY TRIGGER :
trigger AF_RVP on Special_Programs_ADR_Exception__c (after insert, after update) {
List<Id> rvpId = new List<Id>();
Set<Id> adrId = new Set<Id>();
for(Special_Programs_ADR_Exception__c spl:trigger.new)
{
rvpId.add(spl.DOSUser__c);
rvpId.add(spl.NewRequest__c);
adrId.add(spl.Id);
}
RecordType rtypes = [SELECT Name, id FROM RecordType WHERE isActive=true AND SobjectType='Account'AND Name = 'Group Account' limit 1];
User actingUsers =[SELECT Name, ManagerID, Manager.Name, Manager.ManagerID, Manager.Manager.Name FROM User WHERE Id = :rvpId LIMIT 1];
List<Special_Programs_ADR_Exception__c> adrExpList = [Select Id,RVP_Approver__c,NewRequest__c,NewRequest__r.RecordTypeId From Special_Programs_ADR_Exception__c Where Id IN :adrId];
List<Special_Programs_ADR_Exception__c> oppts = new List<Special_Programs_ADR_Exception__c>();
for (Special_Programs_ADR_Exception__c obj : adrExpList)
{
if(obj.NewRequest__r.RecordTypeId = rtypes.Id) {
obj.RVP_Approver__c= actingUsers[0].ManagerID;
}
}
}
I am getting the following error
Error: Compile Error: Expression must be a list type: SOBJECT:User at line 20 column 23
obj.RVP_Approver__c= actingUsers[0].ManagerID;
Kindly help me what do i need to change in my trigger
Thanks in Advance
for (Special_Programs_ADR_Exception__c obj : adrExpList)
{
if(obj.NewRequest__r.RecordTypeId = rtypes.Id) {
obj.RVP_Approver__c= actingUsers[0].ManagerID;
}
Update adrExpList;
All Answers
So you cannot use actingUsers[0].ManagerId.
Instead of that try actingUsers.ManagerId
Hit Best Answer if it solved your problem
if(obj.NewRequest__r.RecordTypeId == rtypes.Id) {
obj.RVP_Approver__c= actingUsers.ManagerID;
}
its saving the trigger , but not updating the field , is there any issues with my trigger
for (Special_Programs_ADR_Exception__c obj : adrExpList)
{
if(obj.NewRequest__r.RecordTypeId = rtypes.Id) {
obj.RVP_Approver__c= actingUsers[0].ManagerID;
}
Update adrExpList;
You code look quite difficult, Could you try the below one