• Manju053
  • NEWBIE
  • 50 Points
  • Member since 2020
  • Developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 15
    Replies
Hello all

I am New to the Aura Componets, i am trying to Build Tree Structure Pictorical Diagram where related contacts should show 
for Parent Account, any help would highly be appriated

User-added imageMy Code
Apex code

public class AccountTreeMapClass {

   @AuraEnabled
   public static account getaccountData(string recId){
       return [select id, name, Company_Head__c,Sales_Team__c,SalesManager__c,Department__c,Director__c, HR_Team__c, Manager1__c, Team_Manager1__c,
               Manager2__c, Team_Manager2__c From account where id=: recId];
   } 
}
-----------------------------

Component


<aura:component controller="AccountTreeMapClass" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="acc" type="Account"/>
    <aura:attribute name="recordId"  type="String" default = "0012w0000085dU4AAI" />
    <aura:handler event="force:refreshView" action="{! c.doInit}" />
    <aura:handler name="init" value="{! this}" action="{! c.doInit}" />
    
    
    <lightning:layout>
        <div class="slds-scrollable" style="height:24rem;width:50rem;background-color: antiquewhite;">
            <body style="margin-top: -19px;">
                <div class="tree"  style="width:200%">
                    <aura:if isTrue="{!not(empty(v.acc.Department__c))}">																																
                        
                        <ul>
                            <li>
                                <p class="bg1"><ui:outputText value="{!v.acc.Department__c}"></ui:outputText> Group</p>
                                <ul>
                                    <li>
                                        <p class="slds-text-heading--medium"  style="background-color: yellow;width: 65px;word-break: break-all;">CEO</p> 
                                        <aura:if isTrue="{!not(empty(v.acc.Company_Head__c))}">
                                            <ul>
                                                <li  class="testry">
                                                    <p class="slds-text-heading--medium" style="background-color: lightblue;width: 65px;word-break: break-all;">{!v.acc.Company_Head__c}</p>
                                                </li>
                                            </ul>
                                        </aura:if>
                                    </li>
                                    <li>
                                        <p class="slds-text-heading--medium"  style="background-color: yellow;Width: 65px;word-break: break-all;">Director</p>			
                                        <aura:if isTrue="{!not(empty(v.acc.Director__c))}">
                                            <ul>
                                                <li>
                                                    <p class="slds-text-heading--medium" style="background-color: lightblue;width: 65px;word-break: break-all;"> {!v.acc.Director__c}</p>
                                                </li>
                                            </ul>
                                        </aura:if>
                                    </li>
                                    <li>
                                        <p class="slds-text-heading--medium"  style="background-color: yellow;width: 65px;word-break: break-all;">HR Department</p>
                                        <aura:if isTrue="{!not(empty(v.acc.HR_Team__c))}">
                                            <ul>
                                                <li>
                                                    <p class="slds-text-heading--medium" style="background-color: lightblue;width: 65px;word-break: break-all;"> {!v.acc.HR_Team__c}</p>
                                                </li>
                                            </ul>
                                        </aura:if>
                                    </li>
                                    
                                    <li>
                                        <p class="slds-text-heading--medium"  style="background-color: yellow;width: 65px;word-break: break-all;">Project Manager1</p>
                                        <aura:if isTrue="{!not(empty(v.acc.Manager1__c))}">
                                            <ul>
                                                
                                                <li>
                                                    <p class="slds-text-heading--medium" style="background-color: lightblue;width: 65px;word-break: break-all;">{!v.acc.Manager1__c}</p>
                                                    <ul>
                                                        <li>
                                                            <p class="slds-text-heading--medium" style="background-color: lightgray;width: 65px;word-break: break-all;">{!v.acc.Team_Manager1__c}</p>
                                                        </li>
                                                        
                                                    </ul>
                                                </li>
                                            </ul>
                                        </aura:if>
                                    </li>
                                    <li>
                                        <p class="slds-text-heading--medium" style="background-color: yellow;width: 65px;word-break: break-all;">Project Manager2</p>
                                        <aura:if isTrue="{!not(empty(v.acc.Manager2__c))}">
                                            <ul>
                                                <li style="background-color: antiquewhite;">
                                                    <p class="slds-text-heading--medium" style="background-color: lightblue;width: 65px;word-break: break-all;"> {!v.acc.Manager2__c}</p>
                                                    <ul>
                                                        <li style="background-color: antiquewhite;">
                                                            <p class="slds-text-heading--medium" style="background-color: lightgray;width: 65px;word-break: break-all;">Yeshwanth</p><!--{!v.keyResult.Team_Manager2__c}-->
                                                        </li>
                                                        <li style="background-color: antiquewhite;">
                                                            <p class="slds-text-heading--medium" style="background-color: lightgray;width: 65px;word-break: break-all;">Sai</p>
                                                        </li>
                                                        
                                                    </ul>
                                                </li>
                                                
                                            </ul>
                                        </aura:if>
                                    </li>
                                    <li>
                                        <p class="slds-text-heading--medium"  style="background-color: yellow;width: 65px;word-break: break-all;">Sales Department</p>
                                        <aura:if isTrue="{!not(empty(v.acc.Sales_Team__c))}">
                                            <ul>
                                                <li class="test" style="background-color: antiquewhite;">
                                                    <p class="slds-text-heading--medium" style="background-color: lightblue;width: 65px;word-break: break-all;">{!v.acc.Sales_Team__c}</p>
                                                </li>
                                            </ul>
                                        </aura:if>
                                    </li>
                                    <li>
                                        <p class="slds-text-heading--medium"  style="background-color: yellow;width: 65px;word-break: break-all;">Sales Project Manager</p>
                                        <aura:if isTrue="{!not(empty(v.acc.SalesManager__c))}">
                                            <ul>
                                                <li class="test">
                                                    <p class="slds-text-heading--medium" style="background-color: lightblue;width: 65px;word-break: break-all;">{!v.acc.SalesManager__c}</p>
                                                </li>
                                            </ul>
                                        </aura:if>
                                    </li>
                                    
                                </ul>
                            </li>
                        </ul>
                    </aura:if>
                </div>
            </body>
        </div>
        
    </lightning:layout>
    
    <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
    
    <div class="tree11" >
        <body>
            <a style="background-color: lightgreen;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Account</a>
            <img src="{!$Resource.Capture1}" style="margin-left: 126px;margin-top: -43px;width: 80px;margin-left: 0px;height: 38px;margin-top: -10px;border: 2px solid aliceblue;border-radius: 14px;"/>
            
            <ul>
                <li>
                    <a  style="background-color: yellow;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact1</a>
                    <ul>
                        <li>
                            <a  style="background-color: lightblue;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;"> {!v.acc.Company_Head__c}</a>
                        </li>
                    </ul>
                </li>
                <li>
                    <a style="background-color: yellow;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact2</a>
                    <ul>
                        <li>
                            <a style="background-color: lightblue;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;"> {!v.acc.Director__c}</a>
                        </li>
                    </ul>
                </li>
                <li>
                    <a style="background-color: yellow;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact3</a>
                    <ul>
                        <li>
                            <a style="background-color: lightblue;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;"> {!v.acc.HR_Team__c}</a>
                        </li>
                    </ul>
                </li>
                
                <li>
                    <a  style="background-color: yellow;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact4</a>
                    <ul>
                        <li>
                            <a  style="background-color: lightblue;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact5</a>
                            <ul>
                                <li>
                                    <a  style="background-color: lightgray;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact6</a><!--{!v.keyResult.Team_Manager1__c}-->
                                </li>
                                <li>
                                    <a  style="background-color: lightgray;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact7</a>
                                </li>
                                <li>
                                    <a style="background-color: lightgray;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact8</a>
                                </li>
                                <li>
                                    <a style="background-color: lightgray;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact9</a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li>
                    <a style="background-color: yellow;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Project Manager2</a>
                    <ul>
                        <li>
                            <a  style="background-color: lightblue;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;"> {!v.acc.Manager2__c}</a>
                            <ul>
                                <li>
                                    <a  style="background-color: lightgray;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Yeshwanth</a><!--{!v.keyResult.Team_Manager2__c}-->
                                </li>
                                <li>
                                    <a  style="background-color: lightgray;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Sai</a>
                                </li>
                                
                            </ul>
                        </li>
                    </ul>
                </li>
                <li>
                    
                    <a   style="background-color: yellow;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Sales Department</a>
                    <ul>
                        <li>
                            <a  style="background-color: lightblue;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Ila, Nikhil</a>
                        </li>
                    </ul>
                </li>
                <li>
                    <a  style="background-color: yellow;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Sales Project Manager</a>
                    <ul>
                        <li>
                            <a style="background-color: lightblue;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Haider</a>
                        </li>
                    </ul>
                </li>
                
            </ul>
        </body>
    </div>
    
</aura:component>

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

J.s code

({
    doInit: function (component, event, helper) {
        var action= component.get("c.getaccountData");
        action.setParams({
            recId: component.get("v.recordId")
        });
        action.setCallback(this, function(res) {
            var state=res.getState();
            var r = res.getReturnValue();
            if(state==="SUCCESS"){
                component.set("v.acc", r);
            }
        });
     $A.enqueueAction(action);              
    },
   
    recordUpdate: function (component, event, helper) {
        var accountFields = component.get("v.keyResult");
        var items = [{
            "label": "Department Of Proseraa",
            "name": "1",
            "expanded": true,
            "items": [{
                "label": "CEO",
                "name": "2",
                "expanded": true,
                "items" :[{
                    "label": accountFields.Company_Head__c,
                    "name": "3",
                    "expanded": true,
                }]
            },{
                "label": "Director",
                "name": "4",
                "expanded": true,
                "items" :[{
                    "label": accountFields.Director__c,
                    "name": "3",
                    "expanded": true,
                }]
            },{
                "label": "HR Team",
                "name": "5",
                "expanded": true,
                "items" :[{
                    "label": accountFields.HR_Team__c,
                    "name": "3",
                    "expanded": true,
                }]
            },{
                "label": "Project Manager",
                "name": "6",
                "expanded": true,
                "items" :[{
                    "label": accountFields.Manager1__c,
                    "name": "7",
                    "expanded": true,
                    "items" :[{
                        "label": accountFields.Team_Manager1__c,
                        "name": "8",
                        "expanded": true,
                    }]
                },{
                    "label":  accountFields.Manager2__c,
                    "name": "9",
                    "expanded": true,
                   
                    "items" :[{
                        "label": accountFields.Team_Manager2__c,
                        "name": "10",
                        "expanded": true,
                        'tag': 'button',
                    }]
                }]
            }],
           
           
        }];
        component.set('v.items', items);
    },
})

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

css


.THIS .tree ul {
    padding-top: 20px; position: relative;
    transition: all 0.5s;
}


.THIS .tree li {
    float: left; text-align: center;
    list-style-type: none;
    position: relative;
    padding: 40px 0px 0 3px;
   
    transition: all 0.5s;
    margin-left: -1px;
}

.THIS .tree li::before, .THIS .tree li::after{
    content: '';
    position: absolute; top: 0; right: 50%;
    border-top: 2px solid blue;
    width: 55%; height: 40px;
}

.THIS .tree li::after{
    right: auto; left: 50%;
    border-left: 2px solid blue;
}



/*We need to remove left-right connectors from elements without
any siblings*/
.THIS .tree li:only-child::after, .THIS .tree li:only-child::before {
    display: none;
}

/*Remove space from the top of single children*/
.THIS .tree li:only-child{ padding-top: 0;}

/*Remove left connector from first child and
right connector from last child*/
.THIS .tree li:first-child::before, .THIS .tree li:last-child::after{
    border: 0 none;
}
/*Adding back the vertical connector to the last nodes*/
.THIS .tree li:last-child::before{
    border-right: 2px solid blue;
    border-radius: 0 5px 0 0;}
.THIS .tree li:first-child::after{
    border-radius: 10px 0 0 0;
}

/*Time to add downward connectors from parents*/
.THIS .tree ul ul::before{
    content: '';
    position: absolute; top: 0; left: 49%;
    border-left: 3px solid blue;
    width: 0; height: 20px;
}

.THIS .test{
    position: absolute; top: 0;
}

.THIS .bg1{
    background-color: lightgreen;
}


.THIS .tree ul ul:empty::before{
    display: none;
}
.THIS .tree li p{
    border: 1px solid red;
    padding: 5px 10px;
    text-decoration: none;
    color: #666;
    font-family: arial, verdana, tahoma;
    font-size: 10px;
    display: inline-block;
    border-radius: 5px;
    transition: all 0.5s;
    border-right: 2px solid red;
}

/*Time for some hover effects*/
/*We will apply the hover effect the the lineage of the element also*/
.THIS .tree li p:hover, .THIS .tree li p:hover+ul li p {
    background: #c8e4f8; color: #000; border: 1px solid #94a0b4;
}
/*Connector styles on hover*/
.THIS .tree li p:hover+ul li::after,
.THIS .tree li p:hover+ul li::before,
.THIS .tree li p:hover+ul::before,
.THIS .tree li p:hover+ul ul::before{
    border-color:  #94a0b4;
}

.THIS.tree11{
    margin:0 auto;
    width: 100%;
}

.THIS.tree11 ul{
    padding: 10px 5px 0 5px;
    position: relative;
    z-index: 1;
}


.THIS.tree11 li{
    margin-left: 28px;
    list-style-type: none;
    position: relative;
    padding: 5px 5px 0 5px;
}

.THIS.tree11 li::after{
    content: '';
    position: absolute;
    border-bottom: 3px solid #c61f1f;
    border-left: 3px solid #c61f1f;
    height: 33px;
    width: 15px;
    right: auto;
    left: -10px;
    top: -11px;
    padding: -2px 10px;
    border-radius:2px;
}

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

<aura:application extends="Force:slds">
    <c:TreePicture />
</aura:application>


 
Hello Everyone

I am trying to write single Test class for both Handler class and Trigger, i have written a Test class but i am not able to cover the code coverage, 
any help or suggestion will help a lot

QuotaTriggerHandler
 
public class QuotaTriggerHandler {
    
    public static set<Id> assignedtoSet =new Set<Id>();
    public static set<String> QuaterString =new Set<String>();
    public static set<String> YearString =new Set<String>();
    
    public static final string Quater_1='Q1';
    public static final string Quater_2='Q2';
    public static final string Quater_3='Q3';
    public static final string Quater_4='Q4'; 
    
    public static final string Jan='Jan';
    public static final string Feb='Feb';
    public static final string Mar='Mar';
    public static final string Apr='Apr';
    public static final string May='May';
    public static final string Jun='Jun';
    public static final string Jul='Jul';
    public static final string Aug='Aug';
    public static final string Sep='Sep';
    public static final string Oct='Oct';
    public static final string Nov='Nov';
    public static final string Dec='Dec';
    
    public static final string Null_String='null';
    public static final Integer Integr_Null_String=null;
    
    public static void dupQuotaError (List <Quota__c> newTrigQuo) {
        
        Id recordTypeId = Schema.SObjectType.Quota__c.getRecordTypeInfosByName().get('IS Executive').getRecordTypeId();
        
        //List of all Quota Records with Recordtpe inside sales target currently in the database    
        List <Quota__c> allQuo = [SELECT ID, Name, Assigned_To__c, Quater_Year__c, RecordTypeId, Month__c FROM Quota__c where RecordTypeId=:recordTypeId];
        
        //Iterate through new potential records
        for (Quota__c oneQuoTrig : newTrigQuo) {
            
            //Needed to iterate through all existing records which is contained in the allCon List
            for (Integer i = 0; i < allQuo.size(); i++)
                
                //If all conditions are met, there is a duplicate and thus, returns an error.
                if (oneQuoTrig.Assigned_To__c == allQuo[i].Assigned_To__c 
                    && oneQuoTrig.Quater_Year__c == allQuo[i].Quater_Year__c 
                    && oneQuoTrig.Month__c == allQuo[i].Month__c
                    && oneQuoTrig.RecordTypeId == recordTypeId) {
                        oneQuoTrig.addError('Duplicate Quota Detected! This record already exists.');
                    }
        }      
    }
    public static void UpdateDate(List<Quota__c> quotaList){
        for(Quota__c q: quotaList){
            
            string year = q.Quater_Year__c;
            Date dt= System.today();
            Integer day = 1;
            Integer Month= dt.month();
            Date Startday;  
            
            if(q.Quater__c==Quater_1){
                Month=1;
            }else if(q.Quater__c==Quater_2){
                Month=4;
            }else if(q.Quater__c==Quater_3){
                Month=7;
            }else if(q.Quater__c==Quater_4){
                Month=10;
            }
            
            Integer IntMonth=Integr_Null_String;
            integer ConvertMonth=Integr_Null_String;
            integer ConvertYear=Integr_Null_String;
            
            if(Month==1){
                IntMonth=1;
            }else if(Month==4){
                IntMonth=4;
            }else if(Month==7){
                IntMonth=7;
            }else if(Month==10){
                IntMonth=10;
            }
            
            if(IntMonth!=Integr_Null_String){
                ConvertMonth=IntMonth;
            }else{
                ConvertMonth=null;
            }
            
            if(year!=Null_String){
                ConvertYear=integer.valueof(year);
            }else{
                ConvertYear=Integr_Null_String;
            }
            
            if(ConvertYear!=Integr_Null_String && q.Quater__c!=null){
                Startday= Date.newInstance(ConvertYear, ConvertMonth, day);
                q.End_Date__c =Startday+90;
            }else if(ConvertYear==Integr_Null_String || q.Quater__c==null){
                Startday=null;
                q.End_Date__c=null;
            }else {
                Startday=null;
                q.End_Date__c=null;
            }
            q.Start_Date__c=Startday;
            
        }
    }
    
    public static void dupRegionalError (List<Quota__c> newTrigQuo) {
        assignedtoSet =new Set<Id>();
        QuaterString =new Set<String>();
        YearString =new Set<String>();
        
        for(Quota__c q: newTrigQuo){
            if(q.Assigned_To__c!=null){
                assignedtoSet.add(q.Assigned_To__c);
            }
            
            if(q.Quater__c!=null){
                QuaterString.add(q.Quater__c);
            }
            if(q.Quater_Year__c!=null){
                YearString.add(q.Quater_Year__c);
            }
        }
        Id recordTypeId = Schema.SObjectType.Quota__c.getRecordTypeInfosByName().get('Field Sales Team Manager').getRecordTypeId(); 
        
        //List of all Quota Records with Recordtpe inside sales target currently in the database    
        List <Quota__c> allQuotaList = [SELECT ID, Name, Assigned_To__c,Quater_Year__c, RecordTypeId, Quater__c 
                                        FROM Quota__c where RecordTypeId=:recordTypeId AND Assigned_To__c IN:assignedtoSet
                                        AND Quater__c IN: QuaterString AND Quater_Year__c IN: YearString];
        //Iterate through new potential records
        if(allQuotaList!=null){
            for (Quota__c q : newTrigQuo) {
                //Needed to iterate through all existing records which is contained in the allCon List
                for (Integer i=0; i<allQuotaList.size(); i++){
                    q.addError('Duplicate Quota Detected! This record with same user and Same Quarter already exists.');
                }
            } 
        }
    }
    
    public static void Quotadupuser (List <Quota__c> dupTrigQuo){
        // Set to store email ids
        Set <String> Userset = new Set<String>(); 
        // Iterate through each Quota and add their Assigned to field to their respective Sets
        for (Quota__c Quo:dupTrigQuo) {
            Userset.add(Quo.Assigned_To__c);
        }
        // New list to store the found Assigned to field
        List <Quota__c> QuotaList = new List<Quota__c>();
        // Populating the list using SOQL
        QuotaList = [SELECT Assigned_To__c FROM Quota__c WHERE Assigned_To__c IN :Userset];
        // Iterating through each Quota record to see if the Assigned to was found
        for (Quota__c Quo:dupTrigQuo) {
            If (QuotaList.size() > 0) {
                // Displaying the error
                Quo.Assigned_To__c.adderror( 'Duplicate Assigned User Found. Please Assign a Different User.' );
            }
        }
    }   
}

My Trigger
 
trigger QuotaTrigger on Quota__c (before insert, before update,after insert,after update,before delete) {
    
    public List<Opportunity> userOppList = new List<Opportunity>(); 
    Map<Date,Date> startEndDate = new Map<Date,Date>();
    Set<Id> quotaUserIds = new Set<Id>();
    Map<Id,Quota__c> quotaMap = new Map<Id,Quota__c>();
    Map<String,Quota__c> afterquotaMap = new Map<String,Quota__c>();
    set<Id> assignedToIds = new Set<Id>();
    List<OpportunitySplit>  osList = new List<OpportunitySplit>();
    public Id fsRecordTypeId = Schema.SObjectType.Quota__c.getRecordTypeInfosByDeveloperName().get('Individual_Sales_Rep_Field_Sales').getRecordTypeId();
    public Id directorRecordTypeId = Schema.SObjectType.Quota__c.getRecordTypeInfosByDeveloperName().get('Regional_Head_Director_Sales_manager').getRecordTypeId();//9 March Maanas
    public Map<Id,Quota__c> assignedToQuotaMap = new Map<Id,Quota__c>();
    public Map<Id,Quota__c> directorQuotaMap = new Map<Id,Quota__c>();
    public Map<Id,List<Quota__c>> managerReporteeQuotaMap = new Map<Id,List<Quota__c>>();
    public List<Quota__c> quotaToUpdateManager = new List<Quota__c>();
    public Map<Quota__c,Id> reporteeManagerMap = new Map<Quota__c,Id>();
    public Map<Id,String> keyMap1 = new Map<Id,string>();
    Map<String,String> QauterDateMapping = new Map<String,String>{'Q1'=>'01/01/-03/31/','Q2' => '04/01/-06/30/',
        'Q3' => '07/01/-09/30/','Q4'=>'10/01/-12/31/'};
            
            String message = 'Error! Duplicate Quota Record For Individual Sales Rep / Field Sales (FS)';
    Set<String> newKeys = new Set<String>();   

    if(Trigger.IsInsert && Trigger.IsBefore){
        for(Quota__c qObj : Trigger.new) {
            //if(qObj.Assigned_To__c!=null){
            //QuotaHelper.getConvertedLeadCount_onQuota(Trigger.New, null);                 
            //}
            if(qObj.RecordTypeId == fsRecordTypeId || qObj.recordTypeId == directorRecordTypeId){
                String key = qObj.Assigned_To__c + qObj.Quater__c + qObj.Quater_Year__c;
                if (newKeys.contains(key)) qObj.addError(message);
                else newKeys.add(key);
            }
        }
        
        Set<String> existingKeys = new Set<String>();
        for (Quota__c q : [select Unique_Identifier_Per_Quater_Per_User__c from Quota__c WHERE Unique_Identifier_Per_Quater_Per_User__c IN :newKeys]) {
            existingKeys.add(q.Unique_Identifier_Per_Quater_Per_User__c);
        }
        
        for(Quota__c qqObj : Trigger.new) {
            if(qqObj.RecordTypeId == fsRecordTypeId){
                String key = qqObj.Assigned_To__c + qqObj.Quater__c + qqObj.Quater_Year__c;
                if (existingKeys.contains(key)) qqObj.addError(message);
            }
        } 
    }
    
    
    
    
    if(Trigger.IsInsert && Trigger.IsBefore){
        for(Quota__c singleQuota: Trigger.New){
            
            if(singleQuota.recordTypeId == fsRecordTypeId || singleQuota.recordTypeId == directorRecordTypeId){
                quotaUserIds.add(singleQuota.Assigned_To__c);
                quotaMap.put(singleQuota.Assigned_To__c,singleQuota);
                String quater =QauterDateMapping.get(singleQuota.Quater__c);
                List<String> QuaterDates = quater.split('-');
                String StartDate = QuaterDates[0];
                String EndDate = QuaterDates[1];
                String Year =singleQuota.Quater_Year__c;
                singleQuota.Start_Date__c = date.parse(StartDate+Year);
                singleQuota.End_Date__c =  date.parse(EndDate+Year);
                startEndDate.put(singleQuota.Start_Date__c,singleQuota.End_Date__c);  
                
                singleQuota.Name = singleQuota.Assigned_To_Owner__c + ' ' + singleQuota.Quater__c + ' ' + singleQuota.Quater_Year__c; 
                if(singleQuota.Unique_Identifier_Per_Quater_Per_User__c =='' || singleQuota.Unique_Identifier_Per_Quater_Per_User__c ==null)
                    singleQuota.Unique_Identifier_Per_Quater_Per_User__c = singleQuota.Assigned_To__c+singleQuota.Quater__c+singleQuota.Quater_Year__c;
                
            }
            
            if(singleQuota.recordTypeId == directorRecordTypeId){
                assignedToQuotaMap.put(singleQuota.Assigned_To__c,singleQuota);
            }    
            
        }   if(NULL !=startEndDate && startEndDate.size() > 0 ){
            for(OpportunitySplit os: [Select Id,Opportunity.Amount,SplitAmount,SplitOwnerId,Quota__c  FROM OpportunitySplit WHERE
                                      splitOwnerId IN :quotaUserIds AND
                                      Opportunity.CloseDate>= :startEndDate.keyset() AND Opportunity.CloseDate <= :startEndDate.values() 
                                      AND (Opportunity.StageName IN ('Live Won','Agreement Signed') AND Opportunity.Billing_To_Be_Initiated__c ='Yes')]){
                                          
                                          if(quotaMap.containskey(os.splitOwnerId)){
                                              system.debug(os.SplitAmount);
                                              system.debug(quotaMap.get(os.splitOwnerId).Inside_Sales_Roll_Up__c);
                                              if(quotaMap.get(os.splitOwnerId).Inside_Sales_Roll_Up__c == null){
                                                  quotaMap.get(os.splitOwnerId).Inside_Sales_Roll_Up__c = 0;
                                              }
                                              quotaMap.get(os.splitOwnerId).Inside_Sales_Roll_Up__c = quotaMap.get(os.splitOwnerId).Inside_Sales_Roll_Up__c  + (os.SplitAmount !=null ? os.SplitAmount: 0);
                                          }
                                          
                                          
                                      }
            
        }
        
        Map<String,String> tmpMap =new Map<String,String>();
        Map<String,String> reporteeManagerIds = new Map<String,String>();
        if(quotaUserIds != NULL && quotaUserIds.size() >0){
            for(User usrid : [Select Id,ManagerId from User WHERE Id IN:quotaUserIds]){
                if(usrid.ManagerId != null)
                    reporteeManagerIds.put(usrid.Id,usrid.ManagerId);
            }
            
            for(Quota__c qc : [SELECT Id,Quater__c,Quater_Year__c,Assigned_to__r.ManagerId FROM Quota__c WHERE Assigned_to__c IN : reporteeManagerIds.values()]){
                for(Id qId : quotaUserIds){
                    tmpMap.put(qId+qc.Quater__c+qc.Quater_Year__c,qc.Id);    
                }
                
            }
        }
        system.debug('tmpMap::'+ tmpMap);
        if(tmpMap != null && tmpMap.size() > 0){
            for(Quota__c q: trigger.new){
                if(tmpMap.containskey(q.Assigned_To__c + q.Quater__c + q.Quater_Year__c)){
                    q.Manager_Quota__c = tmpMap.get(q.Assigned_To__c + q.Quater__c + q.Quater_Year__c);
                    system.debug(q.Manager_Quota__c);
                }
            }
        }
        
      
        
        if(NULL != assignedToQuotaMap && assignedToQuotaMap.size() >0){
            for (aggregateResult result: [Select Assigned_To__r.managerid,quater__c,quater_year__c, 
                                          Sum(Inside_Sales_Roll_Up__c) FROM Quota__c WHERE Assigned_To__r.ManagerID IN:assignedToQuotaMap.keyset() /* AND 
Assigned_To__r.Quotas_role__c='Individual Sales Rep / Field Sales (FS)'*/ Group BY assigned_To__r.ManagerID,quater__c,quater_year__c]) {
    system.debug(result);
    if(assignedToQuotaMap.containskey((Id)result.get('ManagerId')) &&
       assignedToQuotaMap.get((Id)result.get('ManagerId')).Quater__c == result.get('Quater__c') &&
       assignedToQuotaMap.get((Id)result.get('ManagerId')).Quater_Year__c == result.get('Quater_Year__c')                                
      ){
          assignedToQuotaMap.get((Id)result.get('ManagerId')).Actual_Amount__c = (Decimal)result.get('expr0');
      }                           
    
}
        }
    }
    
    
    if(Trigger.IsInsert && Trigger.IsAfter){
        
        for(Quota__c q: trigger.new){
            if(q.RecordTypeId == fsRecordTypeId){
                afterquotaMap.put(String.ValueOf(q.assigned_to__c) + q.Quater__c+'-' + q.Quater_Year__c,q);
                assignedToIds.add(q.Assigned_To__c);
            }
            
            if(q.RecordTypeId == directorRecordTypeId){
                directorQuotaMap.put(q.Assigned_to__c,q);
            }
            
        }
        for(OpportunitySplit os: [SELECT Id,QuaterYear__c ,SplitOWnerId FROM opportunitySplit WHERE SplitOWnerId IN:assignedToIds]){
            if(afterquotaMap.containskey(String.ValueOf(os.SplitOwnerId)+ os.QuaterYear__c)){
                os.Quota__c = afterquotaMap.get(os.SplitOwnerId+ os.QuaterYear__c).Id;
                osList.add(os);
            }
        }
        
        if(NULL != osList && osList.size() > 0){
            update osList;
        }
        
        if(NULL != directorQuotaMap && directorQuotaMap.size() >0){
            system.debug('directorQuotaMap'+directorQuotaMap.size());
            
            for(Quota__c childQuota :[SELECT Id,Quater__c,Quater_Year__c,Assigned_to__c,Assigned_To__r.ManagerID, Manager_Quota__c FROM Quota__c WHERE Assigned_To__r.ManagerID IN:directorQuotaMap.keyset() AND RecordTypeId=:fsRecordTypeId ]){
                if(directorQuotaMap.containskey(childQuota.Assigned_To__r.ManagerID)){
                    if( childQuota.Quater__c == directorQuotaMap.get(childQuota.Assigned_to__r.ManagerID).Quater__c && childQuota.Quater_Year__c == directorQuotaMap.get(childQuota.Assigned_to__r.ManagerID).Quater_Year__c ){
                        childQuota.Manager_Quota__c = directorQuotaMap.get(childQuota.Assigned_to__r.ManagerID).Id;
                        quotaToUpdateManager.add(childQuota);
                        
                    }   
                } 
            }
        }
        
        if(null != quotaToUpdateManager && quotaToUpdateManager.size()> 0)
            update quotaToUpdateManager;
    }    
    
    
    if(Trigger.IsUpdate && Trigger.IsBefore){
        for(Quota__c qObj : trigger.new){
            if(qObj.Quater__c != trigger.oldMap.get(qObj.Id).Quater__c || qObj.Quater_Year__c != trigger.oldMap.get(qObj.Id).Quater_Year__c)
                qObj.addError('Error: Cannot Change Quarter/Quarter Year For User Once Created. Please Create A New Quota');
        } 
    }
    
    
    if(Trigger.IsUpdate && Trigger.IsBefore){
        for(Quota__c qObj : trigger.new){
            if(qObj.Month__c != trigger.oldMap.get(qObj.Id).Month__c || qObj.Assigned_To__c != trigger.oldMap.get(qObj.Id).Assigned_To__c)
                qObj.addError('Error: Cannot Change Month and Assigned to For User Once Created and Saved. Please Create A Different Quota Record');
        }
    }
    
    
    if(trigger.isBefore && trigger.isInsert){
        QuotaTriggerHandler.dupQuotaError(Trigger.new);
    }

    
    if(Trigger.isBefore){
        if(Trigger.isInsert){
            for(Quota__c q: Trigger.New){
                QuotaTriggerHandler.UpdateDate(Trigger.new);
            }
        }
        if(Trigger.isUpdate){
            for(Quota__c q: Trigger.New){
                Quota__c qold =Trigger.OldMap.get(q.Id);
                if(q.Quater_Year__c!= qold.Quater_Year__c || q.Quater__c!= qold.Quater_Year__c){
                    QuotaTriggerHandler.UpdateDate(Trigger.new);
                }
            }
        }
    }
    if(trigger.isBefore && trigger.isInsert){
        QuotaTriggerHandler.dupRegionalError(Trigger.new);
    }
    
    if(trigger.isAfter && (trigger.isInsert || trigger.isUpdate) ){
        Set<Id> ManagerQuota = new Set<Id>();
        for(Quota__c q : trigger.new){
            if(trigger.isInsert){
                if(q.Manager_Quota__c != null ){
                    ManagerQuota.add(q.Manager_Quota__c);
                }
            }else if(Trigger.isUpdate){
                if(q.Inside_Sales_Roll_Up__c != trigger.oldMap.get(q.Id).Inside_Sales_Roll_Up__c){
                    ManagerQuota.add(q.Manager_Quota__c);
                }
            }
        }
        List<Quota__c> finalQuota = new List<Quota__c>();
        if(ManagerQuota != null && ManagerQuota.size() > 0){
            for (aggregateResult result: [Select Manager_Quota__c, 
                                          Sum(Inside_Sales_Roll_Up__c) FROM Quota__c WHERE Manager_Quota__c IN: ManagerQuota GROUP BY Manager_Quota__c]) {
                                              if(result.get('Manager_Quota__c') != null)
                                                  finalQuota.add(new Quota__c(Id=(Id)result.get('Manager_Quota__c') ,Actual_Amount__c =(Decimal)result.get('expr0')));
                                              
                                          }
        }
        
        if(finalQuota.size () >0){
            update finalQuota;
            
        }
    }
    
    if(Trigger.isDelete && Trigger.isBefore){
        Map<Id,Decimal> finalQuotaAmount = new Map<Id,Decimal>();
        for(Quota__c q: trigger.old){
            if(q.Manager_Quota__c !=NULL){
                Decimal val =0.0;
                if(finalQuotaAmount.containskey(q.Manager_Quota__c)){
                    val = finalQuotaAmount.get(q.Manager_Quota__c) + q.Inside_Sales_Roll_Up__c !=null ? q.Inside_Sales_Roll_Up__c: 0;
                    finalQuotaAmount.put(q.Manager_Quota__c,val);
                }
                else{
                    finalQuotaAmount.put(q.Manager_Quota__c,q.Inside_Sales_Roll_Up__c != null? q.Inside_Sales_Roll_Up__c: 0 );
                }
            }
        }
        
        system.debug('finalQuotaAmount::'+ finalQuotaAmount);
        List<Quota__c> final1Quota = new List<Quota__c>();
        if(finalQuotaAmount != null && finalQuotaAmount.size() > 0){
            for (aggregateResult result: [Select Manager_Quota__c, 
                                          Sum(Inside_Sales_Roll_Up__c) FROM Quota__c WHERE Manager_Quota__c IN: finalQuotaAmount.keyset() GROUP BY Manager_Quota__c]) {
                                              
                                              final1Quota.add(new Quota__c(Id=(Id)result.get('Manager_Quota__c'),Actual_Amount__c =(Decimal)result.get('expr0') - finalQuotaAmount.get((Id)result.get('Manager_Quota__c'))));
                                          }
        }
        
        if(final1Quota.size () >0){
            update final1Quota;
            
        }
        
        
    }
}

My Test Class
 
@isTest
public class QuotaTriggerHandlerTest {
    
    public static String user(){
        User u = [Select id,name from user where isactive=true Limit 1];
        System.debug('u' + u.id);
        return u.id;
    }
    
    
    static testmethod void Duplication(){
        
        List<Quota__c> Quotas = new list <Quota__c>();
        Id RecordTypeIdQuota = schema.SObjectType.Quota__c.getRecordTypeInfosByName().get('IS Executive').getRecordTypeId(); 
        
        // insert First Quota  
        Quota__c Quo = new Quota__c(); 
        Quo.Name='Julian';
        Quo.Assigned_To__c = user();
        Quo.Month__c='March';  
        Quo.Quater_Year__c = '2020';
        Quo.Unique_Identifier_Per_Quater_Per_User__c = 'Hello';
        Quo.recordtypeid=RecordTypeIdQuota;
        Quotas.add(Quo);
        insert Quo;
        System.debug(' First Quota  inserted...and Id is .....'+Quo.Id);
         
        
        if(Quo.id!=NULL){
            Quota__c Quo1=new Quota__c();
            Quo1.Name='Testing';
            Quo1.Assigned_To__c = user();
            Quo1.Unique_Identifier_Per_Quater_Per_User__c = 'Second Quota inserted';
            Quo1.Month__c = 'march';
            Quo1.Quater_Year__c = '2020';
            Quo1.recordtypeid=RecordTypeIdQuota;
            System.debug(' Scecond Quote  inserted...and Id is .....'+Quo1.Id);
            try{
                insert Quo1;
            }
            catch(Exception ex){
                Boolean expectedExceptionThrown =  ex.getMessage().contains('Duplicate Quota Error! This record already exists.') ? true : false;
                System.debug('Error message is '+ex.getMessage());
            }
            
        }
        
    }
    static testmethod void Quateryear(){
        List<Quota__c> Quotas = new list <Quota__c>();
        
        Id RecordTypeIdQuota1 = schema.SObjectType.Quota__c.getRecordTypeInfosByName().get('Field Sales Team Manager').getRecordTypeId();
        Quota__c qt = new Quota__c();
        qt.Name = 'test';
        qt.Quater_Year__c = '2020';
        qt.Quater__c = 'Q1';
        qt.Assigned_To__c = user();
        qt.Unique_Identifier_Per_Quater_Per_User__c = 'Third Quota inserted';
        qt.RecordTypeId = RecordTypeIdQuota1;
        Quotas.add(qt);
        
        Quota__c qt1 = new Quota__c();
        qt1.Name = 'test';
        qt1.Quater_Year__c = '2020';
        qt1.Quater__c = 'Q2';
        qt1.Assigned_To__c = user();
        qt1.Unique_Identifier_Per_Quater_Per_User__c = 'fourth Quota inserted';
        qt1.RecordTypeId = RecordTypeIdQuota1;
        Quotas.add(qt1);
        
        Quota__c qt2 = new Quota__c();
        qt2.Name = 'test';
        qt2.Quater_Year__c = '2020';
        qt2.Quater__c = 'Q3';
        qt2.Assigned_To__c = user();
        qt2.Unique_Identifier_Per_Quater_Per_User__c = 'fifth Quota inserted';
        qt2.RecordTypeId = RecordTypeIdQuota1;
        Quotas.add(qt2);
        
        Quota__c qt3 = new Quota__c();
        qt3.Name = 'test';
        qt3.Quater_Year__c = '2020';
        qt3.Quater__c = 'Q4';
        qt3.Unique_Identifier_Per_Quater_Per_User__c = 'Sixth Quota inserted';
        qt3.RecordTypeId = RecordTypeIdQuota1;
        Quotas.add(qt3);
        
        insert Quotas;
        
        Quota__c qtr = new Quota__c();
        qtr.Name = 'test';
        qtr.Quater_Year__c = '2020';
        qtr.Quater__c = 'Q1';
        qtr.Assigned_To__c = User();
        qtr.Unique_Identifier_Per_Quater_Per_User__c = 'seventh Quota inserted';
        qtr.RecordTypeId = RecordTypeIdQuota1; 
        
        try{
            insert qtr;
            update qtr;
        }
        catch(Exception ex){
            Boolean expectedExceptionThrown =  ex.getMessage().contains('Duplicate Quota Detected! This record with same user and Same Quarter already exists.') ? true : false;
            System.debug('Error message is '+ex.getMessage());
        }
    }    
}

​​​​​​​​​​​​​​
Hello Developers

I want to design a batch apex where it should fire an email on daily basis, and i have designed a visualforce component and controller with vf email templates where it sends reports with csv attachments, How do i design a batch apex class where it can send the vf email templates on daily basis

This is my VF component
 
<apex:component controller="ReportsToEmailController" access="global">
    <apex:attribute name="ReportId" description="Report ID" type="Id" assignTo="{!rptId}"/>
    <apex:attribute name="Color" description="Background color" type="String" assignTo="{!rptId}"/>
    <apex:outputPanel >      
        
        <table style="width: 100%;">
            <thead style="background : {!Color}">                
                <apex:repeat value="{!ReportResult.reportMetadata.detailColumns}" var="colName">
                    
                    <!-- reportMetadata is a class where it contains metadata of a report.
DetailColumns is a method of ReportMetadata class, it returns the API names(Coloumns Names)
for the fields that contain detailed data-->
                    
                    <th><apex:outputText value="{!ReportResult.reportExtendedMetadata.detailColumnInfo[colName].label}"/></th>
                    
                    
                    <!-- reportExtendedMetadata is class where it contains Report extended metadata and
it provides data type and label information.
detailColumnInfo is a method of reportExtendedMetadata clas, it returns map of columns names
and its label to Display as Header -->
                    
                </apex:repeat>
                <!-- Grouped fieds in summary report to get in header -->
                <apex:repeat value="{!ReportResult.reportMetadata.groupingsDown}" var="colName">
                    <th><apex:outputText value="{!colName.name}"/></th>
                </apex:repeat>
            </thead>
            <tbody>
                
                <!-- Summary Report with 2 level of grouping -->
                <apex:repeat value="{!ReportResult.groupingsDown.groupings}" var="groupingLevel1" >
                    <apex:repeat value="{!groupingLevel1.groupings}" var="groupingLevel2" >
                        <apex:repeat value="{!ReportResult.factMap[groupingLevel2.key+'!T'].rows}" var="row" rows="999">
                            <!-- Here we will get entire data of each row and T refers to the Row -->
                            <tr> <apex:repeat value="{!row.dataCells}" var="cell">
                                <!-- Here we will get data of each cell and displayed -->
                                <td><apex:outputText value="{!cell.label}"/></td>
                                </apex:repeat><td>{!groupingLevel1.label}</td><td>{!groupingLevel2.label}</td> </tr>
                        </apex:repeat>
                    </apex:repeat>
                </apex:repeat>
                
                <!-- Summary Report with 1 level of grouping -->
                <apex:repeat value="{!ReportResult.groupingsDown.groupings}" var="grouping" >
                    <apex:repeat value="{!ReportResult.factMap[grouping.key+'!T'].rows}" var="row" rows="999">
                        <!-- Here we will get entire data of each row and T refers to the Row -->
                        <tr> <apex:repeat value="{!row.dataCells}" var="cell">
                            <!-- Here we will get data of each cell and displayed -->
                            <td><apex:outputText value="{!cell.label}"/></td>
                            </apex:repeat><td>{!grouping.label}</td> </tr>
                    </apex:repeat>
                </apex:repeat>
                
                <!-- Tabular Report -->
                <apex:repeat value="{!ReportResult.factMap['T!T'].rows}" var="row" rows="999">
                    <!-- Here we will get entire data of each row and T refers to the Row -->
                    <tr> <apex:repeat value="{!row.dataCells}" var="cell">
                        <!-- Here we will get data of each cell and displayed -->
                        <td><apex:outputText value="{!cell.label}"/></td>
                        </apex:repeat></tr>
                </apex:repeat>
                <!--</apex:repeat>-->
            </tbody>
        </table>
    </apex:outputPanel>
</apex:component>

apex controller
 
public class ReportsToEmailController {
    public Id rptId { get; set; } // Here we will get the report Id from the VF Component
    private transient Reports.ReportResults results; // It will hold the entire data of a report
 
    /*********************
     // Method Name : getReportResult
     // Description : Here we will get the data of a report and send to the VF Component
    /********************/
 
    public Reports.ReportResults getReportResult() {
        // Here it will run the report with that report ID and adding the report data into results
        results = Reports.ReportManager.runReport(rptId, true);
        return results;
    }
}

Vf template
 
<messaging:emailTemplate subject="Report" recipientType="User" >
    <messaging:plainTextEmailBody >
        Hi {!recipient.FirstName}
        Please find the below attachments. 
 
    </messaging:plainTextEmailBody>
    <messaging:attachment filename="Account Report.xls">
        <!-- Here we can add multiple Reports -->
        <c:ReportsToEmail ReportId="00O2w000002RDbUEAW"/>
        <c:ReportsToEmail ReportId="00O2w000002Rp56EAC"/>
    </messaging:attachment>
</messaging:emailTemplate>

Can someone help me with the batch apex
Hello Developers

My Requirement is that Reports must be sent through email with csv attachments, i have refered several blogs,

Basically Report needs to go in email with csv format, i have designed a apex class, but i dont know how to excute it in ananomus window
 
global class sendreport implements System.Schedulable {
    global void execute(SchedulableContext sc) {
        ApexPages.PageReference report = new ApexPages.PageReference('00O2w000002RDbUEAW'); //this id of the report
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        attachment.setFileName('report.xls');
        attachment.setBody(report.getContent());
        attachment.setContentType('text/csv');
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setSubject('Report');
        message.setPlainTextBody('The report is attached.');
        message.setToAddresses( new String[] { 'manjunath.s@proseraa.com' } );
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
        
    }
 }
Any help please?

 
i have  designed a apex class on custom object where it checks the duplicate value for Specific recordtype, it is invoked by a trigger handler, i am getting this error - 

QuotaTrigger: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Class.QuotaTriggerHandler.dupQuotaError: line 5, column 1 Trigger.QuotaTrigger: line 3, column 1

I tried Googling the error but still   not able to Resolve the error, Any suggestions please

QuotaTrigger
 
trigger QuotaTrigger on Quota__c (before insert, before update) {

    QuotaTriggerHandler.dupQuotaError(Trigger.new);
    
}

QuotaTriggerHandler
 
public class QuotaTriggerHandler {
    
    public static void dupQuotaError (List <Quota__c> newTrigCon) {
        
        Id recordTypeId = Schema.SObjectType.Quota__c.getRecordTypeInfosByDeveloperName().get('Inside Sales Target(IS)').getRecordTypeId();
        
        //List of all Contact Records currently in the database    
        List <Quota__c> allCon = [SELECT ID, Name, Assignedto__c, Quater_Year__c, RecordTypeId, Month__c FROM Quota__c where RecordTypeId=:recordTypeId];
        
        //Iterate through new potential records
        for (Quota__c oneConTrig : newTrigCon) {
            
            //Needed to iterate through all existing records which is contained in the allCon List
            for (Integer i = 0; i < allCon.size(); i++)
                
                //If all conditions are met, there is a duplicate and thus, returns an error.
                if (oneContrig.Assignedto__c == allCon[i].Assignedto__c 
                    && oneContrig.Quater_Year__c == allCon[i].Quater_Year__c 
                    && oneConTrig.Month__c == allCon[i].Month__c
                    && oneConTrig.RecordTypeId == recordTypeId) {
                        
                        oneConTrig.addError('Duplicate Quota Detected! This record already exists.');
                        
                    }
        }      
    }
}

How do i resove this issue
Hello Developers 

I am new to the Apex Development, we have multiple triggers on a Opportunity, So i have been Given a Task to create a OpportunityHelper Class where all the Logic has to be Implemented in a Single Class, i am getting some errors where i am not able to resolve it

This is my below Trigger Logic
 
trigger opportunityTrigger on Opportunity (after delete,after update,after insert,after undelete) {
   
    set<ID>QtaIds = new set<ID>(); 
    if(trigger.isinsert || trigger.isundelete){
        for(opportunity opp : trigger.new){
            QtaIds.add(opp.Quota__c);
        }
    }  
    if(trigger.isdelete){
        for(opportunity opp : trigger.old){
            QtaIds.add(opp.Quota__c);           
        }        
    }
    if(trigger.isupdate){
        for(opportunity opp:trigger.new){
            QtaIds.add(opp.Quota__c);
            if(trigger.oldmap.get(opp.id).Quota__c != opp.Quota__c && trigger.oldmap.get(opp.id).Quota__c != null ){
                QtaIds.add(trigger.oldmap.get(opp.id).Quota__c);
            }            
        }
    }    
    map<id,double> amtmap = new map<id,double>();
    for(aggregateresult ag : [SELECT SUM(Amount) sum,Quota__c FROM Opportunity where Quota__c in :QtaIds and ClosedDate_Checkbox__c ='True' and StageName = 'Closed Won' group by Quota__c ]){
        amtmap.put((ID)ag.get('Quota__c'), double.valueof(ag.get('SUM')));
    }
    list<Quota__c>Qtalist = new list<Quota__c>();
    for(id iid : QtaIds){
        Quota__c quot = new Quota__c(id=iid); 
        if(amtmap.containskey(iid)){
            quot.Inside_Sales_Roll_up__c = amtmap.get(iid);
        }else{
            quot.Inside_Sales_Roll_up__c = 0;
        } 
        Qtalist.add(quot);       
    } 
    if(Qtalist.size()>0){
        update Qtalist;
    }
}

Below is My OpportunityTrigger
 
trigger OpportunityTrigger on Opportunity (after insert,after update) {
    
    IF(Trigger.isafter && Trigger.isupdate){ 
        OpportunityHelper.MMCountRollUpAmount();
     }
    
}

This is My OpportunityHelper
 
public class OpportunityHelper {
    
    public static Map<Id, Quota__c> QuotaMap =new Map<Id, Quota__c>();
    public static Map<String, List<Opportunity>> OpportunityListMap = new Map<String, List<Opportunity>>();
    public static set<ID>QtaIds = new set<ID>(); 
    
    public static void MMCountRollUpAmount(set<id> QuotaIdSet){
        set<ID>QtaIds = new set<ID>(); 
        if(trigger.isinsert || trigger.isundelete){
            for(opportunity opp : trigger.new){
                QtaIds.add(opp.Quota__c);
            }
        }  
        if(trigger.isdelete){
            for(opportunity opp : trigger.old){
                QtaIds.add(opp.Quota__c);           
            }        
        }
        if(trigger.isupdate){
            for(opportunity opp:trigger.new){
                QtaIds.add(opp.Quota__c);
                if(trigger.oldmap.get(opp.id).Quota__c != opp.Quota__c && trigger.oldmap.get(opp.id).Quota__c != null ){
                    QtaIds.add(trigger.oldmap.get(opp.id).Quota__c);
                }            
            }
        }    
        map<id,double> amtmap = new map<id,double>();
        for(aggregateresult ag : [SELECT SUM(Amount) sum,Quota__c FROM Opportunity where Quota__c in :QtaIds and Closed_Date_Checkbox__c ='True' AND StageName = 'Closed Won' group by Quota__c ]){
            amtmap.put((ID)ag.get('Quota__c'), double.valueof(ag.get('SUM')));
        }
        list<Quota__c>Qtalist = new list<Quota__c>();
        for(id iid : QtaIds){
            Quota__c quot = new Quota__c(id=iid); 
            if(amtmap.containskey(iid)){
                quot.Inside_Sales_Roll_up__c = amtmap.get(iid);
            }else{
                quot.Inside_Sales_Roll_up__c = 0;
            } 
            Qtalist.add(quot);       
        } 
        if(Qtalist.size()>0){
            update Qtalist;
        }
    }
}

TT​​​​​​​
Hello Everyone

I am new to the Apex development, i have Developed a Trigger where a custom field is updated based on the Formula field(Region), i have designed a trigger and its working perfectly, but the thing is i have written 5 seperate SOQL queries, so when i save a record it queries 5 times, How do i bulkify the trigger, so that it should query only once

Any Help will be Appricated

trigger Increment on Lead (before insert,Before Update) {
    if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate || Trigger.IsUnDelete))  {
        List<Lead> leadList = [Select Id,PraticeLWC__Lead_No_Region_IN__c From Lead Where PraticeLWC__Region__c = 'India'];
        For(Lead l : trigger.New ) {
            if(l.PraticeLWC__Region__c == 'India') {
                if(leadList.size() > 0){
                    l.PraticeLWC__Lead_No_Region_IN__c = leadList.size()+0;
                } else {
                    l.PraticeLWC__Lead_No_Region_IN__c = 1;
                }
            }
        }
        List<Lead> leadListt = [Select Id,PraticeLWC__Lead_No_Region_USA__c From Lead Where PraticeLWC__Region__c = 'US'];
        For(Lead m : trigger.New) {
            if(m.PraticeLWC__Region__c == 'US') {
                if(leadListt.size() > 0){
                    m.PraticeLWC__Lead_No_Region_USA__c = leadListt.size()+0;   
                } else {
                    m.PraticeLWC__Lead_No_Region_USA__c = 1;
                }
            }
        } 
        List<Lead> leadListm = [Select Id,PraticeLWC__Lead_No_Region_EU__c From Lead Where PraticeLWC__Region__c = 'EU'];
        For(Lead n : trigger.New) {
            if(n.PraticeLWC__Region__c == 'EU') {
                if(leadListm.size() > 0){
                    n.PraticeLWC__Lead_No_Region_EU__c = leadListm.size()+0;   
                } else {
                    n.PraticeLWC__Lead_No_Region_EU__c = 1;
                }
            }
        } 
        List<Lead> leadListo = [Select Id,PraticeLWC__Lead_No_Region_SEA__c From Lead Where PraticeLWC__Region__c = 'SEA'];
        For(Lead o : trigger.New) {
            if(o.PraticeLWC__Region__c == 'SEA') {
                if(leadListo.size() > 0){
                    o.PraticeLWC__Lead_No_Region_SEA__c = leadListo.size()+0;   
                } else {
                    o.PraticeLWC__Lead_No_Region_SEA__c = 1;
                }
            }
        }
        List<Lead> leadListp = [Select Id,PraticeLWC__Lead_No_Region_ME__c From Lead Where PraticeLWC__Region__c = 'ME'];
        For(Lead p : trigger.New) {
            if(p.PraticeLWC__Region__c == 'ME') {
                if(leadListp.size() > 0){
                    p.PraticeLWC__Lead_No_Region_ME__c = leadListp.size()+0;   
                } else {
                    p.PraticeLWC__Lead_No_Region_ME__c = 1;
                }
            }
        } 
        
    }                   
}
Hello Developers

I have been trying to write test class for the Below trigger, the Trigger basically syncs products from quote line items to opportunity line items, when custom checkbox is checked, i have designed a test class, but when i click run test, the code coverage shows 0, below is my trigger and tets class 

Trigger
 
trigger QuoteLineItemTrigger on Quotes__c (after insert, after update)
{
    
    Map<Id,Id> quoteIdToOppId =new Map<Id,Id>();
    Map<Id,List<QuoteLineitem__c>> quoteIdToLineItems = new Map<Id,List<QuoteLineitem__c>>();
    List<OpportunityLineItem__c> oppLineItems = new List<OpportunityLineItem__c>();
    Map<Id,String> oppIdtoName = new Map<Id,String>();
    
    for(Quotes__c q : trigger.new)
    {
        if(q.IsSyncing__c && q.IsSyncing__c  != Trigger.oldMap.get(q.Id).IsSyncing__c ) quoteIdToOppId.put(q.id, q.OpportunityId__c);
    }
    System.debug('UAC: quoteIdToOppId ' + quoteIdToOppId);
    
    for( QuoteLineitem__c qli :[SELECT Id, Product2Id__c,Product2Id__r.name,Quantity__c,ServiceDate__c, QuotesId__c,ListPrice__c,Line_Item_Description__c,Total_Price__c,Product2Id__r.Product_Code__c,UnitPrice__c  FROM QuoteLineitem__c WHERE QuotesId__c =:quoteIdToOppId.keyset() ])
    {
        List<QuoteLineitem__c> tempList = quoteIdToLineItems.get(qli.QuotesId__c) ;
        if(tempList == null)
        {
            
            templist = new List<QuoteLineitem__c>();
            quoteIdToLineItems.put(qli.QuotesId__c, templist);
           
        }
        tempList.add(qli);
    }
    System.debug('UAC: quoteIdToLineItems ' + quoteIdToLineItems);
    
    for(Opportunities__c opp : [SELECT Id , Name  FROM Opportunities__c WHERE ID IN :quoteIdToOppId.values()] )
    
    {
        oppIdtoName.put(opp.id, opp.Name)   ;
    }
    System.debug('UAC: oppIdtoName ' + quoteIdToLineItems);
    
    for(Quotes__c q : Trigger.new)
    {
        if(q.IsSyncing__c && quoteIdToLineItems.containsKey(q.Id))
        {
            for(QuoteLineitem__c qli : quoteIdToLineItems.get(q.Id))
            {
                OpportunityLineItem__c oli = new OpportunityLineItem__c();
                oli.OpportunityId__c = quoteIdToOppId.get(qli.QuotesId__c); 
                System.debug(' qli.Product2Id__r.name ' +  qli.Product2Id__r.name);
                oli.Name = qli.Product2Id__r.name;
                System.debug(' qli.Product2Id__c ' +  qli.Product2Id__c);
                System.debug(' qli.ListPrice__c ' +  qli.ListPrice__c);
                System.debug(' qli.Line_Item_Description__c ' +  qli.Line_Item_Description__c);
                oli.Product2Id__c = qli.Product2Id__c; 
                oli.Quantity__c = qli.Quantity__c; 
                oli.ListPrice__c = integer.valueof(qli.ListPrice__c); 
                oli.Description__c = qli.Line_Item_Description__c;
                oli.ServiceDate__c = qli.ServiceDate__c;
                oli.Total_Price__c = qli.Total_Price__c;
                oli.ProductCode__c = qli.Product2Id__r.Product_Code__c;
                oli.Sales_Price__c =qli.UnitPrice__c;
                oppLineItems.add(oli);
            }
            
        }
        System.debug('UAC: oppLineItems ' + oppLineItems);
        if(oppLineItems.size() > 0) insert oppLineItems ;
        
    }
}

My test Class

 
@isTest(SeeAllData=true)
public class QuoteLineItemTestClass {							
    
    
    private static void setUpData(){
        
        Opportunities__c opp = new Opportunities__c();
        opp.Name = 'Test Opp';
        opp.Stage__c = 'Prospecting';
        opp.Close_Date__c = Date.today();
        insert opp;
        
        Quotes__c Quo = new Quotes__c();
        Quo.Name = 'Test Quote';
        Quo.OpportunityId__c = opp.Id;
        Quo.AccountId__c = opp.Id;
        insert Quo;
        
        QuoteLineitem__c QLI = new QuoteLineitem__c();
        QLI.QuotesId__c = Quo.Id;
        QLI.Quantity__c = 1;
        QLI.Product2Id__c = Quo.Id;
        insert QLI;
        
        Product2__c P = new Product2__c();
        P.Name = 'Test record';
        P.Opportunities__c = opp.Id;
        insert P;
        
        PricebookEntry__c PBE = new PricebookEntry__c();
        PBE.Product2Id__c = p.Id;
        PBE.IsActive__c = true;
        insert PBE;
        
        Pricebook2__c pb = [select Id from Pricebook2__c where Is_Standard_Price_Book__c = true limit 1]; 
        
    }
    
    static testMethod void  basicTest() {
       
    QuoteLineitem qli = [Select Id,QuoteId From QuoteLineitem Limit 1];
        Test.startTest();
            Insert qli;
        Test.stopTest();                
    }
}
Hello all

I am New to the Aura Componets, i am trying to Build Tree Structure Pictorical Diagram where related contacts should show 
for Parent Account, any help would highly be appriated

User-added imageMy Code
Apex code

public class AccountTreeMapClass {

   @AuraEnabled
   public static account getaccountData(string recId){
       return [select id, name, Company_Head__c,Sales_Team__c,SalesManager__c,Department__c,Director__c, HR_Team__c, Manager1__c, Team_Manager1__c,
               Manager2__c, Team_Manager2__c From account where id=: recId];
   } 
}
-----------------------------

Component


<aura:component controller="AccountTreeMapClass" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="acc" type="Account"/>
    <aura:attribute name="recordId"  type="String" default = "0012w0000085dU4AAI" />
    <aura:handler event="force:refreshView" action="{! c.doInit}" />
    <aura:handler name="init" value="{! this}" action="{! c.doInit}" />
    
    
    <lightning:layout>
        <div class="slds-scrollable" style="height:24rem;width:50rem;background-color: antiquewhite;">
            <body style="margin-top: -19px;">
                <div class="tree"  style="width:200%">
                    <aura:if isTrue="{!not(empty(v.acc.Department__c))}">																																
                        
                        <ul>
                            <li>
                                <p class="bg1"><ui:outputText value="{!v.acc.Department__c}"></ui:outputText> Group</p>
                                <ul>
                                    <li>
                                        <p class="slds-text-heading--medium"  style="background-color: yellow;width: 65px;word-break: break-all;">CEO</p> 
                                        <aura:if isTrue="{!not(empty(v.acc.Company_Head__c))}">
                                            <ul>
                                                <li  class="testry">
                                                    <p class="slds-text-heading--medium" style="background-color: lightblue;width: 65px;word-break: break-all;">{!v.acc.Company_Head__c}</p>
                                                </li>
                                            </ul>
                                        </aura:if>
                                    </li>
                                    <li>
                                        <p class="slds-text-heading--medium"  style="background-color: yellow;Width: 65px;word-break: break-all;">Director</p>			
                                        <aura:if isTrue="{!not(empty(v.acc.Director__c))}">
                                            <ul>
                                                <li>
                                                    <p class="slds-text-heading--medium" style="background-color: lightblue;width: 65px;word-break: break-all;"> {!v.acc.Director__c}</p>
                                                </li>
                                            </ul>
                                        </aura:if>
                                    </li>
                                    <li>
                                        <p class="slds-text-heading--medium"  style="background-color: yellow;width: 65px;word-break: break-all;">HR Department</p>
                                        <aura:if isTrue="{!not(empty(v.acc.HR_Team__c))}">
                                            <ul>
                                                <li>
                                                    <p class="slds-text-heading--medium" style="background-color: lightblue;width: 65px;word-break: break-all;"> {!v.acc.HR_Team__c}</p>
                                                </li>
                                            </ul>
                                        </aura:if>
                                    </li>
                                    
                                    <li>
                                        <p class="slds-text-heading--medium"  style="background-color: yellow;width: 65px;word-break: break-all;">Project Manager1</p>
                                        <aura:if isTrue="{!not(empty(v.acc.Manager1__c))}">
                                            <ul>
                                                
                                                <li>
                                                    <p class="slds-text-heading--medium" style="background-color: lightblue;width: 65px;word-break: break-all;">{!v.acc.Manager1__c}</p>
                                                    <ul>
                                                        <li>
                                                            <p class="slds-text-heading--medium" style="background-color: lightgray;width: 65px;word-break: break-all;">{!v.acc.Team_Manager1__c}</p>
                                                        </li>
                                                        
                                                    </ul>
                                                </li>
                                            </ul>
                                        </aura:if>
                                    </li>
                                    <li>
                                        <p class="slds-text-heading--medium" style="background-color: yellow;width: 65px;word-break: break-all;">Project Manager2</p>
                                        <aura:if isTrue="{!not(empty(v.acc.Manager2__c))}">
                                            <ul>
                                                <li style="background-color: antiquewhite;">
                                                    <p class="slds-text-heading--medium" style="background-color: lightblue;width: 65px;word-break: break-all;"> {!v.acc.Manager2__c}</p>
                                                    <ul>
                                                        <li style="background-color: antiquewhite;">
                                                            <p class="slds-text-heading--medium" style="background-color: lightgray;width: 65px;word-break: break-all;">Yeshwanth</p><!--{!v.keyResult.Team_Manager2__c}-->
                                                        </li>
                                                        <li style="background-color: antiquewhite;">
                                                            <p class="slds-text-heading--medium" style="background-color: lightgray;width: 65px;word-break: break-all;">Sai</p>
                                                        </li>
                                                        
                                                    </ul>
                                                </li>
                                                
                                            </ul>
                                        </aura:if>
                                    </li>
                                    <li>
                                        <p class="slds-text-heading--medium"  style="background-color: yellow;width: 65px;word-break: break-all;">Sales Department</p>
                                        <aura:if isTrue="{!not(empty(v.acc.Sales_Team__c))}">
                                            <ul>
                                                <li class="test" style="background-color: antiquewhite;">
                                                    <p class="slds-text-heading--medium" style="background-color: lightblue;width: 65px;word-break: break-all;">{!v.acc.Sales_Team__c}</p>
                                                </li>
                                            </ul>
                                        </aura:if>
                                    </li>
                                    <li>
                                        <p class="slds-text-heading--medium"  style="background-color: yellow;width: 65px;word-break: break-all;">Sales Project Manager</p>
                                        <aura:if isTrue="{!not(empty(v.acc.SalesManager__c))}">
                                            <ul>
                                                <li class="test">
                                                    <p class="slds-text-heading--medium" style="background-color: lightblue;width: 65px;word-break: break-all;">{!v.acc.SalesManager__c}</p>
                                                </li>
                                            </ul>
                                        </aura:if>
                                    </li>
                                    
                                </ul>
                            </li>
                        </ul>
                    </aura:if>
                </div>
            </body>
        </div>
        
    </lightning:layout>
    
    <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
    
    <div class="tree11" >
        <body>
            <a style="background-color: lightgreen;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Account</a>
            <img src="{!$Resource.Capture1}" style="margin-left: 126px;margin-top: -43px;width: 80px;margin-left: 0px;height: 38px;margin-top: -10px;border: 2px solid aliceblue;border-radius: 14px;"/>
            
            <ul>
                <li>
                    <a  style="background-color: yellow;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact1</a>
                    <ul>
                        <li>
                            <a  style="background-color: lightblue;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;"> {!v.acc.Company_Head__c}</a>
                        </li>
                    </ul>
                </li>
                <li>
                    <a style="background-color: yellow;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact2</a>
                    <ul>
                        <li>
                            <a style="background-color: lightblue;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;"> {!v.acc.Director__c}</a>
                        </li>
                    </ul>
                </li>
                <li>
                    <a style="background-color: yellow;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact3</a>
                    <ul>
                        <li>
                            <a style="background-color: lightblue;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;"> {!v.acc.HR_Team__c}</a>
                        </li>
                    </ul>
                </li>
                
                <li>
                    <a  style="background-color: yellow;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact4</a>
                    <ul>
                        <li>
                            <a  style="background-color: lightblue;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact5</a>
                            <ul>
                                <li>
                                    <a  style="background-color: lightgray;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact6</a><!--{!v.keyResult.Team_Manager1__c}-->
                                </li>
                                <li>
                                    <a  style="background-color: lightgray;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact7</a>
                                </li>
                                <li>
                                    <a style="background-color: lightgray;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact8</a>
                                </li>
                                <li>
                                    <a style="background-color: lightgray;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Contact9</a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li>
                    <a style="background-color: yellow;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Project Manager2</a>
                    <ul>
                        <li>
                            <a  style="background-color: lightblue;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;"> {!v.acc.Manager2__c}</a>
                            <ul>
                                <li>
                                    <a  style="background-color: lightgray;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Yeshwanth</a><!--{!v.keyResult.Team_Manager2__c}-->
                                </li>
                                <li>
                                    <a  style="background-color: lightgray;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Sai</a>
                                </li>
                                
                            </ul>
                        </li>
                    </ul>
                </li>
                <li>
                    
                    <a   style="background-color: yellow;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Sales Department</a>
                    <ul>
                        <li>
                            <a  style="background-color: lightblue;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Ila, Nikhil</a>
                        </li>
                    </ul>
                </li>
                <li>
                    <a  style="background-color: yellow;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Sales Project Manager</a>
                    <ul>
                        <li>
                            <a style="background-color: lightblue;font-weight: 300;font-size: 17px;border: 2px solid red;border-radius: 4px;">Haider</a>
                        </li>
                    </ul>
                </li>
                
            </ul>
        </body>
    </div>
    
</aura:component>

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

J.s code

({
    doInit: function (component, event, helper) {
        var action= component.get("c.getaccountData");
        action.setParams({
            recId: component.get("v.recordId")
        });
        action.setCallback(this, function(res) {
            var state=res.getState();
            var r = res.getReturnValue();
            if(state==="SUCCESS"){
                component.set("v.acc", r);
            }
        });
     $A.enqueueAction(action);              
    },
   
    recordUpdate: function (component, event, helper) {
        var accountFields = component.get("v.keyResult");
        var items = [{
            "label": "Department Of Proseraa",
            "name": "1",
            "expanded": true,
            "items": [{
                "label": "CEO",
                "name": "2",
                "expanded": true,
                "items" :[{
                    "label": accountFields.Company_Head__c,
                    "name": "3",
                    "expanded": true,
                }]
            },{
                "label": "Director",
                "name": "4",
                "expanded": true,
                "items" :[{
                    "label": accountFields.Director__c,
                    "name": "3",
                    "expanded": true,
                }]
            },{
                "label": "HR Team",
                "name": "5",
                "expanded": true,
                "items" :[{
                    "label": accountFields.HR_Team__c,
                    "name": "3",
                    "expanded": true,
                }]
            },{
                "label": "Project Manager",
                "name": "6",
                "expanded": true,
                "items" :[{
                    "label": accountFields.Manager1__c,
                    "name": "7",
                    "expanded": true,
                    "items" :[{
                        "label": accountFields.Team_Manager1__c,
                        "name": "8",
                        "expanded": true,
                    }]
                },{
                    "label":  accountFields.Manager2__c,
                    "name": "9",
                    "expanded": true,
                   
                    "items" :[{
                        "label": accountFields.Team_Manager2__c,
                        "name": "10",
                        "expanded": true,
                        'tag': 'button',
                    }]
                }]
            }],
           
           
        }];
        component.set('v.items', items);
    },
})

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

css


.THIS .tree ul {
    padding-top: 20px; position: relative;
    transition: all 0.5s;
}


.THIS .tree li {
    float: left; text-align: center;
    list-style-type: none;
    position: relative;
    padding: 40px 0px 0 3px;
   
    transition: all 0.5s;
    margin-left: -1px;
}

.THIS .tree li::before, .THIS .tree li::after{
    content: '';
    position: absolute; top: 0; right: 50%;
    border-top: 2px solid blue;
    width: 55%; height: 40px;
}

.THIS .tree li::after{
    right: auto; left: 50%;
    border-left: 2px solid blue;
}



/*We need to remove left-right connectors from elements without
any siblings*/
.THIS .tree li:only-child::after, .THIS .tree li:only-child::before {
    display: none;
}

/*Remove space from the top of single children*/
.THIS .tree li:only-child{ padding-top: 0;}

/*Remove left connector from first child and
right connector from last child*/
.THIS .tree li:first-child::before, .THIS .tree li:last-child::after{
    border: 0 none;
}
/*Adding back the vertical connector to the last nodes*/
.THIS .tree li:last-child::before{
    border-right: 2px solid blue;
    border-radius: 0 5px 0 0;}
.THIS .tree li:first-child::after{
    border-radius: 10px 0 0 0;
}

/*Time to add downward connectors from parents*/
.THIS .tree ul ul::before{
    content: '';
    position: absolute; top: 0; left: 49%;
    border-left: 3px solid blue;
    width: 0; height: 20px;
}

.THIS .test{
    position: absolute; top: 0;
}

.THIS .bg1{
    background-color: lightgreen;
}


.THIS .tree ul ul:empty::before{
    display: none;
}
.THIS .tree li p{
    border: 1px solid red;
    padding: 5px 10px;
    text-decoration: none;
    color: #666;
    font-family: arial, verdana, tahoma;
    font-size: 10px;
    display: inline-block;
    border-radius: 5px;
    transition: all 0.5s;
    border-right: 2px solid red;
}

/*Time for some hover effects*/
/*We will apply the hover effect the the lineage of the element also*/
.THIS .tree li p:hover, .THIS .tree li p:hover+ul li p {
    background: #c8e4f8; color: #000; border: 1px solid #94a0b4;
}
/*Connector styles on hover*/
.THIS .tree li p:hover+ul li::after,
.THIS .tree li p:hover+ul li::before,
.THIS .tree li p:hover+ul::before,
.THIS .tree li p:hover+ul ul::before{
    border-color:  #94a0b4;
}

.THIS.tree11{
    margin:0 auto;
    width: 100%;
}

.THIS.tree11 ul{
    padding: 10px 5px 0 5px;
    position: relative;
    z-index: 1;
}


.THIS.tree11 li{
    margin-left: 28px;
    list-style-type: none;
    position: relative;
    padding: 5px 5px 0 5px;
}

.THIS.tree11 li::after{
    content: '';
    position: absolute;
    border-bottom: 3px solid #c61f1f;
    border-left: 3px solid #c61f1f;
    height: 33px;
    width: 15px;
    right: auto;
    left: -10px;
    top: -11px;
    padding: -2px 10px;
    border-radius:2px;
}

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

<aura:application extends="Force:slds">
    <c:TreePicture />
</aura:application>


 
Hello Developers

I want to design a batch apex where it should fire an email on daily basis, and i have designed a visualforce component and controller with vf email templates where it sends reports with csv attachments, How do i design a batch apex class where it can send the vf email templates on daily basis

This is my VF component
 
<apex:component controller="ReportsToEmailController" access="global">
    <apex:attribute name="ReportId" description="Report ID" type="Id" assignTo="{!rptId}"/>
    <apex:attribute name="Color" description="Background color" type="String" assignTo="{!rptId}"/>
    <apex:outputPanel >      
        
        <table style="width: 100%;">
            <thead style="background : {!Color}">                
                <apex:repeat value="{!ReportResult.reportMetadata.detailColumns}" var="colName">
                    
                    <!-- reportMetadata is a class where it contains metadata of a report.
DetailColumns is a method of ReportMetadata class, it returns the API names(Coloumns Names)
for the fields that contain detailed data-->
                    
                    <th><apex:outputText value="{!ReportResult.reportExtendedMetadata.detailColumnInfo[colName].label}"/></th>
                    
                    
                    <!-- reportExtendedMetadata is class where it contains Report extended metadata and
it provides data type and label information.
detailColumnInfo is a method of reportExtendedMetadata clas, it returns map of columns names
and its label to Display as Header -->
                    
                </apex:repeat>
                <!-- Grouped fieds in summary report to get in header -->
                <apex:repeat value="{!ReportResult.reportMetadata.groupingsDown}" var="colName">
                    <th><apex:outputText value="{!colName.name}"/></th>
                </apex:repeat>
            </thead>
            <tbody>
                
                <!-- Summary Report with 2 level of grouping -->
                <apex:repeat value="{!ReportResult.groupingsDown.groupings}" var="groupingLevel1" >
                    <apex:repeat value="{!groupingLevel1.groupings}" var="groupingLevel2" >
                        <apex:repeat value="{!ReportResult.factMap[groupingLevel2.key+'!T'].rows}" var="row" rows="999">
                            <!-- Here we will get entire data of each row and T refers to the Row -->
                            <tr> <apex:repeat value="{!row.dataCells}" var="cell">
                                <!-- Here we will get data of each cell and displayed -->
                                <td><apex:outputText value="{!cell.label}"/></td>
                                </apex:repeat><td>{!groupingLevel1.label}</td><td>{!groupingLevel2.label}</td> </tr>
                        </apex:repeat>
                    </apex:repeat>
                </apex:repeat>
                
                <!-- Summary Report with 1 level of grouping -->
                <apex:repeat value="{!ReportResult.groupingsDown.groupings}" var="grouping" >
                    <apex:repeat value="{!ReportResult.factMap[grouping.key+'!T'].rows}" var="row" rows="999">
                        <!-- Here we will get entire data of each row and T refers to the Row -->
                        <tr> <apex:repeat value="{!row.dataCells}" var="cell">
                            <!-- Here we will get data of each cell and displayed -->
                            <td><apex:outputText value="{!cell.label}"/></td>
                            </apex:repeat><td>{!grouping.label}</td> </tr>
                    </apex:repeat>
                </apex:repeat>
                
                <!-- Tabular Report -->
                <apex:repeat value="{!ReportResult.factMap['T!T'].rows}" var="row" rows="999">
                    <!-- Here we will get entire data of each row and T refers to the Row -->
                    <tr> <apex:repeat value="{!row.dataCells}" var="cell">
                        <!-- Here we will get data of each cell and displayed -->
                        <td><apex:outputText value="{!cell.label}"/></td>
                        </apex:repeat></tr>
                </apex:repeat>
                <!--</apex:repeat>-->
            </tbody>
        </table>
    </apex:outputPanel>
</apex:component>

apex controller
 
public class ReportsToEmailController {
    public Id rptId { get; set; } // Here we will get the report Id from the VF Component
    private transient Reports.ReportResults results; // It will hold the entire data of a report
 
    /*********************
     // Method Name : getReportResult
     // Description : Here we will get the data of a report and send to the VF Component
    /********************/
 
    public Reports.ReportResults getReportResult() {
        // Here it will run the report with that report ID and adding the report data into results
        results = Reports.ReportManager.runReport(rptId, true);
        return results;
    }
}

Vf template
 
<messaging:emailTemplate subject="Report" recipientType="User" >
    <messaging:plainTextEmailBody >
        Hi {!recipient.FirstName}
        Please find the below attachments. 
 
    </messaging:plainTextEmailBody>
    <messaging:attachment filename="Account Report.xls">
        <!-- Here we can add multiple Reports -->
        <c:ReportsToEmail ReportId="00O2w000002RDbUEAW"/>
        <c:ReportsToEmail ReportId="00O2w000002Rp56EAC"/>
    </messaging:attachment>
</messaging:emailTemplate>

Can someone help me with the batch apex
Hello Developers

My Requirement is that Reports must be sent through email with csv attachments, i have refered several blogs,

Basically Report needs to go in email with csv format, i have designed a apex class, but i dont know how to excute it in ananomus window
 
global class sendreport implements System.Schedulable {
    global void execute(SchedulableContext sc) {
        ApexPages.PageReference report = new ApexPages.PageReference('00O2w000002RDbUEAW'); //this id of the report
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        attachment.setFileName('report.xls');
        attachment.setBody(report.getContent());
        attachment.setContentType('text/csv');
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setSubject('Report');
        message.setPlainTextBody('The report is attached.');
        message.setToAddresses( new String[] { 'manjunath.s@proseraa.com' } );
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
        
    }
 }
Any help please?

 
i have  designed a apex class on custom object where it checks the duplicate value for Specific recordtype, it is invoked by a trigger handler, i am getting this error - 

QuotaTrigger: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Class.QuotaTriggerHandler.dupQuotaError: line 5, column 1 Trigger.QuotaTrigger: line 3, column 1

I tried Googling the error but still   not able to Resolve the error, Any suggestions please

QuotaTrigger
 
trigger QuotaTrigger on Quota__c (before insert, before update) {

    QuotaTriggerHandler.dupQuotaError(Trigger.new);
    
}

QuotaTriggerHandler
 
public class QuotaTriggerHandler {
    
    public static void dupQuotaError (List <Quota__c> newTrigCon) {
        
        Id recordTypeId = Schema.SObjectType.Quota__c.getRecordTypeInfosByDeveloperName().get('Inside Sales Target(IS)').getRecordTypeId();
        
        //List of all Contact Records currently in the database    
        List <Quota__c> allCon = [SELECT ID, Name, Assignedto__c, Quater_Year__c, RecordTypeId, Month__c FROM Quota__c where RecordTypeId=:recordTypeId];
        
        //Iterate through new potential records
        for (Quota__c oneConTrig : newTrigCon) {
            
            //Needed to iterate through all existing records which is contained in the allCon List
            for (Integer i = 0; i < allCon.size(); i++)
                
                //If all conditions are met, there is a duplicate and thus, returns an error.
                if (oneContrig.Assignedto__c == allCon[i].Assignedto__c 
                    && oneContrig.Quater_Year__c == allCon[i].Quater_Year__c 
                    && oneConTrig.Month__c == allCon[i].Month__c
                    && oneConTrig.RecordTypeId == recordTypeId) {
                        
                        oneConTrig.addError('Duplicate Quota Detected! This record already exists.');
                        
                    }
        }      
    }
}

How do i resove this issue
Hello all

I am Trying to Design a Formula where i have Custom Picklist Field called ('Months') where it Contains all 12 months name, Now my Requirement is that when Any Month is Selected, Start Date and End Date Should Auto populate based on Month,

Ex - If i Choose Janaury, Start Date and End Date of January Should Auto Populate in the thosed Custom Fields, How Do i Achive this Functionality
Hello Developers 

I am new to the Apex Development, we have multiple triggers on a Opportunity, So i have been Given a Task to create a OpportunityHelper Class where all the Logic has to be Implemented in a Single Class, i am getting some errors where i am not able to resolve it

This is my below Trigger Logic
 
trigger opportunityTrigger on Opportunity (after delete,after update,after insert,after undelete) {
   
    set<ID>QtaIds = new set<ID>(); 
    if(trigger.isinsert || trigger.isundelete){
        for(opportunity opp : trigger.new){
            QtaIds.add(opp.Quota__c);
        }
    }  
    if(trigger.isdelete){
        for(opportunity opp : trigger.old){
            QtaIds.add(opp.Quota__c);           
        }        
    }
    if(trigger.isupdate){
        for(opportunity opp:trigger.new){
            QtaIds.add(opp.Quota__c);
            if(trigger.oldmap.get(opp.id).Quota__c != opp.Quota__c && trigger.oldmap.get(opp.id).Quota__c != null ){
                QtaIds.add(trigger.oldmap.get(opp.id).Quota__c);
            }            
        }
    }    
    map<id,double> amtmap = new map<id,double>();
    for(aggregateresult ag : [SELECT SUM(Amount) sum,Quota__c FROM Opportunity where Quota__c in :QtaIds and ClosedDate_Checkbox__c ='True' and StageName = 'Closed Won' group by Quota__c ]){
        amtmap.put((ID)ag.get('Quota__c'), double.valueof(ag.get('SUM')));
    }
    list<Quota__c>Qtalist = new list<Quota__c>();
    for(id iid : QtaIds){
        Quota__c quot = new Quota__c(id=iid); 
        if(amtmap.containskey(iid)){
            quot.Inside_Sales_Roll_up__c = amtmap.get(iid);
        }else{
            quot.Inside_Sales_Roll_up__c = 0;
        } 
        Qtalist.add(quot);       
    } 
    if(Qtalist.size()>0){
        update Qtalist;
    }
}

Below is My OpportunityTrigger
 
trigger OpportunityTrigger on Opportunity (after insert,after update) {
    
    IF(Trigger.isafter && Trigger.isupdate){ 
        OpportunityHelper.MMCountRollUpAmount();
     }
    
}

This is My OpportunityHelper
 
public class OpportunityHelper {
    
    public static Map<Id, Quota__c> QuotaMap =new Map<Id, Quota__c>();
    public static Map<String, List<Opportunity>> OpportunityListMap = new Map<String, List<Opportunity>>();
    public static set<ID>QtaIds = new set<ID>(); 
    
    public static void MMCountRollUpAmount(set<id> QuotaIdSet){
        set<ID>QtaIds = new set<ID>(); 
        if(trigger.isinsert || trigger.isundelete){
            for(opportunity opp : trigger.new){
                QtaIds.add(opp.Quota__c);
            }
        }  
        if(trigger.isdelete){
            for(opportunity opp : trigger.old){
                QtaIds.add(opp.Quota__c);           
            }        
        }
        if(trigger.isupdate){
            for(opportunity opp:trigger.new){
                QtaIds.add(opp.Quota__c);
                if(trigger.oldmap.get(opp.id).Quota__c != opp.Quota__c && trigger.oldmap.get(opp.id).Quota__c != null ){
                    QtaIds.add(trigger.oldmap.get(opp.id).Quota__c);
                }            
            }
        }    
        map<id,double> amtmap = new map<id,double>();
        for(aggregateresult ag : [SELECT SUM(Amount) sum,Quota__c FROM Opportunity where Quota__c in :QtaIds and Closed_Date_Checkbox__c ='True' AND StageName = 'Closed Won' group by Quota__c ]){
            amtmap.put((ID)ag.get('Quota__c'), double.valueof(ag.get('SUM')));
        }
        list<Quota__c>Qtalist = new list<Quota__c>();
        for(id iid : QtaIds){
            Quota__c quot = new Quota__c(id=iid); 
            if(amtmap.containskey(iid)){
                quot.Inside_Sales_Roll_up__c = amtmap.get(iid);
            }else{
                quot.Inside_Sales_Roll_up__c = 0;
            } 
            Qtalist.add(quot);       
        } 
        if(Qtalist.size()>0){
            update Qtalist;
        }
    }
}

TT​​​​​​​
Hello Everyone

I am new to the Apex development, i have Developed a Trigger where a custom field is updated based on the Formula field(Region), i have designed a trigger and its working perfectly, but the thing is i have written 5 seperate SOQL queries, so when i save a record it queries 5 times, How do i bulkify the trigger, so that it should query only once

Any Help will be Appricated

trigger Increment on Lead (before insert,Before Update) {
    if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate || Trigger.IsUnDelete))  {
        List<Lead> leadList = [Select Id,PraticeLWC__Lead_No_Region_IN__c From Lead Where PraticeLWC__Region__c = 'India'];
        For(Lead l : trigger.New ) {
            if(l.PraticeLWC__Region__c == 'India') {
                if(leadList.size() > 0){
                    l.PraticeLWC__Lead_No_Region_IN__c = leadList.size()+0;
                } else {
                    l.PraticeLWC__Lead_No_Region_IN__c = 1;
                }
            }
        }
        List<Lead> leadListt = [Select Id,PraticeLWC__Lead_No_Region_USA__c From Lead Where PraticeLWC__Region__c = 'US'];
        For(Lead m : trigger.New) {
            if(m.PraticeLWC__Region__c == 'US') {
                if(leadListt.size() > 0){
                    m.PraticeLWC__Lead_No_Region_USA__c = leadListt.size()+0;   
                } else {
                    m.PraticeLWC__Lead_No_Region_USA__c = 1;
                }
            }
        } 
        List<Lead> leadListm = [Select Id,PraticeLWC__Lead_No_Region_EU__c From Lead Where PraticeLWC__Region__c = 'EU'];
        For(Lead n : trigger.New) {
            if(n.PraticeLWC__Region__c == 'EU') {
                if(leadListm.size() > 0){
                    n.PraticeLWC__Lead_No_Region_EU__c = leadListm.size()+0;   
                } else {
                    n.PraticeLWC__Lead_No_Region_EU__c = 1;
                }
            }
        } 
        List<Lead> leadListo = [Select Id,PraticeLWC__Lead_No_Region_SEA__c From Lead Where PraticeLWC__Region__c = 'SEA'];
        For(Lead o : trigger.New) {
            if(o.PraticeLWC__Region__c == 'SEA') {
                if(leadListo.size() > 0){
                    o.PraticeLWC__Lead_No_Region_SEA__c = leadListo.size()+0;   
                } else {
                    o.PraticeLWC__Lead_No_Region_SEA__c = 1;
                }
            }
        }
        List<Lead> leadListp = [Select Id,PraticeLWC__Lead_No_Region_ME__c From Lead Where PraticeLWC__Region__c = 'ME'];
        For(Lead p : trigger.New) {
            if(p.PraticeLWC__Region__c == 'ME') {
                if(leadListp.size() > 0){
                    p.PraticeLWC__Lead_No_Region_ME__c = leadListp.size()+0;   
                } else {
                    p.PraticeLWC__Lead_No_Region_ME__c = 1;
                }
            }
        } 
        
    }                   
}
Hello Developers

I have been trying to write test class for the Below trigger, the Trigger basically syncs products from quote line items to opportunity line items, when custom checkbox is checked, i have designed a test class, but when i click run test, the code coverage shows 0, below is my trigger and tets class 

Trigger
 
trigger QuoteLineItemTrigger on Quotes__c (after insert, after update)
{
    
    Map<Id,Id> quoteIdToOppId =new Map<Id,Id>();
    Map<Id,List<QuoteLineitem__c>> quoteIdToLineItems = new Map<Id,List<QuoteLineitem__c>>();
    List<OpportunityLineItem__c> oppLineItems = new List<OpportunityLineItem__c>();
    Map<Id,String> oppIdtoName = new Map<Id,String>();
    
    for(Quotes__c q : trigger.new)
    {
        if(q.IsSyncing__c && q.IsSyncing__c  != Trigger.oldMap.get(q.Id).IsSyncing__c ) quoteIdToOppId.put(q.id, q.OpportunityId__c);
    }
    System.debug('UAC: quoteIdToOppId ' + quoteIdToOppId);
    
    for( QuoteLineitem__c qli :[SELECT Id, Product2Id__c,Product2Id__r.name,Quantity__c,ServiceDate__c, QuotesId__c,ListPrice__c,Line_Item_Description__c,Total_Price__c,Product2Id__r.Product_Code__c,UnitPrice__c  FROM QuoteLineitem__c WHERE QuotesId__c =:quoteIdToOppId.keyset() ])
    {
        List<QuoteLineitem__c> tempList = quoteIdToLineItems.get(qli.QuotesId__c) ;
        if(tempList == null)
        {
            
            templist = new List<QuoteLineitem__c>();
            quoteIdToLineItems.put(qli.QuotesId__c, templist);
           
        }
        tempList.add(qli);
    }
    System.debug('UAC: quoteIdToLineItems ' + quoteIdToLineItems);
    
    for(Opportunities__c opp : [SELECT Id , Name  FROM Opportunities__c WHERE ID IN :quoteIdToOppId.values()] )
    
    {
        oppIdtoName.put(opp.id, opp.Name)   ;
    }
    System.debug('UAC: oppIdtoName ' + quoteIdToLineItems);
    
    for(Quotes__c q : Trigger.new)
    {
        if(q.IsSyncing__c && quoteIdToLineItems.containsKey(q.Id))
        {
            for(QuoteLineitem__c qli : quoteIdToLineItems.get(q.Id))
            {
                OpportunityLineItem__c oli = new OpportunityLineItem__c();
                oli.OpportunityId__c = quoteIdToOppId.get(qli.QuotesId__c); 
                System.debug(' qli.Product2Id__r.name ' +  qli.Product2Id__r.name);
                oli.Name = qli.Product2Id__r.name;
                System.debug(' qli.Product2Id__c ' +  qli.Product2Id__c);
                System.debug(' qli.ListPrice__c ' +  qli.ListPrice__c);
                System.debug(' qli.Line_Item_Description__c ' +  qli.Line_Item_Description__c);
                oli.Product2Id__c = qli.Product2Id__c; 
                oli.Quantity__c = qli.Quantity__c; 
                oli.ListPrice__c = integer.valueof(qli.ListPrice__c); 
                oli.Description__c = qli.Line_Item_Description__c;
                oli.ServiceDate__c = qli.ServiceDate__c;
                oli.Total_Price__c = qli.Total_Price__c;
                oli.ProductCode__c = qli.Product2Id__r.Product_Code__c;
                oli.Sales_Price__c =qli.UnitPrice__c;
                oppLineItems.add(oli);
            }
            
        }
        System.debug('UAC: oppLineItems ' + oppLineItems);
        if(oppLineItems.size() > 0) insert oppLineItems ;
        
    }
}

My test Class

 
@isTest(SeeAllData=true)
public class QuoteLineItemTestClass {							
    
    
    private static void setUpData(){
        
        Opportunities__c opp = new Opportunities__c();
        opp.Name = 'Test Opp';
        opp.Stage__c = 'Prospecting';
        opp.Close_Date__c = Date.today();
        insert opp;
        
        Quotes__c Quo = new Quotes__c();
        Quo.Name = 'Test Quote';
        Quo.OpportunityId__c = opp.Id;
        Quo.AccountId__c = opp.Id;
        insert Quo;
        
        QuoteLineitem__c QLI = new QuoteLineitem__c();
        QLI.QuotesId__c = Quo.Id;
        QLI.Quantity__c = 1;
        QLI.Product2Id__c = Quo.Id;
        insert QLI;
        
        Product2__c P = new Product2__c();
        P.Name = 'Test record';
        P.Opportunities__c = opp.Id;
        insert P;
        
        PricebookEntry__c PBE = new PricebookEntry__c();
        PBE.Product2Id__c = p.Id;
        PBE.IsActive__c = true;
        insert PBE;
        
        Pricebook2__c pb = [select Id from Pricebook2__c where Is_Standard_Price_Book__c = true limit 1]; 
        
    }
    
    static testMethod void  basicTest() {
       
    QuoteLineitem qli = [Select Id,QuoteId From QuoteLineitem Limit 1];
        Test.startTest();
            Insert qli;
        Test.stopTest();                
    }
}
I'm using the following to email my report as CSV but it just includes the first 2000 rowes in the csv file while my report has more than 50000 rowes. how can I solve this? thanks in advance:


global class Report implements System.Schedulable {
    global void execute(SchedulableContext sc) {
        ApexPages.PageReference report = new ApexPages.PageReference('/00O60000003XpO6?csv=1');
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        attachment.setFileName('testcsv');
        attachment.setBody(report.getContent());
        attachment.setContentType('text/csv');
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setSubject('test');
        message.setPlainTextBody('test is attached.');
        message.setToAddresses( new String[] { 'test@test.com' } );
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
        
    }
}