• Gaurav Sinha 27
  • NEWBIE
  • 35 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 7
    Replies
Hi All Veterans

I have created a component to search account data from external server. We have two of the search criterias as Country and State. Country is a picklist and state we have to create a autocomplete component based on the country selected, i am getting the country and corresponding state values from the apex controller in doinit method and storing it in attribute countrypicklistvalue and statepicklistvalue respectively. can anyone help me in creating the autocomplete ui:inputtext field please.
Thanks in advance

Gaurav Sinha
Hi all Veterans
I have a lightning account search page, where one of the search criteria is Country(Picklist). I am populating country picklist value from apex class. There is one more field called State. Now the requirement is that the Country picklist value should be set default to the logged in user's country and while we type in state field its should show option to autocomplete the field. Lets say selected country is India, so when we type 'ka' in state field it should show options starting with 'ka ' for rg. Karnataka and so on. Any help will be highly appreciated as its an urgent requirement.

Thanks in Advance
Gaurav Sinha
Hi All Veterans

Is there any way we can do Fuzzy match of strings in salesforce, lets say we want to compare the value of first name of a contact to find the duplicate based on fuzzy match. 

Thanks and regards
Gaurav Sinha
Hi all Veteran

We have a requirement wherein we have to create a lightning page where we have to search account data from external server. attached is the screenshot for the page layout. can anyone help me in that please.
User-added image
Hi All Veterans
We have a requirement wherein we have to write a trigger on contact after update. There will be a field called IsDeleted in contacts, when that field will be selected the contact will automatically get associated with a private account. Now the challenge is we have to create the  private account dynamically. Before associating the contact we have to check if that pfivate account contains 10000 contacts if yes then create a new private account and associate that contact with the newly created private account else with the previous account, this process will continue.

Thanks in advance...:)
HI all
Can anyone help me in writing a test class for below class.
Public Class QuotationController
{
   
    Public quoteInfo Quote {get;set;}     
    private final Quotation__c QuotationRec;

    public QuotationController(ApexPages.StandardController controller) {
        QuotationRec=(Quotation__c)controller.getRecord();
        Quotation__c QuotationRec=getQuotationRec(QuotationRec.Id);
        getQuote(QuotationRec);
    }
    
    Public quoteInfo getQuote(Quotation__c Quotation)
    {
        Query__c Query=[Select Id,Name,Client__c,Destination__c,Duration__c,Hotel_Category__c,Meal_Plan__c,Source__c from Query__c where Id=:Quotation.Query__c];
        
        Quote=New quoteInfo();
        Quote.QuoteNumber=Quotation.Name;
        Quote.Client=getContactInfo(Query.Client__c);
        Quote.QuotationValidTill=Quotation.Quotation_Valid_Till__c; 
        Quote.companyinfoRec=getcompanyInfo(Quotation.Id);
        Quote.hotelInfoList=gethotelInfo(Quotation.Id);     
        Quote.excursionInfoList=getexcursionInfo(Quotation.Id); 
        Quote.source=getDestinationInfo(Query.Source__c);
        Quote.destination=getDestinationInfo(Query.Destination__c); 
        Quote.HotelCharge=Quotation.Hotel_Charge__c;    
        Quote.ExcursionCharge=Quotation.Excursion_Charge__c;    
        Quote.GST=Quotation.GST__c; 
        Quote.PackageCost=Quotation.Package_Cost__c;
        Quote.Markup=Quotation.Markup__c;
        Quote.Itinerary=Quotation.Itinerary__c;     
        Quote.ProposedByName=Quotation.Createdby.Name;          
        System.debug('<===Quote==>'+Quote);
        return Quote;
    }    
    
    Public Quotation__c getQuotationRec(String QuotationId)
    {
        Quotation__c Q=[SELECT Createdby.Name,Excursion_Charge__c,GST__c,Hotel_Charge__c,Id,Itinerary__c,Markup__c,Name,Package_Cost__c,Query__c,Quotation_Valid_Till__c,Quoted_By__c,Status__c FROM Quotation__c Where Id=:QuotationId];
        return Q;
    }    
    
    Public Contact getContactInfo(String ContactId)
    {
       System.debug('<==ContactId==>'+ContactId);
        Contact C=[Select Id,Name,Email,MailingStreet,MailingCity,MailingPostalCode ,MailingCountry,HomePhone  From Contact Where Id=:ContactId];
        return C;
    }   
    
    Public Destination__c getDestinationInfo(String DestinationId)
    {
        Destination__c D=[Select Id,Name,Country__c From Destination__c Where Id=:DestinationId];
        return D;
    }      
    
    
    Public companyInfo getcompanyInfo(String QuoteId)
    {
        Company_Information__c CompInf=Company_Information__c.getInstance(UserInfo.getOrganizationId());
        companyInfo CI=New companyInfo();       
        CI.Name=CompInf.Name;
        CI.Address=CompInf.Address__c;
        CI.Email=CompInf.Email__c;
        CI.Phone=CompInf.Mobile__c;
        CI.Website=CompInf.Website__c;
        CI.Follow=CompInf.Follow_on_Facebook__c;        
        return CI;
    }
    
    Public List<hotelInfo> gethotelInfo(String QuoteId)
    {
        List<hotelInfo>hotelInfoList=New List<hotelInfo>();
        List<Hotel__c>HotelList=New List<Hotel__c>();   
        Map<Id,Hotel_Information__c>HotelInfoMap=New Map<Id,Hotel_Information__c>();        
        Set<Id>HotelIds=New Set<Id>();
        
        List<Hotel_Information__c>HIlist=[Select ID,Hotel__c,Hotel_Charge__c,Request__c,Payable_Amount__c from Hotel_Information__c where Quotation__c=:QuoteId];
        for(Hotel_Information__c E:HIlist )
        {
            HotelInfoMap.put(E.Hotel__c,E);
            HotelIds.add(E.Hotel__c);
        }
        
        HotelList=[Select Id,Name,Rate__c,Category__c,City__c,Country__c,State__c from Hotel__c where id=:HotelIds];
        
        for(Hotel__c E:HotelList)
        {
            Hotel_Information__c HIN=HotelInfoMap.get(E.Id);
            hotelInfo HI=New hotelInfo();
            HI.Name=E.Name;
            HI.Category=E.Category__c;  
            HI.City=E.City__c;  
            HI.Country=E.Country__c;                
            HI.Rate=E.Rate__c;  
            HI.NumberofNights=HIN.Request__c;
            HI.Amount=HIN.Payable_Amount__c;            
            hotelInfoList.add(HI);          
        }
                
        return hotelInfoList;     
    }       
    
    Public List<excursionInfo> getexcursionInfo(String QuoteId)
    {
        List<excursionInfo>excursionInfoList=New List<excursionInfo>();
        List<Excursions__c>ExcursionsList=New List<Excursions__c>();    
        Map<Id,Excursion_INformation__c>ExcursionMap=New Map<Id,Excursion_INformation__c>();        
        Set<Id>ExcursionIds=New Set<Id>();
        
        List<Excursion_INformation__c>EIlist=[Select ID,Excursion__c,Excursion_Charge__c,Number_of_Persons__c,Payable_Amount__c from Excursion_INformation__c where Quotation__c=:QuoteId];
        for(Excursion_INformation__c E:EIlist )
        {
            ExcursionMap.put(E.Excursion__c,E);
            ExcursionIds.add(E.Excursion__c);
        }
        
        ExcursionsList=[Select Id,Name,Rate__c from Excursions__c where id=:ExcursionIds];
        
        for(Excursions__c E:ExcursionsList)
        {
            Excursion_INformation__c EIN=ExcursionMap.get(E.Id);
            excursionInfo EI=New excursionInfo();
            EI.Name=E.Name;
            EI.Rate=E.Rate__c;      
            EI.NumberofPerson=EIN.Number_of_Persons__c;   
            EI.Amount=EIN.Payable_Amount__c;
            excursionInfoList.add(EI);          
        }
                
        return excursionInfoList;     
    }       


    Public class quoteInfo
    {
        public string QuoteNumber {get;set;}
        public contact Client {get;set;}
        public Date QuotationValidTill {get;set;}       
        public companyInfo companyinfoRec {get;set;}
        public list<hotelInfo> hotelInfoList {get;set;}
        public list<excursionInfo> excursionInfoList {get;set;}
        public Destination__c source {get;set;}
        public Destination__c destination {get;set;}
        public Decimal HotelCharge {get;set;}
        public Decimal ExcursionCharge {get;set;}
        public Decimal GST {get;set;}
        public Decimal PackageCost {get;set;}   
        public Decimal Markup {get;set;}    
        public string Itinerary {get;set;}     
        public string ProposedByName {get;set;}                       
    }


    Public class companyInfo
    {
        public string Name {get;set;}
        public string Address {get;set;}
        public string Email {get;set;}
        public string Phone {get;set;}
        public string Website {get;set;}
        public string Follow{get;set;}        
    }
    
    Public class hotelInfo
    {
        public string Name {get;set;}
        public string Category {get;set;}
        public string City {get;set;}
        public string Country {get;set;}        
        public Decimal Rate {get;set;}
        public Decimal NumberofNights {get;set;}
        public Decimal Amount {get;set;}
    }       
    
    Public class excursionInfo
    {
        public string Name {get;set;}
        public Decimal Rate {get;set;}
        public Decimal NumberofPerson {get;set;}
        public Decimal Amount {get;set;}
    } 
    
             
}
Hi all Veterans
We have a requirement wherein we need to call a class which performs a callout to sync account with external system inside a batch apex and after the sync is success we need to update a particular field in the synced account. Can anyone help me to achieve this?
Thanks
Gaurav Sinha
Hi all Veterans
We have a requirement wherein we have to sync the account record with an external server. In account there would be a checkbox to select to sync, if the checkbox will be selected the sync should be processed asynchronously and after the sync is successfully done the checkbox should be set to false. I would appreciate if someone can help me with the complete code.
Thanks in advance.
Below is the class to merge contacts based on merge criteria defined. Can someone help me in writing a test class for the same. Need to deploy it by EOD.
global class ContactMergeBatch implements Database.Batchable<AggregateResult>, Database.Stateful
{
    private String query;
    private String dupBy;
    private String pastNDays; 
    private Integer BatchSize;  
    private Set<ID> accIds;
    private Set<String> previousQualifiedIds = new Set<String>();  
    private Set<String> skipEmails;   
    private List<String> recipientEmails;      
    private String CustomerRTId=Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Customer').getRecordTypeId();   
    private String ConsumerRTId=Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Consumer').getRecordTypeId(); 
    private Map<String,ContactMergeWrappper> mergeDupMap;  
    private Map<String,DateTime> createdDateMap;    
    private List<ContactMergeWrappper>MergeStatusList;   
    Private Integer MergeCount;   

    
    global ContactMergeBatch(String pnds,String db,Set<String> pqIds,Map<String,DateTime>cdbm)
    {
        dupBy=db;
        pastNDays=pnds; 
        previousQualifiedIds=pqIds;
        createdDateMap=cdbm; 
              
        mergeDupMap = new Map<String,ContactMergeWrappper>();
        MergeStatusList=New List<ContactMergeWrappper>();        
        
        EMDM_Schedule_Job_Config__c config= EMDM_Schedule_Job_Config__c.getvalues('Contact Merge Batch');
        pastNDays=config.Last_N_Days__c; 
        BatchSize=Integer.Valueof(config.BatchLoad__c); 
        
        skipEmails = new Set<String>(config.Skip_Email_List__c.split(','));
        recipientEmails= new List<String>(config.Confirmation_Recipient__c.split(','));        
                                           
        if(dupBy == 'PersonId') query = 'Select AccountId from Contact where AccountId !=null and CreatedDate = LAST_N_DAYS:'+pastNDays+' and ( RecordTypeId=\''+CustomerRTId+'\' OR RecordTypeId=\''+ConsumerRTId+'\') and IsActive__c=true GROUP BY AccountId';
        else 
        {
            if(previousQualifiedIds.size()>0)
            {
                String pIds = String.join(new List<String>(previousQualifiedIds), '\',\'');
                pIds='(\''+pIds+'\')';
                System.debug('pIds==>'+pIds);
                query = 'Select AccountId from Contact where ( AccountId !=null and CreatedDate = LAST_N_DAYS:'+pastNDays+' and ( RecordTypeId=\''+CustomerRTId+'\' OR RecordTypeId=\''+ConsumerRTId+'\') and IsActive__c=true ) OR AccountId IN '+pIds+' GROUP BY AccountId';
            }
            else
            {
                query = 'Select AccountId from Contact where  AccountId !=null and CreatedDate = LAST_N_DAYS:'+pastNDays+' and ( RecordTypeId=\''+CustomerRTId+'\' OR RecordTypeId=\''+ConsumerRTId+'\') and IsActive__c=true GROUP BY AccountId';
            }   
        }
        
        System.debug('mergeBy==>'+dupBy+' pastNDays==>'+pastNDays+ ' query==>'+query);  
    }
        
    //The batch job starts  if(a!=null) 
    global Iterable<AggregateResult> start(Database.BatchableContext bc)
    {
        return new AggregateResultIterable(query);
    } 
    
    
    global void execute(Database.BatchableContext bc, List<sObject> scope)
    {   
        accIds=new Set<ID>();
        for(sObject a : scope) accIds.add((Id)a.get('AccountId'));
        System.debug('accIds==>'+accIds.size()); 
               
        List<Contact>QualifiedContacts=[SELECT id,Accountid,Salutation,FirstName,Second_Name__c,LastName,Phone,Separation_Contact__c,Preferred_Method_of_Contact__c,Preferred_Language__c,IsActive__c,Service_Sales_Contact__c,Phonetic_First_Name__c,Phonetic_Second_Name__c ,Phonetic_Last_Name__c ,First_Name_Local__c,Second_Name_Local__c,Last_Name_Local__c,Title,Standardized_Title__c,Phone__c,Work_Phone_Extension__c,MobilePhone,HomePhone,Email,Key_Contact_to__c,DoNotCall,Left_Company__c,Isolation_Status__c,Isolation_Status_Date__c,GDPR_Governed__c,Isolation_Comment__c,Teleoptin_Required__c,Preferred_Subjects__c,Job_Seniority__c,Lead_Source_Most_Recent__c,Job_Responsibilities__c,MDM_ContactSync_Status__c,Suppress_Marketing__c,Suppression_Start_Date__c,Suppression_End_Date__c,Description,Job_Role__c,Business_Function__c,Industry__c,BU_Lead__c, Lead_Source_Original1__c, HP_Customer_Self_Reported__c, MailingCity, MailingState, MailingCountry, MailingPostalCode, MailingStreet, Fax,MDM_Person_ID__c,MDCP_Last_Sync_Date__c,LeadSource,SFDC_MDCP_Batch_Sync_Flag__c,CreatedDate, RecordTypeId, LastModifiedDate,Isolation_Reason__c,  MailingCity__c, MailingCountry__c, MailingPostalCode__c, MailingState__c, MailingStreet__c, Telephone_Access_Code__c, Service_Delivery_Email_Opt_In__c, Email_Quality_Survey_Opt_In__c, Phone_Quality_Survey_Opt_In__c, Department, Lead_Source__c,Case_Closure_Notification_Opt_In__c, Alternate_Preferred_Customer_Language__c, Part_Delivered_Notification_Opt_In__c, VisitOps__LinkedInUrl__c, Previous_MDCP_Contact_Relationship__c, Preferred_Language_Code__c,  Preferred_Customer_Language__c, Location_ID__c, Contact_External_Id__c, Customer_Division__c, DPlus_Company_Reference__c, SourceSystemContactID__c FROM Contact where AccountId=:accIds and IsActive__c=true AND EMAIL NOT IN :skipEmails ORDER BY CreatedDate DESC];
        System.debug('QualifiedContacts==>'+QualifiedContacts);  
         
        Map<ID,List<contact>> SegContactMap  = new Map<ID,List<contact>>();
        Map<String,ContactMergeWrappper> DupMap = new Map<string,ContactMergeWrappper>();
     
        String dupKey;
        //Segregating All Contacts by Account
        for(contact c :QualifiedContacts)
        {
            list<contact> clist=new list<contact>();  
            if(SegContactMap.get(c.accountid)!=null)
            {
                clist  = SegContactMap.get(c.accountid);
            }
            clist.add(c);
            SegContactMap.put(c.accountid,clist);
        }
        System.debug('SegContactMap==>'+SegContactMap); 
        
        //Finding Duplicate based on Filter Passed
        Boolean validKey = true;
        for(Id accid : SegContactMap.keySet())
        {
            for(Contact con : SegContactMap.get(accid))
            {
                validKey = true;
                if(DupBy=='LastNameEmail') 
                {   
                    if(String.isBlank(con.Email))  validKey = false;
                    dupKey = con.AccountId+con.LastName+con.Email; 
                }
                else 
                {
                    if(String.isBlank(con.MDM_Person_ID__c))  validKey = false;
                    dupKey = con.AccountId+con.MDM_Person_ID__c; 
                }
                System.debug('dupKey ===>'+dupKey +' ==>'+DupBy); 
                if(DupMap.get(dupKey)==null && validKey)
                {
                    list<Contact> Dlist = new list<Contact>();
                    ContactMergeWrappper W = new ContactMergeWrappper(con,Dlist,'Processing');
                    DupMap.put(dupKey,W);
                }
                else if(DupMap.get(dupKey)!=null && validKey)
                { 
                    ContactMergeWrappper W=DupMap.get(dupKey);  
                    
                    DateTime RTCD,CSCD;
                    RTCD = createdDateMap.get(con.Id) !=null? createdDateMap.get(con.Id):con.CreatedDate;
                    CSCD = createdDateMap.get(W.Survivor.Id) !=null? createdDateMap.get(W.Survivor.Id):W.Survivor.CreatedDate;
                    
                    if(RTCD >= CSCD)
                    {
                        W.donors.add(W.Survivor);
                        W.Survivor=con;
                    }
                    else
                    {
                        W.donors.add(con);  
                    }
                    DupMap.put(dupKey,W);              
                }
            }
        }        
        //Filter out records with no Donors
        System.debug('DupMap==>'+DupMap.size()+' ===>'+DupMap); 
        mergeDupMap=New Map<String,ContactMergeWrappper>();
        for(String key : DupMap.keySet())
        {
            ContactMergeWrappper W=DupMap.get(key);
            if(W.donors.Size()>0)
            {
                mergeDupMap.put(W.Survivor.Id,W);
                System.debug('The previousQualifiedIds 2' + previousQualifiedIds);
                previousQualifiedIds.add(W.Survivor.AccountId);  
                createdDateMap.put(W.Survivor.Id,W.Survivor.CreatedDate);               
            }
        }
        System.debug('mergeDupMap==>'+mergeDupMap.size()+' ===>'+mergeDupMap); 
       
        //Merging the Qualified records one by one
        for(ID DI:mergeDupMap.keyset())
        {
            ContactMergeWrappper MergeResult=ContactMergeHelper.ProcessMerge(mergeDupMap.get(DI)) ;             
            MergeStatusList.add(MergeResult);
            System.debug('MergeResult==>'+MergeResult);             
        }
                                        
    }     
    
    // The batch job finishes
    global void finish(Database.BatchableContext bc)
    { 
        String mergeText = 'Donor PersonId,Donor Email,Donor FirstName,Donor LastName,Donor Id,Donor CreatedDate,Survivor PersonId,Survivor Email,Survivor FirstName,Survivor LastName,Survivor Id,Survivor CreatedDate,Status' + '\n';
        Integer ErorCount = 0;
        for(ContactMergeWrappper mw:MergeStatusList)
        {
            List<Contact>DonorList = mw.Donors; 
            Contact Survivor = mw.Survivor; 
            if(mw.Status=='Processed')
            {
                for(Contact donor:DonorList)
                {
                    if(mw.MergeStatusMap.get(donor.Id) !='Record Merged Sucessfully'){
                        mergeText += donor.MDM_Person_ID__c+ ','  +donor.Email+ ','+donor.FirstName+ ',' +donor.LastName+ ','  +donor.Id+ ','+donor.CreatedDate+ ','  +Survivor.MDM_Person_ID__c+ ',' +Survivor.Email+ ','  +Survivor.FirstName+ ','  +Survivor.LastName+ ','  +Survivor.Id+ ','  +Survivor.CreatedDate+ ','  +mw.MergeStatusMap.get(donor.Id)  + '\n';
                        ErorCount++; 
                    }
            //DonorList.clear();            
                    MergeCount= mw.MergeStatusMap.size(); 
                }
            }  
        }      
        mergeText = mergeText.substring(0, mergeText.length() -1 );
        
        If(ErorCount>0){ 
             Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment();
            blob csvBlob = Blob.valueOf(mergeText);
            DateTime d = Date.Today() ; 
            String dateStr =  d.format('dd-MM-yyyy') ;        
            string csvname= 'Contact_Merge_Status_BY_'+dupBy+'  '+dateStr+'.csv';
            csvAttc.setFileName(csvname);
            csvAttc.setBody(csvBlob);
            Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
            message.toAddresses = recipientEmails;
            message.subject = 'Contact merge Error report '+String.valueof(Date.Today());
          //message.plainTextBody = 'Hi,  \n  Please Find the Status of Merge Performed on'+String.valueof(Date.Today());
            message.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc});
            String bodyStart='<html><body><h3>Contact Merge Failure Report:</h3> <table align="left" border="1" cellpadding="1" cellspacing="1" style="width: 500px;"><tbody><tr><td>Operation</td><td>Contact Merge</td></tr><tr><td>Status</td><td>Merge Failed</td>';
            String BodyStarttime='</td></tr><tr><td>Time Processed</td><td>';
            String NoOfRecordProssced='</td></tr><tr><td>Number of Duplicate records Processed</td><td>';
            String errorCounts='</td></tr><tr><td>Number of records Faield to Merge</td><td>';
            String BodyTail='</td></tr></tbody></table><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>&nbsp;<p>&nbsp;</p><p>Thank You</p><p>Contact Merging Team</p><body></html>';       
            String HTMLBody=bodyStart+NoOfRecordProssced+MergeCount+errorCounts+ErorCount+BodyStarttime+string.valueof(system.now())+BodyTail;
            message.setHtmlBody(HTMLBody);
            Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
            Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);

        }
        if(dupBy=='PersonId') Id JobId = Database.executeBatch(new ContactMergeBatch(pastNDays,'LastNameEmail',previousQualifiedIds,createdDateMap),BatchSize);

    }
}
hi, I need to create a custom VF page to show account hierarchy. Can someone help me with the same as its urgent.
Hi All Veterans
We have a requirement wherein we have to write a trigger on contact after update. There will be a field called IsDeleted in contacts, when that field will be selected the contact will automatically get associated with a private account. Now the challenge is we have to create the  private account dynamically. Before associating the contact we have to check if that pfivate account contains 10000 contacts if yes then create a new private account and associate that contact with the newly created private account else with the previous account, this process will continue.

Thanks in advance...:)
My requirement is 

I need to show the Account hierarchy in custom vf page as same as standard like

In Account object, we have created on the field which is existing Account (lookUp).
if any Account is linked with this account then we need to show the All child account linked to that particular acc in VF page.
Account Name(Parent Account)    Type(Child Account)   Account Owner(Child Acc Owner)
TRTest                                            Industry                      prem
TrTest1                                           other                           karan 
And finally I want to add this page on Account Layout that user can see his/her Linked Account Hierarchy Wise..

Need Urgent Help...