Could you help me with my method for my approval flow? I created a custom settings named Approver_Matrix . Here is a sample:
Note: Private Account and Public Account fields were checkbox. For my method, the expected return of the method is a Map of Integer and object type Approver_Matrix : Map.
Public Map<Integer, Approval_Matrix__c > ApprovalProcess(Opportunity oppty) {
Map<Integer, Approval_Matrix__c > approvalMap = new Map<Integer, Approval_Matrix__c >();
Decimal contractAmount = Opportunity.Contract_Amount__c;
String acctMgrRole = Opportunity. Account_Manager__r.UserRole.Name;
Boolean pubAcc = acctMgrRole.contains(‘Public Account’);
Boolean prvAcc = acctMgrRole.contains(‘Private Account’);
List< Approval_Matrix__c > approverList = new List< Approval_Matrix__c > ([SELECT Name, Limit__c, Position__c, Approver__c, Approver_Email__c, Public_Account__c, Private_Account__c WHERE Public_Account__c =: pubAcc && Private_Account__c =: prvAcc]);
Integer approverCtr = 1;
For (Approval_Matrix__c apr :approverList) {
If (contractAmount <= apr.Limit__c) {
approvalMap.add(approverCtr, apr);
approverCtr ++;
}
}
Return approvalMap;
}
Questions:
- What will be the differences between querying the custom settings using these List< Approval_Matrix__c > apr = Approval_Matrix__c.getall().values() VS SELECT Name, Limit__c, Position__c, Approver__c, Approver_Email__c, Public_Account__c, Private_Account__c WHERE Public_Account__c =: pubAcc && Private_Account__c =: prvAcc?
- What would be the effective one to be used?
- When using the SOQL query (see above), got an error saying unexpected token: ‘:’. What to do here?
- What missing code will do the work if the opportunity’s contract amount is 25, 000 and role of Account Manager is neither Public nor Private the following approver would be retrieved.
Opportunity oppty = [SELECT Id, Contract_Amount__c, Account_Manager__r.UserRole.Name FROM Opportunity WHERE Id = '<oppty ID>']; system.debug(aprs.determineApprovalFlow(oppty));
Got an error when the anonymous code was executed saying 'System.QueryException: List has more than 1 row for assignment to SObject' What to do to get rid of the error? Thanks in advance.