• Saravana Bharathi 1
  • NEWBIE
  • 75 Points
  • Member since 2017

  • Chatter
    Feed
  • 2
    Best Answers
  • 2
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 22
    Replies
Hi,

I have to write a trigger to calculate next meeting date from today. I have an object which stores input of Frequency(monthly, two month, quaterly), Day(Mon-Fri),Week (Week1 -Week 5). Based on these input how should I calculate the next meeting date from today.

example: If Frequency is "Monthly", Day is "Wednesday" and Week is "Week 3".
then I have to calculate date of next meeting which should be Wednesday of 3rd week of next month.

Please help.
Thanks!
 
  • April 13, 2017
  • Like
  • 0
I have an apex batch class that I was able to get workig in my sandbox enviorment and that is ready for deployment into my production enviroment. 

However when I went to write the test class for this I ran into some trouble, with an error message that says line 50 = Test Class Error: Argument must be an object that implements Database.Batchable.

Can you guys help me get over this hurdle or tell me if i need a new test class code in order to be able to deploy to production? Below are my batch class and my test class thanks. 

Batch Class
global class UpdateContactsVoter implements Database.Batchable<sObject>{
    global Database.QueryLocator start(Database.BatchableContext BC){
        String query = 'Select ID,FirstName,LastName,MailingPostalCode from contact where contact.voter_file_id__c = null';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext info, List<contact> scope){
        Set<String> set_Str = new Set<string>();
                                Map<String,Voter_File_TX__c> mp_VoterFile;

        for(Voter_File_TX__c VoterFile : [Select ID,First_Name__c, Last_Name__c,Zipcode__c, Contact__c From Voter_File_TX__c] ){
                                                if(mp_VoterFile==null){
                                                                mp_VoterFile = new Map<String,Voter_File_TX__c>();
                                                }
                                                mp_VoterFile.put(VoterFile.First_Name__c +''+VoterFile.Last_Name__c +''+VoterFile.Zipcode__c,VoterFile);
                                }
                                for(Contact ContactList : scope){
                                                if(mp_VoterFile!=null && mp_VoterFile.containsKey(ContactList.FirstName+''+ ContactList.LastName+''+ ContactList.MailingPostalCode))
            
            {
                                                                mp_VoterFile.get(ContactList.FirstName +''+ ContactList.LastName +''+ ContactList.MailingPostalCode).Contact__c = ContactList.id;
                                                }
                                }
                                if(mp_VoterFile!=null && mp_VoterFile.values()!=null){
                                                update mp_VoterFile.values();
                                }
    }
    
    global void finish(Database.BatchableContext info){
        
    }
}


Test Class
 line 50 = Test Class Error: Argument must be an object that implements Database.Batchable.

@isTest 
public class TestClassUpdateContacts 
{
    static testMethod void testMethod1() 
    {
        List<Contact> lstContact= new List<Contact>();
        List<Voter_File_TX__c> lstVoterfile = new List<Voter_File_TX__c>();
        if(contact.voter_file_id__c == null && voter_file_tx__c.contact__c == null)
        {
        Contact cont = new Contact();
        cont.FirstName ='Test';
        cont.LastName = 'Test';
        cont.id = 'Test';
        cont.MailingPostalCode = 'test';
            
        insert cont;
            
        Voter_File_TX__c vf = new Voter_File_TX__c();
        vf.First_Name__c ='Test';
        vf.Last_Name__c ='Test';
        vf.RNC_ID__c = 'Test';
        vf.Zipcode__c = 'Test'; 
                                vf.First_Name__c = cont.FirstName ;
        vf.Last_Name__c = cont.LastName ;
        vf.Zipcode__c = cont.MailingPostalCode ;
        vf.Contact__c = cont.Id ;
        
        insert vf;
       
        cont.FirstName = vf.First_Name__c ;
        cont.LastName = vf.Last_Name__c ;
        cont.MailingPostalCode = vf.Zipcode__c;
        cont.RNC_ID__c = vf.RNC_ID__c ;
            
                                update cont;
        }
        else {
         contact cont1 = new Contact(); 
         Voter_File_TX__c vf1 = new Voter_File_TX__c();
         cont1.Voter_File_ID__c = null;
         vf1.Contact__c = null; 
          
        }
        insert lstContact;
        update lstContact;
        
        Test.startTest();

            TestClassUpdateContacts obj = new TestClassUpdateContacts();
            DataBase.executeBatch(obj); 
            
        Test.stopTest();
    }
}
 


 

Hi All,

I am a newbie to Lightning component Development.

I have written a lightning component, which holds Text Input, and a button.
When User enters some text in the text field, by clicking a button. I am calling a javascript controller, then to Javascript Handler, then to Apex Controller. I am searching and returning the result to handler, to javascript handler and then to component attribute values.

I am setting Response to Component attribute in Handler.

I am not getting the response in UI. When I debugged using Lightning Inspector - Chrome Extensions, Actions are successful, and I am getting result in the attributes.

Please let me know, whether i am missing anything.

Thanks in advance.
Hi All,

I am a newbie to Lightning component Development.

I have written a lightning component, which holds Text Input, and a button.
When User enters some text in the text field, by clicking a button. I am calling a javascript controller, then to Javascript Handler, then to Apex Controller. I am searching and returning the result to handler, to javascript handler and then to component attribute values.

I am setting Response to Component attribute in Handler.

I am not getting the response in UI. When I debugged using Lightning Inspector - Chrome Extensions, Actions are successful, and I am getting result in the attributes.

Please let me know, whether i am missing anything.

Thanks in advance.

Hi All:

I am trying to implement Bitly with a custom field in Opportunity. I am successful in getting the Bitly Url for the Opportunity field. However I am having trouble in getting test cases set up for the same. I followed the following article:

https://douglascayers.com/2015/10/21/salesforce-create-short-urls-with-bitly-process-builder-and-apex/
https://gist.github.com/DouglasCAyers/de978590b97e235a96fc

However my test method fails in static void test_shorten() in BitlyShortenURLInvocableTest, where it throws the following error:

System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
Class.BitlyService.getAccessToken: line 56, column 1
Class.BitlyService.: line 12, column 1
Class.BitlyShortenURLInvocable.shortenAsync: line 25, column 1


I have got a process builder that calls the method shorten of BitlyShortenURLInvocable, on creation/update of Opportunity. My code in test_shorten is given below.
 

    Test.startTest();
    Test.setMock( HttpCalloutMock.class, new MockHttpResponse() );
    
    Opportunity job = new Opportunity();
    job.Name = 'Test Job';
    job.StageName = 'Not yet started';
    job.CloseDate = System.today() ; 
    insert job;
    Test.stopTest();
      
      
    job  = [ SELECT id, Shortened_Url__c FROM Opportunity WHERE id = :job.id LIMIT 1 ];
    
    System.assert( String.isNotBlank( job.Shortened_Url__c ) );
Any help will be much appreciated.

Regards,
Anindya


 

i want to get results even if i give single letter in searchfield
help me in getting output i tried to manage but still errors 




public class OppNameSearchController {
    public string Name{set;get;}
    public Decimal amount{set;get;}
    public Opportunity Opp{set;get;}
    public string searchstring {get;set;} 
    public boolean show{set;get;}
    
    public void method()
    {
        
       if(searchstring != null && searchstring != '' ){  
    string searchquery='select Name, Amount from opportunity where Name like \'%'+searchstring+'%\'  Limit 10';  
    
     Opp = Database.query(searchstring); 
           show = true;

                   }
        else
        {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'There are no Opportunities with the Name -'  +searchstring);
            ApexPages.addMessage(myMsg);
            show = false;
        }
    }
    
    public void save()
    {
        Opportunity op = Opp;
        update op;
      }
     public void clear(){  
   opp.clear();  
   }  
}







<apex:page controller="OppNameSearchController" >
    <apex:form>
        <apex:pageBlock >
            <apex:pageBlockSection title="Search Filter" >
                Opportunity Name: <apex:inputText value="{!searchstring}"/>
                <apex:commandButton value="Search" action="{!method}" />
            </apex:pageBlockSection>
            <apex:pageMessages ></apex:pageMessages>
            
            
            <apex:pageBlockSection title="Searched Record" rendered="{!show}" >
                <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" 
                                        hideOnEdit="editButton" event="ondblclick" 
                                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit">
                    <apex:outputField value="{!Opp.Name}"></apex:outputField>
                    <apex:outputField value="{!Opp.Amount}"/>
                </apex:inlineEditSupport>
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!clear}" value="reset"/>
            </apex:pageBlockSection>
        </apex:pageBlock>        
           
        
    </apex:form>
</apex:page>



 
Hi,

I have to write a trigger to calculate next meeting date from today. I have an object which stores input of Frequency(monthly, two month, quaterly), Day(Mon-Fri),Week (Week1 -Week 5). Based on these input how should I calculate the next meeting date from today.

example: If Frequency is "Monthly", Day is "Wednesday" and Week is "Week 3".
then I have to calculate date of next meeting which should be Wednesday of 3rd week of next month.

Please help.
Thanks!
 
  • April 13, 2017
  • Like
  • 0
HI, 

we have 15 record types in case object.

do not want to allow to CLOSE/EDIT other records types cases . 

but 3 record types are allowed to close/edit each other cases? 

How to achieve this? 

 
I want to write trigger to enable a checkbox in contact whenever its Account is modified(updated). 
I'm not able to put the condition for Account updated or not! Can you guys provide the logic?? 
 
unable to cover below lines in my test class:

public void onUndelete(List<Opportunity> oldOpps) {
        
        List<AccountShare> acctSharesToAdd = new List<AccountShare>();  
        
        for (Opportunity o : oldOpps) {
            
            ProvideAccShare(o,acctSharesToAdd);
        }
        
        if (acctSharesToAdd.size() > 0)
            insert acctSharesToAdd;
    }
    
Hi,

I need help on the following issue 

I am having a trigger on account object 

When, we trying to upload bulk records  via dataloader or ETL , system is facing 'CPU usage limition'' issue.
For one Account record creation, the trigger is running four times instead of one time.

How to avoid the issue, Kindly help me pls
MY TRIGGER :

trigger AccountTrigger on Account (after insert, before update, after update, after delete) {  
    
    /* Assign & create Account team members based on user department*/
    if(Trigger_Status__c.getValues('AccountTeam').Active__c && Trigger.isUpdate  && Trigger.isBefore ){
        /* Before insert process */
        AccountTriggerHelper.updateAccountTeam(Trigger.newMap, Trigger.oldMap);
    } 
    
    /* Trigger to invoke the AccountIneligibilty Logs Tracking*/
    if(Trigger_Status__c.getValues('AccountEligibilityLogTrigger').Active__c && Trigger.isAfter && Trigger.isUpdate){
        AccountTriggerHelper.createAccountEligiblityLogs(Trigger.newMap, Trigger.oldMap);
    }
    
    /* Trigger to invoke the DiscountCode Calculations on Products*/
    if(Trigger_Status__c.getValues('AccountAirlineLeveltrigger').Active__c && Trigger.isAfter && Trigger.isUpdate) {
        AccountTriggerHelper.calculateDiscountCode(Trigger.newMap,Trigger.oldMap);
    }
    
    /* Trigger to invoke the DeleteAccount Tracking of Records*/
    if(Trigger_Status__c.getValues('AccountDeleteTrigger').Active__c && Trigger.isAfter && Trigger.isDelete) {
        AccountTriggerHelper.createDelAccountLogTracker(Trigger.oldMap); 
    }        
}
MY CLASS:

public class AccountTriggerHelper {
    
    /*--------------------------------------------------------------------------------------      
  Method Name:        updateAccountTeam
  Description:        Method to Assign & create Account team members based on user department
  Parameter:          Account New Map & Old Map 
  --------------------------------------------------------------------------------------*/    
    public static void updateAccountTeam(Map<Id,Account> newMapAccount, Map<Id,Account> oldMapAccount){
      try{
        AccountTeamHandler accHandler = new AccountTeamHandler();
        List<Account> lstNewAccount = newMapAccount.values();
            accHandler.setRevenueManualUpdate(lstNewAccount, oldMapAccount);
            accHandler.createAccountTeamMembers(lstNewAccount, oldMapAccount);
      }
      catch(Exception ex){
        String recType = CustomSettingsUtilities.getConfigDataMap('Log Exception Logs Rec Type');    
            CreateLogs.LogWrapper logWrap = new CreateLogs.LogWrapper('Account Team - Account Trigger', 'AccountTriggerHelper', 
                                                                      'updateAccountTeam', UserInfo.getUserName(), '', 
                                                                      '', false, recType);
            
            Log__c objLogs = CreateLogs.createLogRec(logWrap, '');
            CreateLogs.createApplicationLog(objLogs, ex);
      }
    }

    /*--------------------------------------------------------------------------------------      
  Method Name:        createAccountEligiblityLogs
  Description:        Method to Create AccountIneligibilty Logs and Update
  Parameter:          Account New Map & Old Map 
  --------------------------------------------------------------------------------------*/    
    public static void createAccountEligiblityLogs(Map<Id,Account> newMapAccount, Map<Id,Account> oldMapAccount){
      try{
        AccountEligibilityLogHandler.createAccountEligiblityLogs(newMapAccount, oldMapAccount);
      }
      catch(Exception ex){
        String recType = CustomSettingsUtilities.getConfigDataMap('Log Exception Logs Rec Type');    
            CreateLogs.LogWrapper logWrap = new CreateLogs.LogWrapper('SME - Account Trigger', 'AccountTriggerHelper', 
                                                                      'createAccountEligiblityLogs', UserInfo.getUserName(), '', 
                                                                      '', false, recType);
            
            Log__c objLogs = CreateLogs.createLogRec(logWrap, '');
            CreateLogs.createApplicationLog(objLogs, ex);
      }
    }

    /*--------------------------------------------------------------------------------------      
  Method Name:        calculateDiscountCode
  Description:        Method to DiscountCode Calculations on Products
  Parameter:          Account New Map & Old Map 
  --------------------------------------------------------------------------------------*/    
    public static void calculateDiscountCode(Map<Id,Account> newMapAccount, Map<Id,Account> oldMapAccount){
    try{
            AccountAirlineLevelHandler.updateDiscountCodeOnProducts(newMapAccount, oldMapAccount);
      }
      catch(Exception ex){
        String recType = CustomSettingsUtilities.getConfigDataMap('Log Exception Logs Rec Type');    
            CreateLogs.LogWrapper logWrap = new CreateLogs.LogWrapper('SME - Account Trigger', 'AccountTriggerHelper', 
                                                                      'calculateDiscountCode', UserInfo.getUserName(), '', 
                                                                      '', false, recType);
            
            Log__c objLogs = CreateLogs.createLogRec(logWrap, '');
            CreateLogs.createApplicationLog(objLogs, ex);
      }
    }

    /*--------------------------------------------------------------------------------------      
  Method Name:        createDelAccountLogTracker
  Description:        Method to Create Delete Tracker Logs records when any Account is Deleted
  Parameter:          Account Old Map 
  --------------------------------------------------------------------------------------*/    
    public static void createDelAccountLogTracker(Map<Id,Account> oldMapAccount){
        try{
            String recTypeName = CustomSettingsUtilities.getConfigDataMap('Del Log SME Account Rec Type');
            List<CreateLogs.DeleteLogWrapper> lstDelLogWrapper = new List<CreateLogs.DeleteLogWrapper>();
            for(Account acc: oldMapAccount.values()){
                String directvalue = CustomSettingsUtilities.getConfigDataMap('AccListner Type Direct Stream');
                if(acc.Listner_Type__c == directvalue){
                    CreateLogs.DeleteLogWrapper delLogWrapper = new CreateLogs.DeleteLogWrapper();
                    delLogWrapper.recType = recTypeName;
                    delLogWrapper.recName =  acc.Name;
                    delLogWrapper.abnNumber = acc.ABN_Tax_Reference__c;
                    delLogWrapper.sobjectId = acc.Id;
                    delLogWrapper.sobjectName = 'Account';
                    lstDelLogWrapper.add(delLogWrapper);
                }
            }
            List<Delete_Tracker_Log__c> lstDelTrackerLog = CreateLogs.createDeleteLog(lstDelLogWrapper);
            insert lstDelTrackerLog;
        }catch(Exception ex){
            String recType = CustomSettingsUtilities.getConfigDataMap('Log Exception Logs Rec Type');    
            CreateLogs.LogWrapper logWrap = new CreateLogs.LogWrapper('Direct Stream - Account Trigger', 'AccountTriggerHelper', 
                                                                      'createDelAccountLogTracker', UserInfo.getUserName(), '', 
                                                                      '', false, recType);
            
            Log__c objLogs = CreateLogs.createLogRec(logWrap, '');
            CreateLogs.createApplicationLog(objLogs, ex);
        }
    }

}
Kindly help me pls

Thanks in Advance

 
I have an apex batch class that I was able to get workig in my sandbox enviorment and that is ready for deployment into my production enviroment. 

However when I went to write the test class for this I ran into some trouble, with an error message that says line 50 = Test Class Error: Argument must be an object that implements Database.Batchable.

Can you guys help me get over this hurdle or tell me if i need a new test class code in order to be able to deploy to production? Below are my batch class and my test class thanks. 

Batch Class
global class UpdateContactsVoter implements Database.Batchable<sObject>{
    global Database.QueryLocator start(Database.BatchableContext BC){
        String query = 'Select ID,FirstName,LastName,MailingPostalCode from contact where contact.voter_file_id__c = null';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext info, List<contact> scope){
        Set<String> set_Str = new Set<string>();
                                Map<String,Voter_File_TX__c> mp_VoterFile;

        for(Voter_File_TX__c VoterFile : [Select ID,First_Name__c, Last_Name__c,Zipcode__c, Contact__c From Voter_File_TX__c] ){
                                                if(mp_VoterFile==null){
                                                                mp_VoterFile = new Map<String,Voter_File_TX__c>();
                                                }
                                                mp_VoterFile.put(VoterFile.First_Name__c +''+VoterFile.Last_Name__c +''+VoterFile.Zipcode__c,VoterFile);
                                }
                                for(Contact ContactList : scope){
                                                if(mp_VoterFile!=null && mp_VoterFile.containsKey(ContactList.FirstName+''+ ContactList.LastName+''+ ContactList.MailingPostalCode))
            
            {
                                                                mp_VoterFile.get(ContactList.FirstName +''+ ContactList.LastName +''+ ContactList.MailingPostalCode).Contact__c = ContactList.id;
                                                }
                                }
                                if(mp_VoterFile!=null && mp_VoterFile.values()!=null){
                                                update mp_VoterFile.values();
                                }
    }
    
    global void finish(Database.BatchableContext info){
        
    }
}


Test Class
 line 50 = Test Class Error: Argument must be an object that implements Database.Batchable.

@isTest 
public class TestClassUpdateContacts 
{
    static testMethod void testMethod1() 
    {
        List<Contact> lstContact= new List<Contact>();
        List<Voter_File_TX__c> lstVoterfile = new List<Voter_File_TX__c>();
        if(contact.voter_file_id__c == null && voter_file_tx__c.contact__c == null)
        {
        Contact cont = new Contact();
        cont.FirstName ='Test';
        cont.LastName = 'Test';
        cont.id = 'Test';
        cont.MailingPostalCode = 'test';
            
        insert cont;
            
        Voter_File_TX__c vf = new Voter_File_TX__c();
        vf.First_Name__c ='Test';
        vf.Last_Name__c ='Test';
        vf.RNC_ID__c = 'Test';
        vf.Zipcode__c = 'Test'; 
                                vf.First_Name__c = cont.FirstName ;
        vf.Last_Name__c = cont.LastName ;
        vf.Zipcode__c = cont.MailingPostalCode ;
        vf.Contact__c = cont.Id ;
        
        insert vf;
       
        cont.FirstName = vf.First_Name__c ;
        cont.LastName = vf.Last_Name__c ;
        cont.MailingPostalCode = vf.Zipcode__c;
        cont.RNC_ID__c = vf.RNC_ID__c ;
            
                                update cont;
        }
        else {
         contact cont1 = new Contact(); 
         Voter_File_TX__c vf1 = new Voter_File_TX__c();
         cont1.Voter_File_ID__c = null;
         vf1.Contact__c = null; 
          
        }
        insert lstContact;
        update lstContact;
        
        Test.startTest();

            TestClassUpdateContacts obj = new TestClassUpdateContacts();
            DataBase.executeBatch(obj); 
            
        Test.stopTest();
    }
}
 


 

I am trying to insert a record from developer console for object 'TestTriggers__c'. The record is failing to insert as expected because I am not passing the required field 'Amount__c'. I need to, however, catch this in my trigger, which i am unable to. I can see the error 'System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Amount__c]: [Amount__c]' in the debug log, but unable to catch it within my trigger 'TestTriggers'. Is there any way to do that. I need to use the same approach to catch the errors from different integrations (like data loader) we have in our SF instance.
Hi,
I know Salesforce has limitations but I would need alternate to this issue, please check the below code and provide alternate to that?
The requirement is: calling externam API that has 28000 records to get and that API has limitations on results (only 400 allows) so loooping 72 to get 28K and another for loop on 400 records.

@future (callout=true)
    public static void getAllUsersFromCampusLabs(){
        for (integer i=1;i<=72;i++){
            Map<String,String> parameters = new Map<String,String>();
            parameters.put('page',string.valueof(i));
            parameters.put('page','1');
            parameters.put('pageSize','400');
            String respString = DataAccessController.call_RESTFulAPI_Request('users',parameters);
            Map<String, Object> jsonMap = (Map<String, Object>) JSON.deserializeUntyped(respString);
            List<Object> usersList = (List<Object>)jsonMap.get('items');
                for (Object userObject:usersList){
                    Map<String, Object> user = (Map<String, Object>)userObject;
                    String jsonUserName = String.valueOf(user.get('userId')).trim();
                    String userName = (String)user.get('username');
                    String netID = userName.split('@')[0].trim().toLowerCase();
                    List<Contact> userContacts = [SELECT ID,userID__c,userName__c  from Contact where userID__c=:netID];
                    if (userContacts.size()>0){
                        Contact userContact = userContacts[0];
                        userContact.userName__c = jsonUserName;
                         update userContact;
                    }
                }
            }
    }
My Requirement is When I update Classification values on Top Account(Parent Account),it updates values on all child accounts.
I have Written a batch apex class for this as I faced CPU Timeout error earlier.
Below is the code for Batch Apex Class:
global class batchAccountUpdate implements Database.batchable<sObject>{ 
   public String query;
   global database.querylocator start(Database.BatchableContext info){
   system.debug('query Result:'+query);
       String query1='select Id,ParentId,RecordTypeId,UltimateParent__c,AccountCategory__c,Account_Subcategory__c ,AccountClassification1__c, AccountClassification2__c, AccountClassification3__c,AccountClassification4__c, AccountClassification5__c, AccountClassification6__c, AccountClassification7__c, AllowClassificationUpdate__c,Allow_CategorySubCategory_Update__c,BillingCountry,BillingCountryCode from Account where Id='+query+'';
   system.debug('Query1 Result:'+query1);
   system.debug('Start Info:'+info);
    return Database.getquerylocator(query);
    }     
   global void execute(Database.BatchableContext info, List<Account> children){
       
       if (!children.isEmpty()) {
                update children;
            }
   }     
   global void finish(Database.BatchableContext info){     
   } 
}
The purpose of this batch is to perform DML operation only.I have created instance of this class in another apex class where I have written an actual logic.
Below is the Apex class:
public static List<Account> updateClassification(Map<Id,Account> accMap) {
List<Account> accList = findAccountToUpdate(accMap);
// find ultimate accounts with classification fields
Set<Id> utimateIds = new Set<Id>();
for (Account acc: accList) {
utimateIds.add(acc.UltimateParent__c);
}
Map<Id,Account> ultimateMap = new Map<Id,Account>(new SelectAccounts().execute(utimateIds));
SET<ID> keys = ultimateMap.keyset();

// update statistics from ultimates
List<Account> accToUpdate = new List<Account>();
for (Account acc: accList) {
Account parentAccount = ultimateMap.get(acc.UltimateParent__c);
accToUpdate.add(new Account(
Id = acc.Id,
AccountCategory__c = parentAccount.AccountCategory__c,
Account_Subcategory__c = parentAccount.Account_Subcategory__c,
AccountClassification1__c = parentAccount.AccountClassification1__c,
AccountClassification2__c = parentAccount.AccountClassification2__c,
AccountClassification4__c = parentAccount.AccountClassification4__c,
AccountClassification5__c = parentAccount.AccountClassification5__c,
AccountClassification6__c = parentAccount.AccountClassification6__c,
AccountClassification7__c = parentAccount.AccountClassification7__c,    
AllowClassificationUpdate__c = true,
Allow_CategorySubCategory_Update__c = true
));
}
string query= '\''+String.join(keys,'\',\'')+'\'';

//Calling Batch Class
batchAccountUpdate execbatch = new batchAccountUpdate();
execbatch.query = query;
database.executebatch(execbatch);
resetAllowClassificationUpdate(accToUpdate);
resetAllowCategoryUpdate(accToUpdate);

return accToUpdate;
}

Whenever I Update Classification Value son Top Accounts or If I do Reparenting,it always throws an exception whenever it runs the natch class.
I can not add this method to Batch Class as the method has lots of dependency on another methods.
My Ultimate Goal is I whenever I perform DML,I have to call batch job so that CPU Runtime error will not face as I can update more than 200 Child records at a time too.

Can someone help what is wrong in the above code? 
 
Hi All,

I am a newbie to Lightning component Development.

I have written a lightning component, which holds Text Input, and a button.
When User enters some text in the text field, by clicking a button. I am calling a javascript controller, then to Javascript Handler, then to Apex Controller. I am searching and returning the result to handler, to javascript handler and then to component attribute values.

I am setting Response to Component attribute in Handler.

I am not getting the response in UI. When I debugged using Lightning Inspector - Chrome Extensions, Actions are successful, and I am getting result in the attributes.

Please let me know, whether i am missing anything.

Thanks in advance.
trigger PreviousGLSalesHandling on financialData__c (before  insert) {
    
    list<financialData__c> saleList = new list<financialData__c>();
    list<string> saleListacc = new list<string>();

    for(financialData__c s:trigger.new) {
        saleList.add(s);     
        saleListacc.add(s.account__c);
    }
    
    list<financialData__c> sllist = [select id,Year__c,Month__c,Account__c,GL_Sales__c, Land_Comm__c from financialData__c where account__C in:saleListacc];
    
    for(financialData__c  st: saleList)   {
        
        for(financialData__c sm: sllist){
            
            if(st.Year__c!=null && st.Month__c!=null && st.Account__c!=null && sm.Year__c!=null && sm.Month__c!=null && sm.Account__c!=null ){
                
                String yr = String.valueof(st.Year__c-1);
                String mnth = String.valueof(st.Month__c);
                
                integer monthhh;
                
                if(mnth=='jan'){monthhh=1;}
                else if(mnth=='feb'){monthhh=2;}
                else if(mnth=='mar'){monthhh=3;}
                else if(mnth=='apr'){monthhh=4;}
                else if(mnth=='may'){monthhh=5;}
                else if(mnth=='jun'){monthhh=6;}
                else if(mnth=='jul'){monthhh=7;}
                else if(mnth=='aug'){monthhh=8;}
                else if(mnth=='sep'){monthhh=9;}
                else if(mnth=='oct'){monthhh=10;}
                else if(mnth=='nov'){monthhh=11;}
                else if(mnth=='dec'){monthhh=12;}
                
                String  acc = st.Account__c;
                Date dd = Date.newInstance(integer.valueof(st.year__c),monthhh, 1);
                
                Integer numberOfDays = Date.daysInMonth(dd.year(), dd.month());
                Date lastDayOfMonth = Date.newInstance(dd.year(), dd.month(), numberOfDays);
                
                system.debug('sssssssssss'+numberOfDays );
                
                st.Start_Day_of_Month__c = '1';
                st.End_Day_of_Month__c = string.valueof(numberOfDays) ;
                
                if(yr.contains(String.valueof(sm.Year__c)) && mnth.contains(String.valueof(sm.Month__c)) && acc.contains(sm.Account__c)){
                    
                    st.Previous_year_GL_Sales__c = sm.GL_Sales__c;
                    //st.Previous_Year_Comm__c = sm.Land_Comm__c;
                }
            }
        }
    }
}




I am getting errro of CPU time exceed. Please help me! Thanks in advance
Hi All,

I have a trigger to assign Contacts by criteria-based-Round Robin based on Project and Language parameters. The below code query was returning values as long as the Projects field was a picklist, now after I've converted it into a multipicklist, it doesn't seem to return any values. Please asist
 
trigger AssignSalesmanager on contact(before insert , after update)
{
    String currentuser = [Select alias From User Where Id = :UserInfo.getUserId()].alias;
            system.debug(currentuser);
            if(currentuser == 'guest' || currentuser == 'oadmi')
            {
    if(Trigger.isBefore)
    {
        if(Trigger.IsInsert)
        {
            Map<String,List<round_robin__c>> mapOfLangUsers = new  Map<String,List<round_robin__c>>();
            Map<String,List<round_robin__c>> mapOfProjUsers = new  Map<String,List<round_robin__c>>();
           
            map<string,list<contact>> MapoflangandContacts = new map<string,list<contact>>();
            map<string,list<contact>> MapofprojandContacts = new map<string,list<contact>>();
            Set<String> projectValues = new Set<String>();
            String projValues;
            Set<String> langValues = new Set<String>();
            List<Contact> allContacts = new List<contact>();
            Boolean hasModifiedUser = false;
            for(contact eachcontact: trigger.new){
  
               if(!String.isBlank(eachcontact.Language__c) && !String.isBlank(eachcontact.Projects__c)) {
                   allContacts.add(eachcontact);
                   langValues.add(eachcontact.language__c);
                   projectValues.add(eachcontact.projects__c);
                   projvalues= String.valueOf(projectValues);
                     
               }     
             
            }
            
            if(MapoflangandContacts.size() > 0 && MapoflangandContacts!= null) {
            for(string strlang : MapoflangandContacts.keyset()){
                integer i=0;
                for(Contact objContact : MapoflangandContacts.get(strlang)){
                    objContact.ownerid = mapOfLangUsers.get(objContact.Language__c)[i].Round_Robin_User__c;
                    mapOfLangUsers.get(objContact.Language__c)[i].Count__c = mapOfLangUsers.get(objContact.Language__c)[i].Count__c+1;
           
                    i++;
                if(i==mapOfLangUsers.get(objContact.Language__c).size())
                    i=0;
                }
            } 
           
            list<round_robin__c> lstrb = new list<round_robin__c>();
    
            for(list<round_robin__c> lstuser : mapOfLangUsers.values()){
                lstrb.addall(lstuser);
            }  
            update lstrb; 
           
           }
           if(MapofprojandContacts.size() > 0 && MapofprojandContacts!= null) {
               for(string strProject : MapofprojandContacts.keyset()){
                    integer i=0;
                    for(Contact objContact : MapofprojandContacts.get(strProject)){
                        objContact.ownerid = mapOfProjUsers.get(objContact.Projects__c)[i].Round_Robin_User__c;
                        mapOfProjUsers.get(objContact.Projects__c)[i].Count__c = mapOfProjUsers.get(objContact.Projects__c)[i].Count__c+1;
               
                        i++;
                    if(i==mapOfProjUsers.get(objContact.Projects__c).size())
                        i=0;
                    }
                } 
           
                list<round_robin__c> lstrb = new list<round_robin__c>();
        
                for(list<round_robin__c> lstuser : mapOfProjUsers.values()){
                    lstrb.addall(lstuser);
                }  
                update lstrb; 
           }
          
           if(allContacts.size() > 0 && allContacts!=null) {
           Integer recordCount = [select count() from contact];
           system.debug('recordCount='+recordCount);
           Integer rr = [select Count() from round_robin__c where Is_Active__c = TRUE AND Language__c IN:langValues AND Projects__c INCLUDES (:projvalues)   ];
             system.debug('rr='+rr);
             if(rr!=0)
           {
             Integer index = Math.mod(recordCount+1,rr);
            
           list <round_robin__c> lstRoundSpecificUsers  = [select id,name,Count__c,Round_Robin_User__c,Language__c,Projects__c from round_robin__c where Is_Active__c = TRUE AND Language__c IN:langValues AND Projects__c INCLUDES (:projvalues)   ];
               system.debug(lstRoundSpecificUsers  );
               Integer i;
               IF(i==null)
               {i=0;}

               for(contact eachContact : trigger.new) {
                   
                       system.debug('index='+index);
                     eachContact.ownerId = lstRoundSpecificUsers[index].Round_Robin_User__c;
              
                   
               }
               }  
           } 
        } 
      
     }   
     }
    
   if(trigger.isUpdate) { 
       System.debug('----->Entered');
        Map<Id,Id> mapOfContact = new Map<Id,Id>();
        for(Contact con: trigger.new)
         {
             
           if(con.OwnerId != trigger.oldmap.get(con.id).ownerId)
           {
               System.debug('----->Entered111');
              mapOfContact.put(con.Id,con.OwnerId);
          }
        }
        list<pba__Request__c> lstRequest = [select id,name,Contact_Owner__c,pba__Contact__c from pba__Request__c where pba__Contact__c IN:mapOfContact.keySet() ];
        if(lstRequest.size() > 0) {
            for(pba__Request__c eachReq : lstRequest) {
                eachReq.OwnerId = mapOfContact.get(eachReq.pba__Contact__c);
            }
        }
        update lstRequest;
    }
}


The system.debug statement for vairable rr keeps returning as 0 if I compare it with a set of values. It returns rows if I hardcode the values, which I don't want to. I want this to be dynamic.

How do i work around this.

Thanks,

Avinash

Main Object : Case
Child Object : custom_object__c

Conditions:

Create custom_object__c record If ,

1) Case.Survey_Star_Rating__c != null for the cases created last week. create a child record immediately (no other conditions needed).
                   
2) Case.STS__C = true. Create child records per owner 1 in a day and maximum 2 per week if no above records is found for the same owner.
3) Case.CS_Deal__c = true. Create child records per owner 1 in a day and maximum 2 per week if no above records is found for the same owner.

Hint - if 1 survey record is found in last week then this week only 3 more records to be created for points 2 & 3

       if 2 survey record is found     in last week then this week only 2 more records to be created for points 2 & 3
       
       if a record is created for point 2 or 3, no other records should be created today for the same owner.

Child records should be updated with:

1) custom_object__c.Owner = queueid
2) custom_object__c.Case No. = Lookup of case
3) custom_object__c.Agent__c = Case.owner
Hi All,

I have a trigger to assign Contacts by criteria-based-Round Robin based on Project and Language parameters. The below code query was returning values as long as the Projects field was a picklist, now after I've converted it into a multipicklist, it doesn't seem to return any values. Please asist
 
trigger AssignSalesmanager on contact(before insert , after update)
{
    String currentuser = [Select alias From User Where Id = :UserInfo.getUserId()].alias;
            system.debug(currentuser);
            if(currentuser == 'guest' || currentuser == 'oadmi')
            {
    if(Trigger.isBefore)
    {
        if(Trigger.IsInsert)
        {
            Map<String,List<round_robin__c>> mapOfLangUsers = new  Map<String,List<round_robin__c>>();
            Map<String,List<round_robin__c>> mapOfProjUsers = new  Map<String,List<round_robin__c>>();
           
            map<string,list<contact>> MapoflangandContacts = new map<string,list<contact>>();
            map<string,list<contact>> MapofprojandContacts = new map<string,list<contact>>();
            Set<String> projectValues = new Set<String>();
            String projValues;
            Set<String> langValues = new Set<String>();
            List<Contact> allContacts = new List<contact>();
            Boolean hasModifiedUser = false;
            for(contact eachcontact: trigger.new){
  
               if(!String.isBlank(eachcontact.Language__c) && !String.isBlank(eachcontact.Projects__c)) {
                   allContacts.add(eachcontact);
                   langValues.add(eachcontact.language__c);
                   projectValues.add(eachcontact.projects__c);
                   projvalues= String.valueOf(projectValues);
                     
               }     
             
            }
            
            if(MapoflangandContacts.size() > 0 && MapoflangandContacts!= null) {
            for(string strlang : MapoflangandContacts.keyset()){
                integer i=0;
                for(Contact objContact : MapoflangandContacts.get(strlang)){
                    objContact.ownerid = mapOfLangUsers.get(objContact.Language__c)[i].Round_Robin_User__c;
                    mapOfLangUsers.get(objContact.Language__c)[i].Count__c = mapOfLangUsers.get(objContact.Language__c)[i].Count__c+1;
           
                    i++;
                if(i==mapOfLangUsers.get(objContact.Language__c).size())
                    i=0;
                }
            } 
           
            list<round_robin__c> lstrb = new list<round_robin__c>();
    
            for(list<round_robin__c> lstuser : mapOfLangUsers.values()){
                lstrb.addall(lstuser);
            }  
            update lstrb; 
           
           }
           if(MapofprojandContacts.size() > 0 && MapofprojandContacts!= null) {
               for(string strProject : MapofprojandContacts.keyset()){
                    integer i=0;
                    for(Contact objContact : MapofprojandContacts.get(strProject)){
                        objContact.ownerid = mapOfProjUsers.get(objContact.Projects__c)[i].Round_Robin_User__c;
                        mapOfProjUsers.get(objContact.Projects__c)[i].Count__c = mapOfProjUsers.get(objContact.Projects__c)[i].Count__c+1;
               
                        i++;
                    if(i==mapOfProjUsers.get(objContact.Projects__c).size())
                        i=0;
                    }
                } 
           
                list<round_robin__c> lstrb = new list<round_robin__c>();
        
                for(list<round_robin__c> lstuser : mapOfProjUsers.values()){
                    lstrb.addall(lstuser);
                }  
                update lstrb; 
           }
          
           if(allContacts.size() > 0 && allContacts!=null) {
           Integer recordCount = [select count() from contact];
           system.debug('recordCount='+recordCount);
           Integer rr = [select Count() from round_robin__c where Is_Active__c = TRUE AND Language__c IN:langValues AND Projects__c INCLUDES (:projvalues)   ];
             system.debug('rr='+rr);
             if(rr!=0)
           {
             Integer index = Math.mod(recordCount+1,rr);
            
           list <round_robin__c> lstRoundSpecificUsers  = [select id,name,Count__c,Round_Robin_User__c,Language__c,Projects__c from round_robin__c where Is_Active__c = TRUE AND Language__c IN:langValues AND Projects__c INCLUDES (:projvalues)   ];
               system.debug(lstRoundSpecificUsers  );
               Integer i;
               IF(i==null)
               {i=0;}

               for(contact eachContact : trigger.new) {
                   
                       system.debug('index='+index);
                     eachContact.ownerId = lstRoundSpecificUsers[index].Round_Robin_User__c;
              
                   
               }
               }  
           } 
        } 
      
     }   
     }
    
   if(trigger.isUpdate) { 
       System.debug('----->Entered');
        Map<Id,Id> mapOfContact = new Map<Id,Id>();
        for(Contact con: trigger.new)
         {
             
           if(con.OwnerId != trigger.oldmap.get(con.id).ownerId)
           {
               System.debug('----->Entered111');
              mapOfContact.put(con.Id,con.OwnerId);
          }
        }
        list<pba__Request__c> lstRequest = [select id,name,Contact_Owner__c,pba__Contact__c from pba__Request__c where pba__Contact__c IN:mapOfContact.keySet() ];
        if(lstRequest.size() > 0) {
            for(pba__Request__c eachReq : lstRequest) {
                eachReq.OwnerId = mapOfContact.get(eachReq.pba__Contact__c);
            }
        }
        update lstRequest;
    }
}


The system.debug statement for vairable rr keeps returning as 0 if I compare it with a set of values. It returns rows if I hardcode the values, which I don't want to. I want this to be dynamic.

How do i work around this.

Thanks,

Avinash