0

Could you help me with my method for my approval flow? I created a custom settings named Approver_Matrix . Here is a sample:

enter image description here

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:

  1. 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?
  2. What would be the effective one to be used?
  3. When using the SOQL query (see above), got an error saying unexpected token: ‘:’. What to do here?
  4. 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.

enter image description here

| improve this question | | | | |
  • Additional question - When executing anonymous window with code 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. – Grashela Reyes Dec 10 '14 at 13:15
1

On 1, 2 and 3, I would choose to query for the value because all the conveniences of SOQL are then available:

Integer approverCtr = 1;
for (Approval_Matrix__c am : [
        SELECT Name, Limit__c, Position__c, Approver__c, Approver_Email__c,
                Public_Account__c, Private_Account__c
        FROM Approval_Matrix__c
        WHERE Public_Account__c = :pubAcc
        AND Private_Account__c =:prvAcc
        AND Limit__c >= :contractAmount
        ORDER BY Approver_Email__c
        ]) {
    approvalMap.put(approverCtr, am);
}

If you use Approval_Matrix__c.getAll().values(), you have to do more work in your Apex code with the only benefit being avoiding one SOQL query.

I don't understand your question 4.

| improve this answer | | | | |
  • Based from the 'Contract Amount' of the opportunity, when the limit was hit (check the approval matrix values - custom settings) the said approver/s will be retrieved in the custom settings and will be assigned to that opportunity and email notification was sent to the approver/s. – Grashela Reyes Dec 10 '14 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.