• Babar Hussain 13
  • NEWBIE
  • 10 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 0
    Replies
Hi Team, 
I have one requirement says, I have to delete the duplicate account related contact records. 
Note: Keep the latest one and delete the old one.
So, I wrote the code but it is always deleting the new records and kept the older ones.
I have to delete the older ones and keep the new ones 
Please correct my code ifany mistakes I did

MY Code :
*********************************************************************
global class deleteDuplicateRecords implements Database.Batchable<sObject>, Schedulable {
    
    global Database.QueryLocator start (Database.BatchableContext bc) { 
        String Query = 'Select Id, Name From Account';
        return Database.getQueryLocator(Query);
    }
    global void execute (Database.BatchableContext bc, List<Account> accList){  
        Set<Id> accId = new Set<Id>();
        for(Account a :accList) {
            accId.add(a.Id);
            }  
        List<Contact> con = [Select Id, Name,AccountId, Lastname  from Contact Where AccountId IN: accId];
        List<Contact> dupList = new List<Contact>();
        Set<String> orderObj = new Set<String>();
        for(Contact a: con) {
            if(orderObj.contains(a.Name)) {
dupList.add(a);
            }
            else {
                orderObj.add(a.Name);
            }
        }
        delete dupList;
        }
    global void finish (Database.BatchableContext bc) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
   String[] toAddresses = new String[] {'babar.sanjamala@sbdinc.com'}; 
   mail.setToAddresses(toAddresses); 
   mail.setSubject('Apex Batch Job is done');
   mail.setPlainTextBody('The batch Apex job processed successfully'); 
   Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
        
    }
    
    global void execute(Schedulablecontext sc) {
        deleteDuplicateRecords Acc = new deleteDuplicateRecords();
        Database.executeBatch(Acc,200);
    }

}
 
**********************************************************************
Thanks


 
Hi Team,
I have one flow exception error, to rectify that I had one solution but how to implement in flows can any =one please suggest me.

Requirement : I have flow fetching list of cases updating case owner and it is failling user is inactive 
Solution : so I have to fetch the cases realted tasks and check if user is inactive update case owner as  some active user
HI Team, 

I have one task updatevthe contacts related to account. I have wrote the apex code but getting error , please check and let me know where I'm making mistake. 

Apex code :

public class updateRelatedAcc {
    public static  void accUpdate (List<Account> accList){
        Set<Id> getUpdateAcc = new Set<Id>();
        for(Account a: accList) {
            getUpdateAcc.add(a.Id);
            
        }
        
        List<Contact> con = [Select Id, Name,AccountId, MailingCity from Contact Where AccountId =: getUpdateAcc];
        List<Contact> updateContacts = new List<Contact>();
        for(Contact c :con) {
            c.MailingCity = a.BillingCity;
            updateContacts.add(c);
        }
        update updateContacts;
        

    }

}

Error Screenshot :

Error

Hi Everyone,

i was struck on the one condition, my requirement is update the contact status Cancelled when Account status is Cancelled but not update if Account status is "Pending"/"In progress". 

I have added my code below , please check let me know how to add that condification or any hints please

 

public class AccountUpdate {
    public void getIds() {
    List<Account> accIds = new List<Account>();
        Set<Id> getIds = new Set<Id>();
        for(Account a :[select Id, Name from Account]) {
            getIds.add(a.Id);   
        }
        System.debug('Print all the Account Ids =>' +getIds);
         //get the related contacts associated to Account
        List<Contact> con = [Select Id, Name, AccountId From Contact Where AccountId IN :getIds];
        System.debug('Print all related Contacts'+con);
        List<Contact> getupdateContacts = new List<Contact>();
        if(Account.Account_Status__c == 'Cancelled'){
            getupdateContacts.add(con);
            }
            update getupdateContacts;
        }
        
    }
    
   
    
    
}
Hi Everyone,
 I have one requirement, I need to display text field based on picklist value selected.
Picklist values : New Contract, SOW/Amendment, Contract Renewal.
Field : Icertis Contract Number

Please anyone knows send the formaula or validation rule, which one to use, If possible please right the validation/ formaula for above reuirement, 
Thanks
 
Hi Everyone,

I have One requirement, Says when case is created by user we need to send an email along witht the case record link.

But right now we don't provided any access to users to see the case recors. 

Now I have to providee the access to case created users, Which case they have created not for all cases/others case records.

Can anyone please share any hints how to share this