My solution was first to store custom Metadata. With each row containing
- Object
- RecordType
- Picklists ('Field_1__c, Field_2__c, Field_3__c')
Then going forwards-
- Integration team call to a WebService Apex class
- That WebService Apex class starts a batch Job
- The batch Job fires an Apex Class
The below is the method that is commonly timing out. Both 'service.ReadMetadata' are in the same method doing callouts. So I'm not sure how to synchronously fix these to retain within 120s.
My head is deterioriating so please. Any advice is amazingly appreciated.//List<String> recordType = List of picklist fields available in the recordType
//DescribeSObjectResult objectResult = Current object information
//Set<String> metadataFields = Set of fields to udpate listed in the custom metadata as above
//String recordTypeName = recordTypeName label
public Set<String> processPicklist(List<String> recordType, DescribeSObjectResult objectResult, Set<String> metadataFields, String recordTypeName ) {
for(String picklistValue : recordType) {
if(metadataFields.contains(picklistValue)){
String ctObjectRecordType = String.valueOf(''+objectResult.getLocalName()+'.'+recordTypeName+'');
String fieldName = String.valueOf(''+objectResult.getLocalName()+'.'+picklistValue+'');
List<MetadataService.PicklistValue> pickVals = new List<MetadataService.PicklistValue>();
// Either of these two lines are timing out when it comes to error logs
MetadataService.CustomField picklistFieldMdApi = (MetadataService.CustomField) service.readMetadata('CustomField', new String[] { fieldName }).getRecords()[0];
MetadataService.GlobalValueSet globalPickListApi = (MetadataService.GlobalValueSet) service.readMetadata('GlobalValueSet', new String[] { picklistFieldMdApi.valueSet.valueSetName }).getRecords()[0];
for(MetadataService.CustomValue existing : globalPickListApi.customValue){
MetadataService.PickListValue newPickVal = new MetadataService.PickListValue();
newPickVal.fullName = existing.fullName;
newPickVal.label = existing.label;
newPickVal.isActive = true;
newPickVal.default_x = existing.default_x;
pickVals.add(newPickVal);
}
MetadataService.Metadata[] mdRecordTypes = service.readMetadata('RecordType', new String[]{ctObjectRecordType}).getRecords();
MetadataService.RecordType[] recordTypes = (MetadataService.RecordType[]) mdRecordTypes;} else {recordTypes = new MetadataService.RecordType[]{};
MetadataService.RecordTypePicklistValue[] rtPickValues = new MetadataService.RecordTypePicklistValue[]{};
MetadataService.RecordTypePicklistValue rtPickValue = new MetadataService.RecordTypePicklistValue();
rtPickValue.picklist = picklistValue;
rtPickValue.values = pickVals;
rtPickValues.add(rtPickValue);
for(MetadataService.RecordType RT : recordTypes){ RT.PicklistValues = rtPickValues;}
List<MetadataService.SaveResult> results = new List<MetadataService.SaveResult>();
results = service.updateMetadata(new MetadataService.Metadata[] { mdRecordTypes[0] });
}
}
return metadataFields;
}
As you already know what you are running into is a hard limit enforced as part of Execution Governors and Limit and this cannot be increased. If the third party system handling the request is not capable of parsing the request you sent and is not responding back within the 120 Sec time constraint then we need to fix the batch apex classI suggest reviewing this post for suggestionsOne suggestion I found promising is this: You should be able to loop through, and say in chunks or batches of 10 resumes (or whatever number you chose) and issue callouts. You can make up to 100 callouts in a transaction now that the limit has been increased from 10.