• Asakti
  • NEWBIE
  • 35 Points
  • Member since 2021
  • developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 15
    Replies
ScheduleCreateTargetBatch schedule =new ScheduleCreateTargetBatch();

String sch ='0 0 0 1 4 ?';
;
String sch1 ='0 0 2 1 JAN,APR,JUL,OCT ?';
 
i have written the below trigger
trigger CountVistorOnCustomer on Visit__c (After insert) {
     Id devRecordTypeId = Schema.SObjectType.Visit__c.getRecordTypeInfosByName().get('Existing Customer Visit').getRecordTypeId();
    
    List<Account> ct = new List<Account>();
    List<Account> ct1 = new List<Account>();
    List<Account> ct2 = new List<Account>();
    List<Account> ct3 = new List<Account>();
    set<Id> customerId = new set<Id>();
    Integer orgFiscalMonth = [SELECT FiscalYearStartMonth FROM Organization].FiscalYearStartMonth; //april
    Date orgFiscalYearStart = Date.newinstance(system.today().year(), orgFiscalMonth, 1);//2020-04-01
    Date orgFiscalYearEnd = Date.newinstance(system.today().year(), orgFiscalMonth + 11, 31);
    
    Integer PreviousYear = system.today().year() - 1;
    Integer NextYear = system.today().year() + 1;
    Integer CurrentYear = system.today().year();
    
    if(Trigger.isInsert) {
        for(Visit__c v1:Trigger.New) {
            customerId.add(v1.Customer__c);   
            
        }   
        
    }
    
    
    AggregateResult[] groupedResults = [SELECT COUNT(Id), Customer__c FROM Visit__c
                                        where Customer__c IN :customerId and 
                                        VisitDate__c>=:orgFiscalYearStart 
                                        and VisitDate__c<=:orgFiscalYearEnd
                                        and RecordTypeId ='012O0000000KkAVIA0'
                                        GROUP BY Customer__c  ];
    AggregateResult[] groupedResults1 = [SELECT COUNT(Id), Customer__c FROM Visit__c
                                         where Customer__c IN :customerId 
                                         and VisitDate__c = LAST_FISCAL_QUARTER
                                         and RecordTypeId ='012O0000000KkAVIA0'
                                         GROUP BY Customer__c  ];
    AggregateResult[] groupedResults2 = [SELECT COUNT(Id), Customer__c FROM Visit__c
                                         where Customer__c IN :customerId 
                                         and VisitDate__c = THIS_QUARTER
                                         and RecordTypeId ='012O0000000KkAVIA0'
                                         GROUP BY Customer__c  ];
    
    for(AggregateResult ar:groupedResults) {
        
        Id custid = (ID)ar.get('Customer__c');
        Integer count = (INTEGER)ar.get('expr0');
        Account cust1 = new Account(Id=custid);
        cust1.Current_FY_for_Report__c = count;
        ct1.add(cust1);
        
    }
    for(AggregateResult ar:groupedResults1) {
        system.debug('Trigger Fired groupedResults second one'+groupedResults1);
        Id custid = (ID)ar.get('Customer__c');
        
        Integer count1 = (INTEGER)ar.get('expr0');
        
        Account cust1 = new Account(Id=custid);
        
        cust1.Previous_Quater_For_Report__c = count1;
        
        ct2.add(cust1);
        
    }
    for(AggregateResult ar:groupedResults2) {
        system.debug('Trigger Fired groupedResults third one'+groupedResults1);
        Id custid = (ID)ar.get('Customer__c');
        
        Integer count2 = (INTEGER)ar.get('expr0');
        
        Account cust1 = new Account(Id=custid);
        
        cust1.Current_Quarter__c = count2;
        
        ct3.add(cust1);
        
    }
    
    
    system.debug('Trigger Fired ct'+ct);
    update ct1;
    update ct2;
    update ct3;
    ct.addAll(ct1);
    ct.addAll(ct2);
    ct.addAll(ct3);

}


batch class for the same
global class CountVisitorBatch implements Database.Batchable<sObject>{

    global Database.QueryLocator start(Database.BatchableContext BC){
        String query = 'Select ID,Previous_Quater_For_Report__c,(Select Id,Customer__c from Visit__r) from Account'; 
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext info, List<Account> Accounts){
        list<account> updatedList = new list<account>();
        if(Accounts.size() > 0){
            for(account acc : Accounts){
                acc.Previous_Quater_For_Report__c = acc.Visit__r.size();
                
                updatedList.add(acc);
            }
        }
        if(updatedList.size() > 0){
            update updatedList;
        }
        
    }
    
    global void finish(Database.BatchableContext info){
        
    }
}


But getting error
Variable does not exist: Visit__r

Can someone please help me with the batch class
I have two objects Region and territory ,based on region there are different territory ,suppose i chose South region it will show Chennai and Vizag .i have already added all the values and done mapping in object level
i am creating an aura component where i have two 2 picklist type field(region,territory) when i select south from drop down ,it should show in territory list the values Chennai and Vizag in drop down

can anyone help me with any referance for the same.
i want the 'Send List Email' button my lead object but i can not see it even if i have enabled the permission set " Allow sending of List Emails "

i can see it in contact object but can not see it in lead object .
In Account object i have one status picklist which has 3 value  blank,client,prospect ,i want to create the report with conversion rate between only client and prospect type

example:
If there are 78 prospect came in last month and 1 is only client then 
(1/78)*100= 1.28
i want to show 1.28.

What i have done till now:
Report on Account and filter last month,then group by status Field.

and adde the below formula field.
RowCount/PARENTGROUPVAL(RowCount, Account.Status_Of_Account__c)    

it is not working.
trigger opportunityProduct on OpportunityLineItem (after insert) {
   
   
   Set<Id> oppId = new Set<Id>();
   
   for(OpportunityLineItem opp : Trigger.new)
   {
       oppId.add(opp.OpportunityId);
       
   }
   
   List<Opportunity> oppList = new List<Opportunity>();
   List<String> products = new List<String>();
   
   
   for(Opportunity opp : [Select Name,(Select Name,product2Id,product2.Name_Details__c from OpportunityLineItems) from Opportunity where Id in:oppId ])
   {
       for(OpportunityLineItem oppLine : opp.OpportunityLineItems)
       {
           if(OpportunityLineItem.Name != null)
           {
               products.add(oppLine.product2.Name_Details__c);
               
           }
       }
       opp.Product_Details__c = String.join(products,', ');
       oppList.add(opp);
       
   }
      update oppList;
}




batchclass i have written


global class productNameOnOpportunity implements Database.Batchable<sObject>{
   global Database.QueryLocator start(Database.BatchableContext BC){
       String query = 'Select Name,Product_Details__c (Select Name,product2Id,product2.Name_Details__c from OpportunityLineItems) from Opportunity';
       return Database.getQueryLocator(query);
   }
   
   global void execute(Database.BatchableContext info, List<Opportunity> Opp)
   {
       List<String> names = new List<String>();
       List<Opportunity> oppList = new List<Opportunity>();
       for(OpportunityLineItem oppLine : Opp)
       {
           if(OpportunityLineItem.Name != null)
           {          
               names.add(OpportunityLineItem.product2.Name_Details__c);
               Opp.Product_Details__c = String.join(names,',');
               oppList.add(Opp);
           }
       }
       if(oppList.size()>0)
       {
           update oppList;
       }  
   }    
   global void finish(Database.BatchableContext info){
       
   }
}
Hi All,

I want to create a report with lead details along with the emails sent from lead through the email activity with details like last opened email,first opened email.

The emails created under the lead throgh the activity 'Email' is not stored under the object 'Email message'

I have created a custom report type between Lead and Email Message object but it does not have the email details.
 
here is the option to create email under the lead
Hi All, I want to write batch class for below trigger

trigger ContactTrigger on Contact (after insert, after update, after delete, after undelete) {
    //---> above handling all states which could see a contact added to or removed from an account
   
    //---> on delete we use Trigger.Old, all else, Trigger.new
    List<Contact> contacts = Trigger.isDelete ? Trigger.old : Trigger.new;

    //---> the Set class rocks for finding the unique values in a list
    Set<Id> acctIds = new Set<Id>();
   
    for (Contact c : contacts) {
     //yes, you can have a contact without an account
        if (c.AccountId != null) {
            acctIds.add(c.AccountId);
        }
    }
   
    List<Account> acctsToRollup = new List<Account>();
    
    //****** Here is the Aggregate query...don't count in loops, let the DB do it for you*****
    for (AggregateResult ar : [SELECT AccountId AcctId, Count(id) ContactCount 
                               FROM Contact 
                               WHERE AccountId in: acctIds 
                               GROUP BY AccountId]){
        Account a = new Account();
        a.Id = (Id) ar.get('AcctId'); //---> handy trick for updates, set the id and update
        a.No_of_Contacts_For_Account__c = (Integer) ar.get('ContactCount');
        acctsToRollup.add(a);
    }
    
    //----> probably you'll want to do a little more error handling than this...but this should work. 
    update acctsToRollup;

}

can someone help me on same
Hi All, 

there are 3 profiles ,
1.Admin
2.Sales user
3.Unit User

sales user creates a record  i.e. RecordA in a child object of opportunity which is having an approoval process and once it is approved by the Admin(only)  then only the Unit user should be able to see  the  RecordA not before.

How to achieve it?how to check and where to check if this configured in system.

I checked in approval process there is no such rule,and also checked in profiles
Unit user have - read access only
Sales user - read,create ,edit
Hi All i have written a test class for one trigger ,but it does cover all the lines and failing

trigger:
trigger LeadRegionUpdate on Lead (before insert) {
    
    for (Lead L: Trigger.new)
    {
        if(L.Country__c == 'India'){
            L.Lead_Region__c = 'India';
            
        }
        else if(L.Country__c == 'Japan' || L.Country__c == 'China' || L.Country__c == 'Korea')
        {
            L.Lead_Region__c = 'Asia';
            
        }
        else if(L.Country__c == 'Australia' || L.Country__c == 'New Zealand')
        {
            L.Lead_Region__c = 'ANZ';
            
        }
        else if(L.Country__c == 'Canada' || L.Country__c == 'United States of America')
        {
            L.Lead_Region__c = 'North America';
            
        }
        else if(L.Country__c == 'Argentina' || L.Country__c == 'Mexico'
                || L.Country__c == 'Bolivia' || L.Country__c == 'Venezuela'
                || L.Country__c == 'Brazil' || L.Country__c == 'Uruguay' 
                || L.Country__c == 'Guyana' || L.Country__c == 'Suriname' 
                || L.Country__c == 'Chile' || L.Country__c == 'Peru' 
                || L.Country__c == 'Colombia' || L.Country__c == 'Paraguay'
                || L.Country__c == 'Ecuador' || L.Country__c == 'Guyana')
        {
            L.Lead_Region__c = 'South America';
            
        }
        
        else if(L.Country__c == 'Brunei' || L.Country__c == 'Philippines'
                || L.Country__c == 'Burma(Myanmar)' || L.Country__c == 'Singapore'
                || L.Country__c == 'Timor-Leste' || L.Country__c == 'Thailand' 
                || L.Country__c == 'Indonesia' || L.Country__c == 'Suriname' 
                || L.Country__c == 'Taiwan' || L.Country__c == 'Vietnam' 
                || L.Country__c == 'Laos' || L.Country__c == 'Malaysia'
               )
        {
            L.Lead_Region__c = 'South East Asia';
        }
        
        else if(L.Country__c == 'Albania' || L.Country__c == 'Andorra'
                || L.Country__c == 'Armenia' || L.Country__c == 'Austria'
                || L.Country__c == 'Iceland' || L.Country__c == 'Ireland' 
                || L.Country__c == 'Italy' || L.Country__c == 'Kazakhstan' 
                || L.Country__c == 'Latvia' || L.Country__c == 'Liechtenstein' 
                || L.Country__c == 'Hungary' || L.Country__c == 'Greece' 
                || L.Country__c == 'Georgia' || L.Country__c == 'Germany' 
                || L.Country__c == 'Finland' || L.Country__c == 'France'
                || L.Country__c == 'Brunei' || L.Country__c == 'Philippines'
                || L.Country__c == 'Estonia' || L.Country__c == 'Denmark'
                || L.Country__c == 'CzechRepublic' || L.Country__c == 'Cyprus' 
                || L.Country__c == 'Croatia' || L.Country__c == 'Bulgaria' 
                || L.Country__c == 'BosniaandHerzegovina' || L.Country__c == 'Belgium' 
                || L.Country__c == 'Azerbaijan' || L.Country__c == 'Belarus'
               )
        {
            L.Lead_Region__c = 'Europe';
            
        }  
            else if(L.Country__c == 'Algeria' || L.Country__c == 'Bahrain'
                    || L.Country__c == 'Djibouti' || L.Country__c == 'Egypt'
                    || L.Country__c == 'Iran' || L.Country__c == 'Iraq' 
                    || L.Country__c == 'Jordan' || L.Country__c == 'Israel' 
                    || L.Country__c == 'Kuwait' || L.Country__c == 'Lebanon' 
                    || L.Country__c == 'Libya' || L.Country__c == 'Malta' 
                    || L.Country__c == 'Oman' || L.Country__c == 'Qatar' 
                    || L.Country__c == 'Saudi Arabia' || L.Country__c == 'Syria'
                    || L.Country__c == 'Tunisia' || L.Country__c == 'United Arab Emirates'
                    || L.Country__c == 'Palestine' || L.Country__c == 'Yemen'
                    
                   )
            {
                L.Lead_Region__c = 'MENA';
                
            }
        }
    }


Test class:

@isTest
private class TestLeadRegionUpdate {
    
    Private static testMethod void contactDmlTest() {
        
        Test.startTest();
        Lead l = new Lead(lastname='A', company='11',Lead_Type__c= 'Junk',Lead_Region__c = 'India',Country__c = 'India');
        insert l;
                
        Test.stopTest();
         Test.startTest();
        Lead l1 = new Lead(lastname='B', company='11',Lead_Type__c= 'Junk',Lead_Region__c = 'Japan',Country__c = 'Asia');
        insert l1;
                
        Test.stopTest();
         Test.startTest();
        Lead l2 = new Lead(lastname='C', company='11',Lead_Type__c= 'Junk',Lead_Region__c = 'China',Country__c = 'Asia');
        insert l2;
                
        Test.stopTest();
         Test.stopTest();
         Test.startTest();
        Lead l3 = new Lead(lastname='C', company='11',Lead_Type__c= 'Junk',Lead_Region__c = 'Korea',Country__c = 'Asia');
        insert l3;
                
        Test.stopTest();
    }
}

code coverage is 7%
can someone help me with the test class
Hi All,

I have 2 fields in Quote object both are currency type,
Multi-currency is enabled .
fieldA is populating as per the Opportunity currency .
but the fieldB  should always   show  vaule in INR whenever entered manually irrespective of the Opportunity currency but now it shows value as per the opportunity currency?

Can we do it ,please suggest.
can we create one single activities report with both opportunity and project object?,i checked there is no way we can create a custom  report type  with activity,product,oppertunity object together.
  • April 29, 2021
  • Like
  • 0
below is my class for updating the field as per the email reply ,can someone help me with the test class for the same 


global class UpdateStatusOnCertificate implements Messaging.InboundEmailHandler {
    
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, 
                                                           Messaging.InboundEnvelope env){
                                                               
                                                               // Create an InboundEmailResult object for returning the result of the 
                                                               // Apex Email Service
                                                               Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
                                                               
                                                               
                                                               
                                                               Certificate__c vCon = [SELECT Id, Status__c, Personal_Email_id__c,LastModifiedDate 
                                                                                      FROM Certificate__c
                                                                                      WHERE Personal_Email_id__c = :email.fromAddress
                                                                                      order by LastModifiedDate desc LIMIT 1];
                                                               
                                                               string  RepliedMsgOnly = email.plainTextBody.substring(0, 20);    
                                                               
                                                               if(RepliedMsgOnly.contains('Acknowledged'))
                                                               {
                                                                   
                                                                   vCon.Status__c = 'Acknowledged';
                                                                   vCon.Acknowledged__c = true;
                                                               }
                                                               else if(RepliedMsgOnly.contains('Not Received'))
                                                               {
                                                                   vCon.Status__c = 'Not Received';
                                                                   vCon.Acknowledged__c = false;     
                                                               }
                                                               update vCon;
                                                               
                                                               // Set the result to true. No need to send an email back to the user 
                                                               // with an error message
                                                               result.success = true;
                                                               
                                                               // Return the result for the Apex Email Service
                                                               return result;
                                                           }
}




test class:
@isTest
public class UpdateStatus_test {
   public static testMethod void updatecheck()
   {
           Messaging.InboundEmail email = new Messaging.InboundEmail();
        email.subject = 'testing';
        email.plainTextBody = 'Hello, this a test email body. for testing purposes only. Bye';
       
           Certificate__c vCon = [SELECT Id, Status__c, Personal_Email_id__c,LastModifiedDate 
        FROM Certificate__c limit 1];
               vCon.Status__c = 'Acknowledged';
            vCon.Acknowledged__c = true;
       update vCon;

   }
}
  • April 28, 2021
  • Like
  • 0
i have written the below trigger
trigger CountVistorOnCustomer on Visit__c (After insert) {
     Id devRecordTypeId = Schema.SObjectType.Visit__c.getRecordTypeInfosByName().get('Existing Customer Visit').getRecordTypeId();
    
    List<Account> ct = new List<Account>();
    List<Account> ct1 = new List<Account>();
    List<Account> ct2 = new List<Account>();
    List<Account> ct3 = new List<Account>();
    set<Id> customerId = new set<Id>();
    Integer orgFiscalMonth = [SELECT FiscalYearStartMonth FROM Organization].FiscalYearStartMonth; //april
    Date orgFiscalYearStart = Date.newinstance(system.today().year(), orgFiscalMonth, 1);//2020-04-01
    Date orgFiscalYearEnd = Date.newinstance(system.today().year(), orgFiscalMonth + 11, 31);
    
    Integer PreviousYear = system.today().year() - 1;
    Integer NextYear = system.today().year() + 1;
    Integer CurrentYear = system.today().year();
    
    if(Trigger.isInsert) {
        for(Visit__c v1:Trigger.New) {
            customerId.add(v1.Customer__c);   
            
        }   
        
    }
    
    
    AggregateResult[] groupedResults = [SELECT COUNT(Id), Customer__c FROM Visit__c
                                        where Customer__c IN :customerId and 
                                        VisitDate__c>=:orgFiscalYearStart 
                                        and VisitDate__c<=:orgFiscalYearEnd
                                        and RecordTypeId ='012O0000000KkAVIA0'
                                        GROUP BY Customer__c  ];
    AggregateResult[] groupedResults1 = [SELECT COUNT(Id), Customer__c FROM Visit__c
                                         where Customer__c IN :customerId 
                                         and VisitDate__c = LAST_FISCAL_QUARTER
                                         and RecordTypeId ='012O0000000KkAVIA0'
                                         GROUP BY Customer__c  ];
    AggregateResult[] groupedResults2 = [SELECT COUNT(Id), Customer__c FROM Visit__c
                                         where Customer__c IN :customerId 
                                         and VisitDate__c = THIS_QUARTER
                                         and RecordTypeId ='012O0000000KkAVIA0'
                                         GROUP BY Customer__c  ];
    
    for(AggregateResult ar:groupedResults) {
        
        Id custid = (ID)ar.get('Customer__c');
        Integer count = (INTEGER)ar.get('expr0');
        Account cust1 = new Account(Id=custid);
        cust1.Current_FY_for_Report__c = count;
        ct1.add(cust1);
        
    }
    for(AggregateResult ar:groupedResults1) {
        system.debug('Trigger Fired groupedResults second one'+groupedResults1);
        Id custid = (ID)ar.get('Customer__c');
        
        Integer count1 = (INTEGER)ar.get('expr0');
        
        Account cust1 = new Account(Id=custid);
        
        cust1.Previous_Quater_For_Report__c = count1;
        
        ct2.add(cust1);
        
    }
    for(AggregateResult ar:groupedResults2) {
        system.debug('Trigger Fired groupedResults third one'+groupedResults1);
        Id custid = (ID)ar.get('Customer__c');
        
        Integer count2 = (INTEGER)ar.get('expr0');
        
        Account cust1 = new Account(Id=custid);
        
        cust1.Current_Quarter__c = count2;
        
        ct3.add(cust1);
        
    }
    
    
    system.debug('Trigger Fired ct'+ct);
    update ct1;
    update ct2;
    update ct3;
    ct.addAll(ct1);
    ct.addAll(ct2);
    ct.addAll(ct3);

}


batch class for the same
global class CountVisitorBatch implements Database.Batchable<sObject>{

    global Database.QueryLocator start(Database.BatchableContext BC){
        String query = 'Select ID,Previous_Quater_For_Report__c,(Select Id,Customer__c from Visit__r) from Account'; 
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext info, List<Account> Accounts){
        list<account> updatedList = new list<account>();
        if(Accounts.size() > 0){
            for(account acc : Accounts){
                acc.Previous_Quater_For_Report__c = acc.Visit__r.size();
                
                updatedList.add(acc);
            }
        }
        if(updatedList.size() > 0){
            update updatedList;
        }
        
    }
    
    global void finish(Database.BatchableContext info){
        
    }
}


But getting error
Variable does not exist: Visit__r

Can someone please help me with the batch class
I have two objects Region and territory ,based on region there are different territory ,suppose i chose South region it will show Chennai and Vizag .i have already added all the values and done mapping in object level
i am creating an aura component where i have two 2 picklist type field(region,territory) when i select south from drop down ,it should show in territory list the values Chennai and Vizag in drop down

can anyone help me with any referance for the same.
i want the 'Send List Email' button my lead object but i can not see it even if i have enabled the permission set " Allow sending of List Emails "

i can see it in contact object but can not see it in lead object .
trigger opportunityProduct on OpportunityLineItem (after insert) {
   
   
   Set<Id> oppId = new Set<Id>();
   
   for(OpportunityLineItem opp : Trigger.new)
   {
       oppId.add(opp.OpportunityId);
       
   }
   
   List<Opportunity> oppList = new List<Opportunity>();
   List<String> products = new List<String>();
   
   
   for(Opportunity opp : [Select Name,(Select Name,product2Id,product2.Name_Details__c from OpportunityLineItems) from Opportunity where Id in:oppId ])
   {
       for(OpportunityLineItem oppLine : opp.OpportunityLineItems)
       {
           if(OpportunityLineItem.Name != null)
           {
               products.add(oppLine.product2.Name_Details__c);
               
           }
       }
       opp.Product_Details__c = String.join(products,', ');
       oppList.add(opp);
       
   }
      update oppList;
}




batchclass i have written


global class productNameOnOpportunity implements Database.Batchable<sObject>{
   global Database.QueryLocator start(Database.BatchableContext BC){
       String query = 'Select Name,Product_Details__c (Select Name,product2Id,product2.Name_Details__c from OpportunityLineItems) from Opportunity';
       return Database.getQueryLocator(query);
   }
   
   global void execute(Database.BatchableContext info, List<Opportunity> Opp)
   {
       List<String> names = new List<String>();
       List<Opportunity> oppList = new List<Opportunity>();
       for(OpportunityLineItem oppLine : Opp)
       {
           if(OpportunityLineItem.Name != null)
           {          
               names.add(OpportunityLineItem.product2.Name_Details__c);
               Opp.Product_Details__c = String.join(names,',');
               oppList.add(Opp);
           }
       }
       if(oppList.size()>0)
       {
           update oppList;
       }  
   }    
   global void finish(Database.BatchableContext info){
       
   }
}
Hi All,

I want to create a report with lead details along with the emails sent from lead through the email activity with details like last opened email,first opened email.

The emails created under the lead throgh the activity 'Email' is not stored under the object 'Email message'

I have created a custom report type between Lead and Email Message object but it does not have the email details.
 
here is the option to create email under the lead
Hi All, I want to write batch class for below trigger

trigger ContactTrigger on Contact (after insert, after update, after delete, after undelete) {
    //---> above handling all states which could see a contact added to or removed from an account
   
    //---> on delete we use Trigger.Old, all else, Trigger.new
    List<Contact> contacts = Trigger.isDelete ? Trigger.old : Trigger.new;

    //---> the Set class rocks for finding the unique values in a list
    Set<Id> acctIds = new Set<Id>();
   
    for (Contact c : contacts) {
     //yes, you can have a contact without an account
        if (c.AccountId != null) {
            acctIds.add(c.AccountId);
        }
    }
   
    List<Account> acctsToRollup = new List<Account>();
    
    //****** Here is the Aggregate query...don't count in loops, let the DB do it for you*****
    for (AggregateResult ar : [SELECT AccountId AcctId, Count(id) ContactCount 
                               FROM Contact 
                               WHERE AccountId in: acctIds 
                               GROUP BY AccountId]){
        Account a = new Account();
        a.Id = (Id) ar.get('AcctId'); //---> handy trick for updates, set the id and update
        a.No_of_Contacts_For_Account__c = (Integer) ar.get('ContactCount');
        acctsToRollup.add(a);
    }
    
    //----> probably you'll want to do a little more error handling than this...but this should work. 
    update acctsToRollup;

}

can someone help me on same
Hi All i have written a test class for one trigger ,but it does cover all the lines and failing

trigger:
trigger LeadRegionUpdate on Lead (before insert) {
    
    for (Lead L: Trigger.new)
    {
        if(L.Country__c == 'India'){
            L.Lead_Region__c = 'India';
            
        }
        else if(L.Country__c == 'Japan' || L.Country__c == 'China' || L.Country__c == 'Korea')
        {
            L.Lead_Region__c = 'Asia';
            
        }
        else if(L.Country__c == 'Australia' || L.Country__c == 'New Zealand')
        {
            L.Lead_Region__c = 'ANZ';
            
        }
        else if(L.Country__c == 'Canada' || L.Country__c == 'United States of America')
        {
            L.Lead_Region__c = 'North America';
            
        }
        else if(L.Country__c == 'Argentina' || L.Country__c == 'Mexico'
                || L.Country__c == 'Bolivia' || L.Country__c == 'Venezuela'
                || L.Country__c == 'Brazil' || L.Country__c == 'Uruguay' 
                || L.Country__c == 'Guyana' || L.Country__c == 'Suriname' 
                || L.Country__c == 'Chile' || L.Country__c == 'Peru' 
                || L.Country__c == 'Colombia' || L.Country__c == 'Paraguay'
                || L.Country__c == 'Ecuador' || L.Country__c == 'Guyana')
        {
            L.Lead_Region__c = 'South America';
            
        }
        
        else if(L.Country__c == 'Brunei' || L.Country__c == 'Philippines'
                || L.Country__c == 'Burma(Myanmar)' || L.Country__c == 'Singapore'
                || L.Country__c == 'Timor-Leste' || L.Country__c == 'Thailand' 
                || L.Country__c == 'Indonesia' || L.Country__c == 'Suriname' 
                || L.Country__c == 'Taiwan' || L.Country__c == 'Vietnam' 
                || L.Country__c == 'Laos' || L.Country__c == 'Malaysia'
               )
        {
            L.Lead_Region__c = 'South East Asia';
        }
        
        else if(L.Country__c == 'Albania' || L.Country__c == 'Andorra'
                || L.Country__c == 'Armenia' || L.Country__c == 'Austria'
                || L.Country__c == 'Iceland' || L.Country__c == 'Ireland' 
                || L.Country__c == 'Italy' || L.Country__c == 'Kazakhstan' 
                || L.Country__c == 'Latvia' || L.Country__c == 'Liechtenstein' 
                || L.Country__c == 'Hungary' || L.Country__c == 'Greece' 
                || L.Country__c == 'Georgia' || L.Country__c == 'Germany' 
                || L.Country__c == 'Finland' || L.Country__c == 'France'
                || L.Country__c == 'Brunei' || L.Country__c == 'Philippines'
                || L.Country__c == 'Estonia' || L.Country__c == 'Denmark'
                || L.Country__c == 'CzechRepublic' || L.Country__c == 'Cyprus' 
                || L.Country__c == 'Croatia' || L.Country__c == 'Bulgaria' 
                || L.Country__c == 'BosniaandHerzegovina' || L.Country__c == 'Belgium' 
                || L.Country__c == 'Azerbaijan' || L.Country__c == 'Belarus'
               )
        {
            L.Lead_Region__c = 'Europe';
            
        }  
            else if(L.Country__c == 'Algeria' || L.Country__c == 'Bahrain'
                    || L.Country__c == 'Djibouti' || L.Country__c == 'Egypt'
                    || L.Country__c == 'Iran' || L.Country__c == 'Iraq' 
                    || L.Country__c == 'Jordan' || L.Country__c == 'Israel' 
                    || L.Country__c == 'Kuwait' || L.Country__c == 'Lebanon' 
                    || L.Country__c == 'Libya' || L.Country__c == 'Malta' 
                    || L.Country__c == 'Oman' || L.Country__c == 'Qatar' 
                    || L.Country__c == 'Saudi Arabia' || L.Country__c == 'Syria'
                    || L.Country__c == 'Tunisia' || L.Country__c == 'United Arab Emirates'
                    || L.Country__c == 'Palestine' || L.Country__c == 'Yemen'
                    
                   )
            {
                L.Lead_Region__c = 'MENA';
                
            }
        }
    }


Test class:

@isTest
private class TestLeadRegionUpdate {
    
    Private static testMethod void contactDmlTest() {
        
        Test.startTest();
        Lead l = new Lead(lastname='A', company='11',Lead_Type__c= 'Junk',Lead_Region__c = 'India',Country__c = 'India');
        insert l;
                
        Test.stopTest();
         Test.startTest();
        Lead l1 = new Lead(lastname='B', company='11',Lead_Type__c= 'Junk',Lead_Region__c = 'Japan',Country__c = 'Asia');
        insert l1;
                
        Test.stopTest();
         Test.startTest();
        Lead l2 = new Lead(lastname='C', company='11',Lead_Type__c= 'Junk',Lead_Region__c = 'China',Country__c = 'Asia');
        insert l2;
                
        Test.stopTest();
         Test.stopTest();
         Test.startTest();
        Lead l3 = new Lead(lastname='C', company='11',Lead_Type__c= 'Junk',Lead_Region__c = 'Korea',Country__c = 'Asia');
        insert l3;
                
        Test.stopTest();
    }
}

code coverage is 7%
can someone help me with the test class
can we create one single activities report with both opportunity and project object?,i checked there is no way we can create a custom  report type  with activity,product,oppertunity object together.
  • April 29, 2021
  • Like
  • 0
below is my class for updating the field as per the email reply ,can someone help me with the test class for the same 


global class UpdateStatusOnCertificate implements Messaging.InboundEmailHandler {
    
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, 
                                                           Messaging.InboundEnvelope env){
                                                               
                                                               // Create an InboundEmailResult object for returning the result of the 
                                                               // Apex Email Service
                                                               Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
                                                               
                                                               
                                                               
                                                               Certificate__c vCon = [SELECT Id, Status__c, Personal_Email_id__c,LastModifiedDate 
                                                                                      FROM Certificate__c
                                                                                      WHERE Personal_Email_id__c = :email.fromAddress
                                                                                      order by LastModifiedDate desc LIMIT 1];
                                                               
                                                               string  RepliedMsgOnly = email.plainTextBody.substring(0, 20);    
                                                               
                                                               if(RepliedMsgOnly.contains('Acknowledged'))
                                                               {
                                                                   
                                                                   vCon.Status__c = 'Acknowledged';
                                                                   vCon.Acknowledged__c = true;
                                                               }
                                                               else if(RepliedMsgOnly.contains('Not Received'))
                                                               {
                                                                   vCon.Status__c = 'Not Received';
                                                                   vCon.Acknowledged__c = false;     
                                                               }
                                                               update vCon;
                                                               
                                                               // Set the result to true. No need to send an email back to the user 
                                                               // with an error message
                                                               result.success = true;
                                                               
                                                               // Return the result for the Apex Email Service
                                                               return result;
                                                           }
}




test class:
@isTest
public class UpdateStatus_test {
   public static testMethod void updatecheck()
   {
           Messaging.InboundEmail email = new Messaging.InboundEmail();
        email.subject = 'testing';
        email.plainTextBody = 'Hello, this a test email body. for testing purposes only. Bye';
       
           Certificate__c vCon = [SELECT Id, Status__c, Personal_Email_id__c,LastModifiedDate 
        FROM Certificate__c limit 1];
               vCon.Status__c = 'Acknowledged';
            vCon.Acknowledged__c = true;
       update vCon;

   }
}
  • April 28, 2021
  • Like
  • 0