• Thomas Peng - Articulate
  • NEWBIE
  • 0 Points
  • Member since 2014
  • IT Manager
  • ARticulate

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I'm learning about the capabilities of canvas.  Is it possible to create a button on the account page so that it will open the canvas app and pass in the Account Id from the account I'm viewing to canvas?   
Most of the demos that I've see only show opening the app in another tab.   
Hi,

Can anybody help me with a test class for this trigger? I've asked the author of the trigger to send me the test class, but no response. And I'm not familiar with writing triggers / test classes. I've got it working in my sandbox, but I can't deploy it in my production without a test class.

public class LookupCalculation{
    
    public enum Method {COUNT, SUM, MIN, MAX, AVG}
    
    private string sobjectParent,
                   relationName,
                   formulaParent,
                   sobjectChild,
                   parentfield,
                   fieldChild;
    
    public LookupCalculation(string mysobjectParent, string myrelationName, string myformulaParent,
                             string mysobjectChild, string myparentfield, string myfieldChild){
        sobjectParent = mysobjectParent;
        relationName = myrelationName;
        formulaParent = myformulaParent;
        sobjectChild = mysobjectChild;
        parentfield = myparentfield;
        fieldChild = myfieldChild;
    }
    
    public void Calculate(Method calculation, List<sobject> childList){
        set<Id> parentIdSet = new set<Id>();
        for(sobject sobj : childList)
            parentIdSet.add((Id) sobj.get(parentfield));
        string soqlParent = 'select id, (select ' + fieldChild + ' from ' + relationName + ') from ' + sobjectParent + '';
        List<sobject> parentList = Database.query(soqlParent);
        for(sobject parent : parentList){
            List<sobject> children = parent.getSObjects(relationName);
            if(children == null)
                children = new List<sobject>();
            Decimal counter = (mustSum(calculation))? 0 : null;
            if(calculation == Method.COUNT)
                counter = children.size();
            for(sobject child : children){
                Decimal value = (Decimal) child.get(fieldChild);
                if(mustSum(calculation) && value != null)
                    counter += value;
                else if(calculation == Method.MIN && (counter == null || value < counter))
                    counter = value;
                else if(calculation == Method.MAX && (counter == null || value > counter))
                    counter = value;
            }
            if(calculation == Method.AVG && children.size() > 0)
                counter = counter / children.size();
            parent.put(formulaParent, counter);
        }
        update parentList;
    }
    
    private boolean mustSum(Method calculation){
        return (calculation == Method.SUM || calculation == Method.AVG);
    }
    
}

---------------------------------------------------------------------------------------------

trigger InvoiceLineRollUp on Invoice_Line__c (after insert,after update,after delete,after undelete) {
    
    /*******************TO BE CUSTOMIZED*********************/
    string mysobjectParent = 'Invoice__c',      // Parent sobject API Name
           myrelationName = 'Invoice_Lines__r', // Api name of the relation between parent and child (ends with __r)
           myformulaParent = 'Total__c',        // Api name of the number field that will contain the calculation
           mysobjectChild = 'Invoice_Line__c',  // Child sobject API Name
           myparentfield = 'Parent_Invoice__c', // Api name of the lookup field on chield object
           myfieldChild = 'Amount__c';          // Api name of the child field to roll up
    
    LookupCalculation.Method method = LookupCalculation.Method.SUM; //Selected method: could be COUNT, SUM, MIN, MAX, AVG
    /*******************************************************/
    
    LookupCalculation calculation = new LookupCalculation(mysobjectParent, myrelationName, myformulaParent,
                                                          mysobjectChild, myparentfield, myfieldChild);
    List<sobject> objList = new List<sobject>((List<sobject>) Trigger.new);
    if(Trigger.isDelete)
        objList = Trigger.old;
    if(Trigger.isUpdate)
        objList.addAll((List<sobject>) Trigger.old);
    calculation.calculate(method, objList);
}


See website: http://blog.elieperez.net/salesforce-lookup-roll-up-summary/
  • February 17, 2014
  • Like
  • 1
Hi, I have article knowledge enabled in my org and I would like to do some restriction that some users only able to see certain articles by category.

I have created a few category group and my 'Default Visibility Settings' set to None but my standard user still able to see published article.

Thanks.