• edanna k
  • NEWBIE
  • 115 Points
  • Member since 2017

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 27
    Replies
Hi,

I wrote a simple batch that deletes old reports by using the endpoint /services/data/v44.0/analytics/reports/ (which I stored in a custom label).

Now I'm struggling to write the test class code for the batch below.

Which code could I use to test my batch?

Thanks in advance.
 
global class DeleteOldReportsBatch implements Database.Batchable<sObject>, Database.AllowsCallouts {

    //Get the records to be deleted
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'select id, FolderName from Report where LastRunDate <= LAST_N_DAYS:60 and FolderName = \'Public Reports\' ';
        return Database.getQueryLocator(query);        
    }

    //Executes the deletion logic for reports records
    global void execute(Database.BatchableContext BC, List<Report> scope) {
    String url;

    for(Report r : scope) {                
            Http h = new Http();
            url = System.Label.ReportsApi + r.Id;
            System.debug(LoggingLevel.INFO, '*** url: ' + url);          

            HttpRequest req = new HttpRequest();

            req.setHeader('Authorization', 'Bearer '+ UserInfo.getSessionId());
            req.setMethod('DELETE');
            req.setEndpoint(url);

            HttpResponse res = h.send(req);
            System.debug(LoggingLevel.INFO, '*** rest: ' + res.getBody());        
        } 
    }

    global void finish(Database.BatchableContext BC) {}
}

 
Following is my Before trigger:

trigger GroupClusterMap on Account (before insert, before update) {
    set<string> groupId = new set<string>();
    list<Account> listAccs= new list<Account>();
    list<Outlets_Groups_Primary_Customer__c> groupOutlets = new list<Outlets_Groups_Primary_Customer__c>();
    for(Account acc:trigger.new) {
        if(acc.Group_Name1__c!=NULL)
            groupId.add(acc.Group_Name1__c);
        }
    listAccs = [Select Id, Cluster_Code__c,Group_Name1__c,TL_Code__c from Account where Group_Name1__c IN: groupId limit 1];
    groupOutlets = [Select Id, Lead_TL__c,Name from Outlets_Groups_Primary_Customer__c where Id IN: groupId limit 1];
    if(trigger.isinsert) {
        for(Account aa:trigger.new) {
            for(Account dup:listAccs) {
                if (aa.Group_Name1__c!=NULL && (aa.Group_Name1__c==dup.Group_Name1__c && aa.Cluster_Code__c!=dup.Cluster_Code__c)){
                    aa.adderror('Group is mapped to a Cluster');
                if (aa.Group_Name1__c!=NULL && (aa.Group_Name1__c==dup.Group_Name1__c && aa.TL_Code__c!=dup.TL_Code__c)){
                    for(Outlets_Groups_Primary_Customer__c outgrps: groupOutlets){
                        if(outgrps.Lead_TL__c == NULL || outgrps.Lead_TL__c == '')
                            aa.adderror('Please do a Lead TL mapping in the Group');
                    }
                }                    
                }
                }
            }
        }
    if(trigger.isupdate) {
        for(Account aa:trigger.new){
            for(Account dup:listAccs) {                             
               // if ((aa.Group_Name1__c==dup.Group_Name1__c && aa.Group_Name1__c !=trigger.oldmap.get(aa.id).Group_Name1__c) && (aa.Cluster_Code__c!=dup.Cluster_Code__c && aa.Cluster_Code__c !=trigger.oldmap.get(aa.id).Cluster_Code__c))
                if (aa.Group_Name1__c!=NULL && (aa.Group_Name1__c==dup.Group_Name1__c && aa.Cluster_Code__c!=dup.Cluster_Code__c)){
                    aa.adderror('Group is mapped to a Cluster');
                if (aa.Group_Name1__c!=NULL && (aa.Group_Name1__c==dup.Group_Name1__c && aa.TL_Code__c!=dup.TL_Code__c)){
                    for(Outlets_Groups_Primary_Customer__c outgrps: groupOutlets){
                        if(outgrps.Lead_TL__c == NULL || outgrps.Lead_TL__c == '')
                            aa.adderror('Please do a Lead TL mapping in the Group');
                    }
                  }                    
                }
            } 
        }
    }
}
=========================================================
Following is the test class i had written for it - it only covers 57% code.

@IsTest
public class GroupClusterMapTest {   
    
    static testMethod void GroupClusterMapTest(){
        Id RecordTypeId = Schema.SObjectType.Masters__c.getRecordTypeInfosByName().get('Cluster').getRecordTypeId();
        Masters__c master = New Masters__c();
        master.Cluster_Name__c='RPCSCL004';
        master.Geographic_State__c='ANDHRA PRADESH';
        master.RecordTypeid=RecordTypeId;
        insert master;        
        
        TL_Master__c tl1= new TL_Master__c();
        tl1.Name='APTL004';
        tl1.TL_Territory_Name__c='NORTH COASTAL';
        tl1.Cluster__c=master.id;
        insert tl1;
        
        TSE_Master__c oldTse2 = new TSE_Master__c();
        oldTse2.Name = 'APTS033';
        oldTse2.TSE_Territory_Name__c = 'VISAKHAPATNAM - II AREA-I';
        oldTse2.TL_Code__c=tl1.id;
        insert oldTse2;
        
        Beat_TSE_Mapping__c NewBte1 = new Beat_TSE_Mapping__c();
        NewBte1.Beat_Name__c = 'BEAT 03';
        NewBte1.Name = 'ABBT1130';
        NewBte1.TSE_Code__c = oldTse2.id;
        insert NewBte1;
        
        Outlets_Groups_Primary_Customer__c newGrp = new Outlets_Groups_Primary_Customer__c();
        newGrp.Name = 'mygroup';
        newGrp.Type__c = 'Groups';
        newGrp.State_Group_PC__c = 'ANDHRA PRADESH';
        newGrp.Lead_TL__c = tl1.Id;
        insert newGrp;
        
        Account OldAcc = new Account();        
        OldAcc.Beat_Code__c = NewBte1.Id;
        //OldAcc.Beat_Name__c = oldBte.Beat_Name__c ;
        OldAcc.TSE_Code__c = oldTse2.id;
        //OldAcc.TSE_ID__c = oldBte.TSE_ID__c;
        //OldAcc.TSE_Name__c = oldBte.TSE_Name__c;
        OldAcc.District__c = 'Test District';
        OldAcc.Goegraphy_state__c = 'ANDHRA PRADESH';
        OldAcc.Town__c = 'Test Town';
        OldAcc.Name = 'Test name';
        OldAcc.Market_Type__c = 'Corporation';
        OldAcc.MSL_Town_Tier__c= 'BTNTest';
        OldAcc.Cluster_Code__c=master.Id;
        OldAcc.TSE_Code__c=oldTse2.id;
        OldAcc.Outlet_Type__c='D';
        OldAcc.Beat_Code__c= NewBte1.Id;
        OldAcc.TL_Code__c = tl1.Id;
        OldAcc.Address__c = 'testadd';
        OldAcc.Stock_List__c = 'Tier 1';
        OldAcc.Channel_type__c = 'PrOP';
        OldAcc.Micro_channel__c = 'Prestige Bar';
        OldAcc.Perfect_Outlet__c = 'Yes';
        OldAcc.Group_Outlet__c='No';
        oldAcc.Group_Name1__c = newGrp.Id;
        OldAcc.Contract_type__c = 'Open';
        insert OldAcc;
        
         Account NewAcc = new Account();
        NewAcc.id = OldAcc.id;
        NewAcc.Beat_Code__c = NewBte1.ID;
        //  NewAcc.Beat_Name__c = NewBte.Beat_Name__c ; 
        //NewAcc.TSE_Code__c = oldTse3.id;
        // NewAcc.TSE_ID__c = NewBte.TSE_ID__c;
        // NewAcc.TSE_Name__c = NewBte.TSE_Name__c;
        NewAcc.District__c = 'Test District1';
        NewAcc.Town__c = 'Test Town1';
        NewAcc.Name = 'Test name1';
        oldAcc.Group_Name1__c = newGrp.Id;
        update NewAcc;
    }

}

Your help is greatly appreciated...Thank you !!!
 
i wrote a trigger which is use to create a record on case satus update, but now i have to store all record types in custom setting (so that it is easy to add or remove) based on requirment ,can someone please help me to create custom settings ,i am not sure ow to call custom setting under if condition.

Thanks in advance
Hi , i need help. i need a test class for this method from the class name, ASPP_PaymentSource_Controller.cls
@AuraEnabled
    public static Map<String, String> savePS(ASPayment_Source__c ps, String gatewayId){
        System.debug('PS Handed: ' + ps);
        if(ps != null){
            Map<String, String> info = new Map<String, String>();

            Id cardRT = RecordTypeHelper.getRecordTypeIDByName('ASPayment_Source__c', 'Credit_Card');
            Id bankRT = RecordTypeHelper.getRecordTypeIDByName('ASPayment_Source__c', 'Bank');

            if(ps.RecordTypeId == cardRT || ps.RecordTypeId == bankRT){
                try{
                    upsert ps;
                    
                    info.put('message', 'Payment Source successfully created/udpdated.');
                    info.put('id', ps.Id);
                    info.put('isSucess', 'true');

                    return info;
                }catch(Exception e){
                    info.put('message', e.getMessage());
                    info.put('isSucess', 'false');

                    return info;
                }
            }// end if
            
            // Validate if Payment Source have contact or account
            if(ps.PPContact__c == null && ps.Account__c == null){
                info.put('message', 'Payment Source requires either Account or Contact.');
                info.put('isSucess', 'false');

                return info;
            }

            Map<String, String> result = new Map<String, String>();
            
            if(ps.Id != null){
                ASPayment_Source__c oldPS = [Select Id, Name, RecordTypeId, Account__c, 
                                                 PPContact__c, Active__c, Gateway_Payment_Type__c, 
                                                 Card_Name__c, Card_Expiry_Month__c, 
                                                 Card_Expiry_Year__c, token_Card_CCV__c, 
                                                 token_Card_Number__c, Credit_Card_Type__c, 
                                                 Account_BSB__c, Account_Name__c, 
                                                 token_Account_Number__c 
                                             FROM ASPayment_Source__c 
                                             WHERE Id =: ps.Id];
                
                if(oldPS != null){
                    if((ps.Gateway_Payment_Type__c == 'Bank' && (ps.Account_Name__c == oldPS.Account_Name__c && ps.Account_BSB__c == oldPS.Account_BSB__c && ps.token_Account_Number__c == oldPS.token_Account_Number__c)) || 
                        (ps.Gateway_Payment_Type__c == 'Credit Card' && (ps.Card_Name__c == oldPS.Card_Name__c && ps.token_Card_Number__c == oldPS.token_Card_Number__c && ps.Credit_Card_Type__c == oldPS.Credit_Card_Type__c && ps.Card_Expiry_Month__c == oldPS.Card_Expiry_Month__c && ps.Card_Expiry_Year__c == oldPS.Card_Expiry_Year__c && PS.token_Card_CCV__c == oldPS.token_Card_CCV__c))) 
                    {
                        try{
                            update ps;
                            result.put('PaymentSourceID',String.valueOf(ps.Id));
                            result.put('status','200');
                            result.put('message','Payment Source Updated');
                        }catch(Exception e){
                            result.put('status','500');
                            result.put('message',e.getMessage());
                        }
                    } else result = ProcessPayment.setPS(ps, gatewayId);
                } //end of if(oldPS != null)
            }else{
                if(ps.Gateway_Payment_Type__c == 'Credit Card'){
                    ps.Account_Name__c = null;
                    ps.token_Account_Number__c = null;
                    ps.Account_BSB__c = null;
                }else {
                    ps.Card_Name__c = null;
                    ps.token_Card_Number__c  = null;
                    ps.Credit_Card_Type__c = null;
                    ps.Card_Expiry_Month__c = null;
                    ps.Card_Expiry_Year__c = null;
                    ps.Card_CCV__c = null;
                }
                
                result = ProcessPayment.setPS(ps, gatewayId); 
            } 
            
            info.put('message', result.get('message'));
            if(result.get('status') !=  '500'){
                info.put('id', result.get('PaymentSourceID'));
                info.put('isSucess', 'true');
            }else info.put('isSucess', 'false');
            
            return info;    
        }else return null;
    }
thanks in advance..
 
Following is my requirement Please Help Me. 
I want to write an Apex Trigger based on Particular Role Hierarchy (XYZ is my role Name).  If the users are not blank in XYZ Role then fetch those users and add the same users in ABC object's field User(This is a custom picklist field of ABC object). 

Can anyone help me to achieve this  Many Thanks in advance. 

if we add/delete/Update user in XYZ roles then same will reflect on the ABC objects picklist fields named as User. 
Hi,

I wrote a simple batch that deletes old reports by using the endpoint /services/data/v44.0/analytics/reports/ (which I stored in a custom label).

Now I'm struggling to write the test class code for the batch below.

Which code could I use to test my batch?

Thanks in advance.
 
global class DeleteOldReportsBatch implements Database.Batchable<sObject>, Database.AllowsCallouts {

    //Get the records to be deleted
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'select id, FolderName from Report where LastRunDate <= LAST_N_DAYS:60 and FolderName = \'Public Reports\' ';
        return Database.getQueryLocator(query);        
    }

    //Executes the deletion logic for reports records
    global void execute(Database.BatchableContext BC, List<Report> scope) {
    String url;

    for(Report r : scope) {                
            Http h = new Http();
            url = System.Label.ReportsApi + r.Id;
            System.debug(LoggingLevel.INFO, '*** url: ' + url);          

            HttpRequest req = new HttpRequest();

            req.setHeader('Authorization', 'Bearer '+ UserInfo.getSessionId());
            req.setMethod('DELETE');
            req.setEndpoint(url);

            HttpResponse res = h.send(req);
            System.debug(LoggingLevel.INFO, '*** rest: ' + res.getBody());        
        } 
    }

    global void finish(Database.BatchableContext BC) {}
}

 
Hello,

Here is a simple query in Apex:
 
public class edf {

    public list <Asset__c> accaccount {get;set;}
    public String researchKey {get;set;}
 
    public edf( ) {
    }
    
    public void research(){

        researchKey='a1H200000006MCoEAM';
        String searchqueryaccount;
        String Idie='00120000013UXzOAAW';
        
        searchqueryaccount='SELECT Id, Account__r.Name FROM Asset__c WHERE (Asset__c.Product_Strategy__r.Product_ID_18__c LIKE \'%'+researchKey+'%\' AND Account__r.Account_ID_18__c LIKE \'%'+Idie+'%\')';
        
        accaccount= Database.query(searchqueryaccount);
        
    }
    }



And here is the VisualForce code:
 
<apex:page Controller="edf" action="{!research}"> 
    
    <apex:form >

        <apex:pageBlock title="Assets">
            
            <apex:repeat value="{!accaccount}" var="a">
                
                {!a.Id}

            </apex:repeat>
            
        </apex:pageBlock>
     
    </apex:form>
    </apex:page>



It is supposed to simply return Asset IDs for a certain Product ID and a certain Account ID.

The problem is: it does return 10 results whereas I get 32 results with the same SOQL query in Workbench Salesforce.

Could you please help me understand what is wrong with my code? It should be returning 32 results as well.

 
it tried with this but not working SELECT Name, (SELECT Id, Name  From Sales_Order_Line_Item__r) FROM Sales_Order__c 
Hi Experts, 
Is it Possible to get Multiple Charts for Reports from Dashboard in Vf page.

Thanks Swetha
public void validateData() {
        
        Boolean isErrorLogACall = FALSE;
        Boolean isErrorFollowUpTask = FALSE;
        Boolean isErrorOpenTasks = FALSE;
        Boolean PropState;
        
        
        
         if(AccountInfo.PersonMobilePhone!=null && AccountInfo.PersonMobilePhone!='')
           {
              if(LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.PersonMobilePhone,AccountInfo.Id))
              {
              System.debug('Duplicate Mobile 1: ');
               AccountInfo.PersonMobilePhone.addError('Duplicate : '+AccountInfo.PersonMobilePhone);
               isError = TRUE;
                     return;
              }
           }    
           
          if(AccountInfo.Mobile_2__c !=null && AccountInfo.Mobile_2__c!='')
           {
              if(LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.Mobile_2__c ,AccountInfo.Id))
              {
               AccountInfo.Mobile_2__c.addError('Duplicate : '+AccountInfo.Mobile_2__c );
               isError = TRUE;
                     return;
              }
           }    
           
         
           
           
             if(AccountInfo.PersonEmail!=null &&AccountInfo.PersonEmail!='')
           {
              if(LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.PersonEmail,AccountInfo.Id))
              {
               AccountInfo.PersonEmail.addError('Duplicate : '+AccountInfo.PersonEmail);
               isError = TRUE;
                     return;
              }
           }       
        
        
        
        //JJ - 04/27/2016
        
        
        if(AccountInfo.City_Village__c != null && AccountInfo.City_Village__c != '')
        {
            List<Village_City__c> lstCityVill = new List<Village_City__c>();
            
            lstCityVill = HandlerClass.getVillageCityAutocomplete(AccountInfo.City_Village__c, '');
            
            //Case Sensitive Logic
            for(Village_City__c recTaluka :lstCityVill)
            {
                PropState = AccountInfo.City_Village__c.equals(recTaluka.Name);  
                if(PropState) break;                  
            }
            //Case Sensitive Logic - End.
                        
             if(lstCityVill.isEmpty())
             {
                    AccountInfo.City_Village__c.addError('This Communication City/Village value is not available.');
                    isError = true;
             }
             else if(PropState == FALSE)
             {
                AccountInfo.City_Village__c.addError('This Case Sensitive Communication City/Village value is not available.');
                isError = true;
             }
        }
    }    
Here I am trying to get value dynamically from few different fields include, Account, Status, Tracker, Priority, ContactEmail and list down the list of case that matchs the criteria.

When I execute the below code I am getting  system.QueryException: invalid ID field: null

@RestResource(urlMapping='/QueryFilterStatus/*')
global with sharing class QueryFilterStatus{
    
    @HttpPost
    global static List<Case> dopostCase(String accountid,String tracker,String priority,String contactEmail,String status,String CStatus,String subject, String Keyword, String accid) {
    List<Case> caseList = new List<Case>();
    String str='Select id, Case_Owner_Name__c, OwneEmail__c, Description, Subject, Case_Type__c, Code__c, Tracker__c, status, Version__c, type, priority, ContactEmail, ContactId, OwnerId, CaseNumber, CSM_ID__c, CUP_Phone__c, Call_Type__c, IsClosed from Case where accountid =\''+ null +'\'';
    
    if(String.isBlank(accid))
    {
       str+=' AND AccountId=\''+ accid+'\'';
    }
    if(String.isNotBlank(tracker))
    {
       str+=' AND Tracker__c =\''+ tracker+'\'';
    }
     if(String.isNotBlank(priority))
    {
       str+=' AND Priority=\''+ priority+'\'';
    }
     if(String.isNotBlank(contactEmail))
    {
       str+=' AND ContactEmail=\''+ contactEmail+'\'';
    }
     if(String.isNotBlank(status))
    {
       str+=' AND Status =\''+ status+'\'';
    }
    
    if(String.isNotBlank(CStatus))
    {
       str+=' AND CStatus__c=\''+ CStatus+'\'';
    }
    if(String.isNotBlank(Keyword))
   {
      str+=' AND (Subject Like\''+ Keyword+'\'';
      str+=' OR CaseNumber Like \'%'+ Keyword+'%\')';
   }  
   System.debug(str);
    caseList=Database.query(str);
    return caseList;
    
    
}
}
Following is my Before trigger:

trigger GroupClusterMap on Account (before insert, before update) {
    set<string> groupId = new set<string>();
    list<Account> listAccs= new list<Account>();
    list<Outlets_Groups_Primary_Customer__c> groupOutlets = new list<Outlets_Groups_Primary_Customer__c>();
    for(Account acc:trigger.new) {
        if(acc.Group_Name1__c!=NULL)
            groupId.add(acc.Group_Name1__c);
        }
    listAccs = [Select Id, Cluster_Code__c,Group_Name1__c,TL_Code__c from Account where Group_Name1__c IN: groupId limit 1];
    groupOutlets = [Select Id, Lead_TL__c,Name from Outlets_Groups_Primary_Customer__c where Id IN: groupId limit 1];
    if(trigger.isinsert) {
        for(Account aa:trigger.new) {
            for(Account dup:listAccs) {
                if (aa.Group_Name1__c!=NULL && (aa.Group_Name1__c==dup.Group_Name1__c && aa.Cluster_Code__c!=dup.Cluster_Code__c)){
                    aa.adderror('Group is mapped to a Cluster');
                if (aa.Group_Name1__c!=NULL && (aa.Group_Name1__c==dup.Group_Name1__c && aa.TL_Code__c!=dup.TL_Code__c)){
                    for(Outlets_Groups_Primary_Customer__c outgrps: groupOutlets){
                        if(outgrps.Lead_TL__c == NULL || outgrps.Lead_TL__c == '')
                            aa.adderror('Please do a Lead TL mapping in the Group');
                    }
                }                    
                }
                }
            }
        }
    if(trigger.isupdate) {
        for(Account aa:trigger.new){
            for(Account dup:listAccs) {                             
               // if ((aa.Group_Name1__c==dup.Group_Name1__c && aa.Group_Name1__c !=trigger.oldmap.get(aa.id).Group_Name1__c) && (aa.Cluster_Code__c!=dup.Cluster_Code__c && aa.Cluster_Code__c !=trigger.oldmap.get(aa.id).Cluster_Code__c))
                if (aa.Group_Name1__c!=NULL && (aa.Group_Name1__c==dup.Group_Name1__c && aa.Cluster_Code__c!=dup.Cluster_Code__c)){
                    aa.adderror('Group is mapped to a Cluster');
                if (aa.Group_Name1__c!=NULL && (aa.Group_Name1__c==dup.Group_Name1__c && aa.TL_Code__c!=dup.TL_Code__c)){
                    for(Outlets_Groups_Primary_Customer__c outgrps: groupOutlets){
                        if(outgrps.Lead_TL__c == NULL || outgrps.Lead_TL__c == '')
                            aa.adderror('Please do a Lead TL mapping in the Group');
                    }
                  }                    
                }
            } 
        }
    }
}
=========================================================
Following is the test class i had written for it - it only covers 57% code.

@IsTest
public class GroupClusterMapTest {   
    
    static testMethod void GroupClusterMapTest(){
        Id RecordTypeId = Schema.SObjectType.Masters__c.getRecordTypeInfosByName().get('Cluster').getRecordTypeId();
        Masters__c master = New Masters__c();
        master.Cluster_Name__c='RPCSCL004';
        master.Geographic_State__c='ANDHRA PRADESH';
        master.RecordTypeid=RecordTypeId;
        insert master;        
        
        TL_Master__c tl1= new TL_Master__c();
        tl1.Name='APTL004';
        tl1.TL_Territory_Name__c='NORTH COASTAL';
        tl1.Cluster__c=master.id;
        insert tl1;
        
        TSE_Master__c oldTse2 = new TSE_Master__c();
        oldTse2.Name = 'APTS033';
        oldTse2.TSE_Territory_Name__c = 'VISAKHAPATNAM - II AREA-I';
        oldTse2.TL_Code__c=tl1.id;
        insert oldTse2;
        
        Beat_TSE_Mapping__c NewBte1 = new Beat_TSE_Mapping__c();
        NewBte1.Beat_Name__c = 'BEAT 03';
        NewBte1.Name = 'ABBT1130';
        NewBte1.TSE_Code__c = oldTse2.id;
        insert NewBte1;
        
        Outlets_Groups_Primary_Customer__c newGrp = new Outlets_Groups_Primary_Customer__c();
        newGrp.Name = 'mygroup';
        newGrp.Type__c = 'Groups';
        newGrp.State_Group_PC__c = 'ANDHRA PRADESH';
        newGrp.Lead_TL__c = tl1.Id;
        insert newGrp;
        
        Account OldAcc = new Account();        
        OldAcc.Beat_Code__c = NewBte1.Id;
        //OldAcc.Beat_Name__c = oldBte.Beat_Name__c ;
        OldAcc.TSE_Code__c = oldTse2.id;
        //OldAcc.TSE_ID__c = oldBte.TSE_ID__c;
        //OldAcc.TSE_Name__c = oldBte.TSE_Name__c;
        OldAcc.District__c = 'Test District';
        OldAcc.Goegraphy_state__c = 'ANDHRA PRADESH';
        OldAcc.Town__c = 'Test Town';
        OldAcc.Name = 'Test name';
        OldAcc.Market_Type__c = 'Corporation';
        OldAcc.MSL_Town_Tier__c= 'BTNTest';
        OldAcc.Cluster_Code__c=master.Id;
        OldAcc.TSE_Code__c=oldTse2.id;
        OldAcc.Outlet_Type__c='D';
        OldAcc.Beat_Code__c= NewBte1.Id;
        OldAcc.TL_Code__c = tl1.Id;
        OldAcc.Address__c = 'testadd';
        OldAcc.Stock_List__c = 'Tier 1';
        OldAcc.Channel_type__c = 'PrOP';
        OldAcc.Micro_channel__c = 'Prestige Bar';
        OldAcc.Perfect_Outlet__c = 'Yes';
        OldAcc.Group_Outlet__c='No';
        oldAcc.Group_Name1__c = newGrp.Id;
        OldAcc.Contract_type__c = 'Open';
        insert OldAcc;
        
         Account NewAcc = new Account();
        NewAcc.id = OldAcc.id;
        NewAcc.Beat_Code__c = NewBte1.ID;
        //  NewAcc.Beat_Name__c = NewBte.Beat_Name__c ; 
        //NewAcc.TSE_Code__c = oldTse3.id;
        // NewAcc.TSE_ID__c = NewBte.TSE_ID__c;
        // NewAcc.TSE_Name__c = NewBte.TSE_Name__c;
        NewAcc.District__c = 'Test District1';
        NewAcc.Town__c = 'Test Town1';
        NewAcc.Name = 'Test name1';
        oldAcc.Group_Name1__c = newGrp.Id;
        update NewAcc;
    }

}

Your help is greatly appreciated...Thank you !!!
 
Hi All,

We are creating one lead at a time from operation custom object on some conditions met I want to do owner assignment in such way that if
1) existing operation BD Name is A then created lead from that operation record should goes to A,If BD name on operation record is B then lead goes to B and BD name on operation  is C then lead goes to C and 2) if BD name is other than A,B,C then lead goes to sequential among these three A,B,C .

For example, If BD Name on operation record is X then that lead goes to A,If BD name on operation is Y then Lead goes to B, BD name on operation is Z lead goes to C , BD Name on Operation is Q again lead goes to A and like wise

I have tried below code:
This code is working for First Scenario but for Second scenario it is Assigning first user in the list to every leads

global class SendMailtoLeadCreatedFromOperation{
    
    map<String,id> tempMap = new map<String,id>();
      
    global list<id> distributedInuserIDList = new list<id>();
   
    global SendMailtoLeadCreatedFromOperation(){
        tempMap = fetchOwnerForAssignment();
        system.Debug('---tempMap Map---'+ tempMap);
    }
    
    
    public void OwnerAssignment(list<Lead> ownerassignlist){
        
        system.debug('---ownerassignlist---'+ownerassignlist);
        
        list<User> distributedUsersList = [Select id,name from User where Website_Services__c = true];
         system.debug('---distributedUsersList---'+distributedUsersList+'---Size distributedUsersList---'+distributedUsersList.size());
        
        for(User temp : distributedUsersList){
            distributedInuserIDList.add(temp.id);
          }
         system.debug('---distributedInuserIDList---'+distributedInuserIDList);
          
          for(Lead scheduledoperation : ownerassignlist){
          
               if(tempMap.containskey(scheduledoperation.BDE_Name__c)){ 
                  
                  scheduledoperation.OwnerID = tempMap.get(scheduledoperation.BDE_Name__c);
                  scheduledoperation.User__c = tempMap.get(scheduledoperation.BDE_Name__c);
                     
                     
                }else{
                    
                    scheduledoperation.OwnerID = distributedInuserIDList.get(0);
                    scheduledoperation.User__c = distributedInuserIDList.get(0);
                     
                    system.debug('---ownerid is---'+scheduledoperation.OwnerID); 
                                     
                    distributedInuserIDList.add(scheduledoperation.User__c);
                    distributedInuserIDList.remove(0);
                    }
                    system.debug('---distributedInuserIDList contain---'+distributedInuserIDList+'---distributedInuserIDList SIZE---'+distributedInuserIDList.size());
            }   
    }
    
   
     public map<String,String> fetchOwnerForAssignment(){
    
        list<WebInternalLeadOwnerAssignmentCS__c> csList = [Select BDE_Name__c,UserId__c
                                                             from WebInternalLeadOwnerAssignmentCS__c
                                                             where isActive__c =: true];  
        system.debug('----csList---'+csList+'--csList size--'+csList.size()); 
        
        
            for(WebInternalLeadOwnerAssignmentCS__c temp : csList){
                if(tempMap.containskey(temp.BDE_Name__c))
                    tempMap.get(temp.BDE_Name__c);
                    else
                     tempMap.put(temp.BDE_Name__c,temp.UserId__c);
            }
            system.debug('----tempMap---'+tempMap+'--tempMap size--'+tempMap.size());
            return tempMap;
    }
    
 }



Can anyone help if possible
  • December 04, 2018
  • Like
  • 0