Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
1
Indexable
Never
@InvocableMethod(label='Send Account Data D365 to an Endpoint', description='BUCHCRM-2114')
public static List<String> sendAccount(List<Account> inputVariables) {
    CustomerRestClass instanceOfThisClass = new CustomerRestClass();
    List<String> returnMsgList = new List<String>();
    List<Account> accountBatch = new List<Account>();
    Integer batchSize = 10; // 
    for (Integer i = 0; i < inputVariables.size(); i++) {
        accountBatch.add(inputVariables[i]);
        if (accountBatch.size() == batchSize || i == inputVariables.size() - 1) {
            List<String> returnMessages = instanceOfThisClass.sendAccountBatch(accountBatch);
            returnMsgList.addAll(returnMessages);
            accountBatch.clear();
        }
    }
    return returnMsgList;
}
private List<String> sendAccountBatch(List<Account> accountBatch) {
    List<String> returnMessages = new List<String>();
    List<String> requestBodyList = new List<String>();
    for (Account acc : accountBatch) {
        String requestBody = generateRequestBody(acc);
        requestBodyList.add(requestBody);
    }
    String requestBody = String.join(requestBodyList, ',');
    sendCustomerDataToD365('[' + requestBody + ']');
    for (Integer i = 0; i < accountBatch.size(); i++) {
        returnMessages.add('Success');
    }
    return returnMessages;
}