You need to sign in to do that
Don't have an account?
Glen.ax1034
throwing concrete sobject error in for loop? why? these are concrete
trigger ActivateContract on Contract (before update) { List<RecordType> rTypes = [select id,name from RecordType where SobjectType='Contract']; //pull recordtype Id's and record type names from recordtypes where the sobject is contract MAP<Id , String> maprtID_rtName = new MAP<ID , String>(); //map record type ID's to record type names. for(RecordType rTypeObj : rTypes) { maprtID_rtName.put(rTypeObj.id , rTypeObj.Name); //for all recordtypes... log id's and record type names. } List<Group> gTypes = [SELECT Id, name FROM Group where Type = 'Queue']; //pull recordtype Id's and record type names from recordtypes where the sobject is contract MAP<String , Id> mapgName_gID = new MAP<String , Id>(); //map record type ID's to record type names. for(Group gTypeObj : gTypes) { mapgName_gID.put(gTypeObj.Name, gTypeObj.id); //for all recordtypes... log id's and record type names. } List<RecordType> rTypesCases = [select name,id from RecordType where SobjectType='Case']; //pull recordtype Id's and record type names from recordtypes where the sobject is contract MAP<String, ID> maprtName_rtIDCases = new MAP<String, ID>(); //map record type ID's to record type names. for(RecordType rTypeObj : rTypesCases) { maprtName_rtIDCases.put(rTypeObj.Name, rTypeObj.id); //for all recordtypes... log id's and record type names. } List<User> rUserManager = [select id,ManagerId from User]; //pull recordtype Id's and record type names from recordtypes where the sobject is contract MAP<ID, ID> maprtid_rtManagerId = new MAP<ID, ID>(); //map record type ID's to record type names. for(ID uTypeobj : rUserManager) { maprtid_rtManagerId.put(uTypeobj.id, uTypeobj.ManagerId); //for all recordtypes... log id's and record type names. } String rType; //declare string rType. //Use a for loop to run through The trigger Contracts and assign for every Case.AccountId a unique Contract.Id from the map List<Case> Cases = new List<Case>(); for (Contract contract:Trigger.new){ //contract.Manager__c=maprtid_rtManagerId(contract.Salesperson__c); if(contract.First_Activation__c == False) { //this is the first time the contract has been activated if (contract.Status == 'Activated Signed') { if(contract.Major_Product_Line__c == 'Background (BSG)' || contract.Major_Product_Line__c == 'Advanced Biometric/I-9 (ABG)' || contract.Major_Product_Line__c == 'Drug (Occupational Health) (OHG)') { if(maprtID_rtName.containsKey(contract.RecordTypeId)) //these are mapping the current contracts reference to recordtype ID to record type name rType = maprtID_rtName.get(contract.RecordTypeId); //rtype is now the recordtypeID of the contract if(rType == 'Application' || rType == 'Supporting Documentation' || rType == 'MSA - Master Service Agreement' || rType == 'Amendment' || rType == 'Standalone Agreement' || rType == 'Addendum') { Case CaseAdd = new Case (); CaseAdd.AccountId = contract.AccountId; //preload fields for the case CaseAdd.Origin = 'Internal'; CaseAdd.Contract_Number__c = contract.Id; CaseAdd.RecordTypeId = maprtName_rtIDCases.get('Account Set Up'); if(contract.Major_Product_Line__c == 'Background (BSG)') CaseAdd.Request_Product_Type__c = 'Background (BSG)'; if(contract.Major_Product_Line__c == 'Advanced Biometric/I-9 (ABG)') CaseAdd.Request_Product_Type__c = 'Advanced Biometric/Fingerprint//I-9 (ABG)'; if(contract.Major_Product_Line__c == 'Drug (Occupational Health) (OHG)') CaseAdd.Request_Product_Type__c = 'Drug (Occupational Health) (OHG)'; CaseAdd.Ownerid=mapgName_gID.get('Account Set Up'); Cases.add(CaseAdd); //add the case in a bulk way :-) contract.First_Activation__c = True; //set the activation to true.. so that it doesnt create multiple cases.. one is all you need } } } } // } // upsert Cases; // if(contract.Major_Product_Line__c == 'Drug (Occupational Health) (OHG)') { if(contract.Created_Child_Case__c == false) { if (contract.Status == 'Activated Signed') { contract.Created_Child_Case__c = true; Case CaseAdd2 = new Case(); CaseAdd2.RecordTypeId = maprtName_rtIDCases.get('OHG IMPLEMENTATIONS'); CaseAdd2.Ownerid = mapgName_gID.get('OHG Implementations'); CaseAdd2.AccountId = contract.AccountId; CaseAdd2.Contract_Number__c = contract.Id; CaseAdd2.Origin = 'Internal'; CaseAdd2.Request_Type__c = 'Implementation New Client'; Cases.add(CaseAdd2); } } } if(contract.Major_Product_Line__c == 'Background (BSG)') { Set<String> multiselectValues = new Set<String>(); multiSelectValues.addAll(contract.Services_Included__c.split(';')); if (contract.Status == 'Activated Signed') { if(multiSelectValues.contains('Drug Services')){ if(contract.Created_Child_Case__c == false) { contract.Created_Child_Case__c = true; Case CaseAdd3 = new Case(); CaseAdd3.RecordTypeId = maprtName_rtIDCases.get('OHG IMPLEMENTATIONS'); CaseAdd3.AccountId = contract.AccountId; CaseAdd3.Contract_Number__c = contract.Id; CaseAdd3.Origin = 'Internal'; CaseAdd3.Request_Type__c = 'Implementation New Client'; CaseAdd3.Ownerid = mapgName_gID.get('OHG Implementations'); Cases.add(CaseAdd3); } } } } if(contract.Major_Product_Line__c == 'Assessments') { Set<String> multiselectValues = new Set<String>(); multiSelectValues.addAll(contract.Services_Included__c.split(';')); if (contract.Status == 'Activated Signed') { if(multiSelectValues.contains('Assessments Online Testing')){ if(multiSelectValues.contains('Assessments Professional Services')){ } else { if(contract.Created_Child_Case__c == false) { contract.Created_Child_Case__c = true; Case CaseAdd3 = new Case(); CaseAdd3.RecordTypeId = maprtName_rtIDCases.get('Account Set Up'); CaseAdd3.Ownerid = mapgName_gID.get('Account Set Up'); CaseAdd3.AccountId = contract.AccountId; CaseAdd3.Contract_Number__c = contract.Id; CaseAdd3.Origin = 'Internal'; CaseAdd3.Request_Type__c = 'New Account'; Cases.add(CaseAdd3); } } } } } } upsert Cases; }
errors on line 31
Line 26 says you have a list of Users ....
Line Number 29 uses ID to traverse with..
I think it should look like :
Line 29 : for(User uTypeObject:rUserManager)
All Answers
Line 26 says you have a list of Users ....
Line Number 29 uses ID to traverse with..
I think it should look like :
Line 29 : for(User uTypeObject:rUserManager)
awesome thanks. quick question, for the line:
in our database, not all salesperson's have manager's in that field, so would this throw an error if the list that it is referencing and trying to put salesperson__c returns a null or empty manager value?