I have written an Apex code for whenever a new Record for City_census custom Object is inserted, the approver should automatically be the owner of that record based on their City.
In Custom Metadata, I have created a Queue for 4 different cities.
These 4 Cities should be the basis of which Record owner to assign as the approver.
Below is the code I have written for this: Not sure if this would work. But I keep getting this error under logs:
Method does not exist or incorrect signature: void indexOf(Group) from the type String
Where did I have done wrong?
//WHENEVER A NEW RECORD IS ADDED
public static void submitForApproval(List<City_Census__c> census){
//Set<Id> cityName = new Set<Id>();
//Map<Id, List<Contact>> cityName = new Map<Id, List<Contact>>();
census = new List<City_Census__c>();
Boolean isAutoApproved = true;
String approverCityBased;
Group queueApprover = new Group();
//List<City_Census__c> cityCensus = new List<City_Census__c>();
List<Group> listOfApprovers = [SELECT Id, Name FROM Group WHERE Type = 'Queue'];
//String cityName = listOfApprovers.addAll(Name);
for(Group City : listOfApprovers){
Group cityName = new Group(Id = queueApprover.Id);
if(City.Name.indexOf(cityName) != -1){
approverCityBased = City.Name;
}
}
queueApprover = [SELECT Id, Name FROM Group WHERE Type = 'Queue' AND Name =: approverCityBased];
String approverId = queueApprover.Id;
for(City_Census__c cityRecord : census){
cityRecord.OwnerId = approverId;
if(cityRecord.Approval_Status__c == null || !isAutoApproved){
cityRecord.Approval_Status__c = 'Approval';
}
if(isAutoApproved){
cityRecord.Approval_Status__c = 'Approved';
cityRecord.Approved_By__c = approverCityBased;
}
}