• SV M
  • NEWBIE
  • 105 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 62
    Questions
  • 40
    Replies
Hi, I am using Lightning Tabset with multiple tabs inside it. I wanted to fetch the Id the of the tab which is next to active tab. I have Tab1, Tab2 and Tab3. If Tab 1 is active I want to get the Id of Tab 2. I have been trying for this from last 2 days. But I haven't found anything relative. Can someone help me is there any way to acheive it. Thanks in Advance...
  • July 28, 2021
  • Like
  • 0
Hi,
I have a list view button placed on Account object. I wanted to fetch the current page url on click of that button. I have tried {!$Currentpage.parameters.<parameterName>}. But I am getting the URL after redirection. Is there any way to capture the URL before redirection to some other url. Please help me on this. Thanks in Advance...
  • July 23, 2021
  • Like
  • 0
Hi, I have a community portal where I have a rich text field to insert image. But, after selecting image and clicking insert the image isn't inserting. When I try to uplolad image using URL I was able to upload. Can someone help me how to solve this issue...

Thanks in Advance...
  • June 03, 2021
  • Like
  • 0
Hi, I wanted to show Accounts with checkbox on my page. If I select an account and click Next button I want to display contacts related to that Account. Can someone help me how to do this using Aura Components since I am new to Aura Components. Thanks in Advance...
  • May 21, 2021
  • Like
  • 0
I have a requirement that after inserting a record in Campaign Account(Custom Object lookup with Account) it should check the Campaign Account Name with opportunities related to the Account. I was able to achieve the functionality using the trigger. But I wanted to optimize my code so can someone help me with my code.
 
public class CreateOppAfterCAInsertionHelper {
    public string name;
    public Id accId;
    public void insertOpp(List<Campaign_Account__c> campaignAccList) {
        Set<Id> accIds = new Set<Id>();
        List<Opportunity> oppList = new List<Opportunity>();
        List<Opportunity> updatedOpps = new List<Opportunity>();
        for(Campaign_Account__c campAcc : campaignAccList) {
            if(campAcc.Account__c != NULL) {
                accIds.add(campAcc.Account__c);
                name = campAcc.Name;
                accId = campAcc.Account__c;
            }
        }
        oppList = [SELECT Name, AccountId, Count__c 
                   FROM Opportunity 
                   WHERE AccountId IN:accIds AND Name =: name];
        if(oppList.size() > 0) {
            for(Opportunity opp : oppList) {
                opp.Count__c  = opp.Count__c + 1;
                updatedOpps.add(opp);
            }
        }
        if(oppList.size() == 0) {
            Opportunity newOpp = new Opportunity();
            newOpp.Name = name;
            newOpp.StageName = 'Prospecting';
            newOpp.CloseDate = date.today();
            newOpp.AccountId = accId;
            insert newOpp;
        }
        if(updatedOpps.size() > 0) {
            update updatedOpps;
        }
    }
}
I want to avoid the highlighted lines. Need help thank you...
 
  • March 14, 2021
  • Like
  • 0
Hi, I have a VF page with an input text box when I enter some string it should check whether the record exists or not. I was able to achieve the functionality but in my test class, I was not able to cover a few lines.
public class searchAndLinkRecordsToAccount {
    public String searchString{get;set;}
    public Integer count;
    public List<Account_Relation__c> accRelList{get;set;}
    public searchAndLinkRecordsToAccount(ApexPages.StandardController stdController) {
    }
    public void search() {
        List<Account_Relation__c> updatedRecordsList = new List<Account_Relation__c>();
        List<Account_Relation__c> insertedRecordsList = new List<Account_Relation__c>();
        accRelList = [SELECT Id, Name, Count__c, Latest_Submitted_Date__c 
                      FROM Account_Relation__c 
                      WHERE Account__c =:ApexPages.currentPage().getParameters().get('id') AND Name =:searchString];
        if(accRelList.size() > 0) {
            for(Account_Relation__c rel : accRelList) {
                rel.Count__c = rel.Count__c + 1;
                rel.Latest_Submitted_Date__c = Datetime.now();
                updatedRecordsList.add(rel);
                ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.INFO,'Record found with the Search String'));
            }
        }
        if(accRelList.size() == 0){
            Account_Relation__c accRel = new Account_Relation__c();
            accRel.Name = searchString;
            accRel.Account__c = ApexPages.currentPage().getParameters().get('id');
            accRel.Count__c = 1;
            accRel.Latest_Submitted_Date__c = Datetime.now();
            insertedRecordsList.add(accRel);
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.INFO,'Record inserted and sent for Approval'));
        }
        if(updatedRecordsList.size() > 0) {
            update updatedRecordsList;
        }
        if(insertedRecordsList.size() > 0) {
            insert insertedRecordsList;
        }
    }
}
//Test Class

@isTest
public class searchAndLinkRecordsToAccountTest {
    public static testMethod void method1() {
        Account acc = new Account(Name='Test Acc');
        insert acc;

        Account_Relation__c accRel1 = new Account_Relation__c(Name='Test Relation');
        insert accRel1;
        acc.AnnualRevenue = 500;
        update acc;
        
        Test.startTest();
        ApexPages.StandardController stdController = new ApexPages.StandardController(acc);
        searchAndLinkRecordsToAccount recsToAcc = new searchAndLinkRecordsToAccount(stdController);
        recsToAcc.search();
        Test.stopTest();
    }
}
I was not able to cover the highlighted lines of code. Please help. Thanks in Advance.
  • March 09, 2021
  • Like
  • 0
Hi, I've built a trigger that will update the Owner for the Account and its related contacts based on the User Lookup field in the Account. I was able to update the Owner of related contacts with an update in the Account.
If I change the Account in any of the Contact then the new Accounts owner should be added as Contacts Owner. I tried using the Trigger.OldMap. Can someone help me with what needs to be changed in my trigger...
trigger AccountOwnerUpdate on Account (before insert, before update) {
    Set<Id> accIds = new Set<Id>();
    List<Contact> updatedConList = new List<Contact>();
    Map<Id, String> newOwnerIds = new Map<Id, String>();
    
    
    List<Contact> conList = [SELECT Id, AccountId FROM Contact WHERE AccountId IN: accIds];
    for(Account acc : trigger.new) {
        accIds.add(acc.Id);
        newOwnerIds.put(acc.Id, acc.Coverage_Lead__c);
        
        if(acc.Coverage_Lead__c != NULL) {
            acc.OwnerId = acc.Coverage_Lead__c;
        }
        if(acc.Coverage_Lead__c == NULL){
            acc.OwnerId = acc.LastModifiedById;                
        }
    }
    if(trigger.isUpdate) {
        for(Account acc : trigger.new) {
            for(Contact con : conList) {
                if(con.AccountId!= NULL) {
                    if(trigger.oldMap.get(con.Id).AccountId != con.AccountId) {
                        accIds.add(con.AccountId);
                    }
                }
                accIds.add(trigger.oldMap.get(con.Id).AccountId);
            }
        }
    }

    for(Account accs : [SELECT Id, LastModifiedById, (SELECT Id, Owner.Id, AccountId FROM Contacts) FROM Account WHERE Id IN:accIds]) {
        if(newOwnerIds.get(accs.Id) != NULL) {
            for(Contact con : accs.Contacts) {
                con.OwnerId = newOwnerIds.get(accs.Id);
                updatedConList.add(con);
            }
        }
        if(newOwnerIds.get(accs.Id) == NULL) {
            for(Contact con : accs.Contacts) {
                con.OwnerId = accs.LastModifiedById;
                updatedConList.add(con);
            }   
        }
        
    }
    update updatedConList;
}
Thanks in Advance.
  • March 04, 2021
  • Like
  • 0
Hi, I have a requirement where I am sending emails to Lead Email (Field in Lead) using a batch class. After sending the email I want to update the checkbox value to TRUE if the email is sent and FALSE if the email is not sent..
I've written the batch class but I am not sure how to update the field after email... Can someone help me with how to achieve this...
global class SendEmailToLeadBatch implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id, Name, Email, Age_of_Lead__c, Email_Sent__c FROM Lead WHERE Age_of_Lead__c > 7 AND LeadSource = \'Partner Referral\'';
        return database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<Lead> scope) {
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
        for(Lead ldEmail : scope) {
            String body = 'The Lead '+ldEmail.Name+' age is '+ldEmail.Age_of_Lead__c+' Days';
            //String body = 'Hello '+ldEmail.Name+' is created '+ldEmail.Age_of_Lead__c+' Days;
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            List<String> sendTo = new List<String>();
            sendTo.add(ldEmail.Email);
            mail.setToAddresses(sendTo);
            mail.setSaveAsActivity(false);
            mail.setSubject('Hello '+ldEmail.Name+'');
            mail.setHtmlBody(body);
            emails.add(mail);
        }
        Messaging.SendEmailResult[] result = Messaging.sendEmail(emails);
        if(result[0].success) {
            
        }
    }
    global void finish(Database.BatchableContext BC) {
        
    }
}



 
  • March 02, 2021
  • Like
  • 0
Hi, Can someone help me with how to write a Test Class for the below Wrapper Class...
public class OppRelatedSolutionsController {
    public List<WrapperClass> wrapList{get;set;}
    public List<Solution__c> selectedRecords{get;set;}
    public OppRelatedSolutionsController(ApexPages.StandardController stdController) {
        wrapList = new List<WrapperClass>();
        for(Solution__c solRecs : [SELECT Name, Amount__c, Expected_Revenue__c FROM Solution__c WHERE Opportunity__c = NULL]) {
            wrapList.add(new WrapperClass(solRecs));
        }
        if(wrapList.size() <= 0) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'No Records found'));
        }
    }
    public pageReference saveRecords() {
        selectedRecords = new List<Solution__c>();
        for(WrapperClass wrapRecs : wrapList) {
            if(wrapRecs.selected == TRUE) {
                wrapRecs.sol.Opportunity__c = ApexPages.currentPage().getParameters().get('id');
                selectedRecords.add(wrapRecs.sol);
            }
        }
        update selectedRecords;
        if(selectedRecords.size() > 0) {
            pageReference ref = new PageReference('/'+ApexPages.currentPage().getParameters().get('id'));
            ref.setRedirect(true);
            return ref;
        }
        return null;
    }
    //Wrapper Class
    public class WrapperClass {
        public Solution__c sol{get;set;}
        public Boolean selected{get;set;}
        public WrapperClass(Solution__c s) {
            sol = s;
            selected = false;
        }
    }
}

I am trying to learn how to write Test Classes. So any response would be appreciated... Thanks in Advance.

 
  • March 02, 2021
  • Like
  • 0
I have a list of Opportunities that needs to send through email. In the email body, the list elements are displaying as (Rec1, Rec2, Rec3)...
But, I want to display is as,
  • Rec1
  • Rec2
  • Rec3
Is there any possibility that I can change the Email body. Any help would be appreciated...
  • February 24, 2021
  • Like
  • 0
Hi,
I have a requirement where I have a search box in VF Page which displays Contacts based on Search String. If there is only one record matches the string the page should automatically redirect to that Contact record.
I am using Page Reference and Param to get the Id from the Search String. But it's throwing an error says URL is broke.
//Controller
public class SearchContactsController {
    public List<Contact> conList{get;set;}
    public String search {get;set;}
    public String Id{get;set;}
    public PageReference contacts() {
        Id = ApexPages.currentPage().getParameters().get('id');
        conList = [SELECT Id, FirstName, LastName FROM Contact WHERE LastName =:search];
        if(conList.size() == 0) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR,'No Records Found'));
        }else {
            if(conList.size() == 1) {
                PageReference pr = new PageReference('/'+Id);
                pr.setRedirect(true);
                return pr;
            }
        }
        return null;
    }
}
//VF Page
<apex:page controller="SearchContactsController">
    <apex:form >
        <apex:pageMessages />
        <apex:pageBlock >
            <apex:inputText value="{!search}" label="Search Contacts"/>
            <apex:commandButton value="Search" action="{!contacts}">
                <!--<apex:param name="id" assignTo="{!search}" value=""/>-->
            </apex:commandButton>
        </apex:pageBlock>
        <apex:pageBlock >
            <apex:pageBlockTable value="{!conList}" var="con">
                <apex:column headerValue="FirstName" value="{!con.FirstName}"/>
                <apex:column headerValue="LastName">
                    <apex:outputLink value="/{!con.Id}">{!con.LastName}
                        <apex:param name="id" assignTo="{!search}" value="{!con.Id}"/>
                    </apex:outputLink>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Can someone help me with what's wrong with my code. Thanks in Advance...
  • February 17, 2021
  • Like
  • 0
Hi,
I have a VF Page where I am calling multiple methods using different command buttons. I want to call all the methods in the class one after another with only one command button. Is it possible to call one method from another method which is in the same class...

Thanks in Advance...
  • February 15, 2021
  • Like
  • 0
Hi,

I want to display an error message for the user who doesn't have Read Access to Lead Object when he opens a VF Page without using a custom controller. Is it possible to achieve it from VF Page itself...
Thanks in Advance...
  • February 11, 2021
  • Like
  • 0
Hi,

I have a requirement in the Approval Process where it has multiple approvers assigned. When I submit the record for approval if 1st Approver approved and 2nd Rejected then the Approval Request should reach to 3rd Approver also...
I
knew that if any of the approvers rejects the record it will not go to the next approver. But, is there any possibility of achieving this...
Thanks in Advance...
  • February 09, 2021
  • Like
  • 0
Hi, 
I have a VF page where I need to display an error message using Custom Labels when the checkbox is not checked after hitting the save button. Can anyone help me how to use custom labels since I am using it for the first time...

Thanks in Advance.
  • January 27, 2021
  • Like
  • 0
Hi, I want my phone field to be auto-populated as below after record is saved.
+XX (XXX) XXX-XXXX

I've tried regex to format. But, it's working only if I enter a formatted phone number. Can someone help me how to format the phone upon saving the record... The regex function I used is...
^((\\+)(\\d{2})?\\s?\\(\\d{3}\\)\\s?\\d{3}\\-\\d{4})?$
Thanks in Advance...
  • January 21, 2021
  • Like
  • 0
Hi, I want my phone number field number to display the number in the format of +XX (XXX) XXX-XXXX. Can someone help me how to achieve this.

Thanks in Advance...
  • January 19, 2021
  • Like
  • 0
Hi,
I want to show/hide a specific field in an object when a picklist value is selected. Can someone help me how to implement this using script which I want to access using action function...

Thanks in Advance.
  • December 14, 2020
  • Like
  • 0
Hi,

I have a requirement where I need to display only 2 Contacts related to each Account in a list view. Can someone help me how to build the query for my requirement...

Thanks in Advance...
  • November 03, 2020
  • Like
  • 0
Hi, I am trying to populate Account Type on Contact by creating custom picklist 'Type' using Maps.

public class ContactAccountMap {
    public void accountMap() {
        Set<Id> accountIds = new Set<Id>();
        List<Contact> conList = [SELECT Id, Name, Type__c, AccountId FROM Contact];
        for(Contact con : conList) {
            accountIds.add(con.AccountId);
        }
        List<Account> accList = [SELECT Id, Name, Type FROM Account WHERE Id IN:accountIds];
        //System.debug('accounts'+accountIds);
        //System.debug('contacts'+conList);
        Map<Id,Account> accMap = new Map<Id,Account>([SELECT Id, Name, Type FROM Account WHERE Id in:accountIds]);
        for(Contact con : conList) {
            if(con.AccountId != NULL) {
                con.Type__c = accMap.get(con.AccountId).Type;
            }
        }
    }
}

The code doesn't throw any errors but the I am not getting the functionality. Can someone help me with this...

Thanks in advance...
  • October 19, 2020
  • Like
  • 0
Hi, I have a community portal where I have a rich text field to insert image. But, after selecting image and clicking insert the image isn't inserting. When I try to uplolad image using URL I was able to upload. Can someone help me how to solve this issue...

Thanks in Advance...
  • June 03, 2021
  • Like
  • 0
Hi, I wanted to show Accounts with checkbox on my page. If I select an account and click Next button I want to display contacts related to that Account. Can someone help me how to do this using Aura Components since I am new to Aura Components. Thanks in Advance...
  • May 21, 2021
  • Like
  • 0
Hi, I have a requirement where I am sending emails to Lead Email (Field in Lead) using a batch class. After sending the email I want to update the checkbox value to TRUE if the email is sent and FALSE if the email is not sent..
I've written the batch class but I am not sure how to update the field after email... Can someone help me with how to achieve this...
global class SendEmailToLeadBatch implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id, Name, Email, Age_of_Lead__c, Email_Sent__c FROM Lead WHERE Age_of_Lead__c > 7 AND LeadSource = \'Partner Referral\'';
        return database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<Lead> scope) {
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
        for(Lead ldEmail : scope) {
            String body = 'The Lead '+ldEmail.Name+' age is '+ldEmail.Age_of_Lead__c+' Days';
            //String body = 'Hello '+ldEmail.Name+' is created '+ldEmail.Age_of_Lead__c+' Days;
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            List<String> sendTo = new List<String>();
            sendTo.add(ldEmail.Email);
            mail.setToAddresses(sendTo);
            mail.setSaveAsActivity(false);
            mail.setSubject('Hello '+ldEmail.Name+'');
            mail.setHtmlBody(body);
            emails.add(mail);
        }
        Messaging.SendEmailResult[] result = Messaging.sendEmail(emails);
        if(result[0].success) {
            
        }
    }
    global void finish(Database.BatchableContext BC) {
        
    }
}



 
  • March 02, 2021
  • Like
  • 0
I have a list of Opportunities that needs to send through email. In the email body, the list elements are displaying as (Rec1, Rec2, Rec3)...
But, I want to display is as,
  • Rec1
  • Rec2
  • Rec3
Is there any possibility that I can change the Email body. Any help would be appreciated...
  • February 24, 2021
  • Like
  • 0
Hi,

I want to display an error message for the user who doesn't have Read Access to Lead Object when he opens a VF Page without using a custom controller. Is it possible to achieve it from VF Page itself...
Thanks in Advance...
  • February 11, 2021
  • Like
  • 0
Hi, 
I have a VF page where I need to display an error message using Custom Labels when the checkbox is not checked after hitting the save button. Can anyone help me how to use custom labels since I am using it for the first time...

Thanks in Advance.
  • January 27, 2021
  • Like
  • 0
Hi,

I have a requirement where I need to display only 2 Contacts related to each Account in a list view. Can someone help me how to build the query for my requirement...

Thanks in Advance...
  • November 03, 2020
  • Like
  • 0
HI Experts,

Can anyone help me out, how can i send an email to public group users under a queue based on language. Thanks in advance
Hi, I am trying to populate Account Type on Contact by creating custom picklist 'Type' using Maps.

public class ContactAccountMap {
    public void accountMap() {
        Set<Id> accountIds = new Set<Id>();
        List<Contact> conList = [SELECT Id, Name, Type__c, AccountId FROM Contact];
        for(Contact con : conList) {
            accountIds.add(con.AccountId);
        }
        List<Account> accList = [SELECT Id, Name, Type FROM Account WHERE Id IN:accountIds];
        //System.debug('accounts'+accountIds);
        //System.debug('contacts'+conList);
        Map<Id,Account> accMap = new Map<Id,Account>([SELECT Id, Name, Type FROM Account WHERE Id in:accountIds]);
        for(Contact con : conList) {
            if(con.AccountId != NULL) {
                con.Type__c = accMap.get(con.AccountId).Type;
            }
        }
    }
}

The code doesn't throw any errors but the I am not getting the functionality. Can someone help me with this...

Thanks in advance...
  • October 19, 2020
  • Like
  • 0
Hi, I would like to validate the phone number field to accept only numbers except zeros.

Acceptable : 9987541452
Not Acceptable : 9010058471

Can someone help me achieve the functionality...

Thanks in advance...
  • August 18, 2020
  • Like
  • 0
I have a scenario where I have a Custom Object 'Owner Assignment' with fields Owner ID filled with different Users. I want to develop a trigger which will assign the Owner from 'Owner Assignment' object in Round Robin fashion whenever a Contact is created. Can someone help me build the logic for the above scenario since I am new to Salesforce...
Thanks in Advance...
  • July 23, 2020
  • Like
  • 0
Hi, I have a batch class which was running continuously form a long time. Can someone tell me how to abort the job? I have tried aborting from Setup -> Apex Jobs but that didn't work. Is there any other way to abort the job. Please tell me if there is any another way...

Thanks in Advance...
  • April 01, 2020
  • Like
  • 0
Hi, I have written a batch class to send email to contact owner with Contact details created by lead conversion. I have tried Test class for the same but it was not running. Can someone help me resolve this.

//Batch Class
global class EmailWithAttachment implements Database.Batchable <sObject>, Database.Stateful{
    public List<Contact> conList {get;set;}
    public String body{get;set;}
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id, FirstName, LastName, LeadSource, ConvertedDate isConverted FROM Lead';
        //system.debug('aaaaaaa'+query);
        return Database.getQueryLocator(query);
        
    }
    global void execute(Database.BatchableContext BC, Lead[] scope) {
        List<Contact> conList = new List<Contact>();
        for(Lead lead : scope) {
            conList = ([SELECT FirstName, LastName, Email, Phone
                        FROM Contact 
                        WHERE Id IN (SELECT ConvertedContactId FROM Lead)]);
        }
        system.debug('Contacts List'+conList);
        String.join(conList,',');
        messaging.SingleEmailMessage email = new messaging.SingleEmailMessage();
        body = 'Contact Details : ' +conList+ '';
        email.setPlainTextBody(body);
        email.setSubject('Contact Details from Converted Lead');
        email.setToAddresses(new string[]{'maddulasaivineeth@gmail.com'});
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
        //system.debug('Contacts'+conList);
    }
    global void Finish(Database.BatchableContext BC) {
        
    }
}

//Test Class
@isTest
public class EmailWithAttachment_TC {
    public static testMethod void EmailWithAttachment_TCMethod() {
        Lead led = new Lead (
            LastName = 'Test Lead',
            Company = 'Test Company',
            Status = 'Open - Not Contacted'
        );
        insert led;
        Database.LeadConvert lc = new Database.LeadConvert();
        lc.setLeadId(led.Id);
        lc.setDoNotCreateOpportunity(false);
        lc.setConvertedStatus('Converted');
        
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
        
    }
}
  • March 27, 2020
  • Like
  • 0
Hi, I have a batch class which should send email to contact owner which includes contacts created from lead conversion. I was unable to use contact owner email in ToAddress field. Here is my batch class..

//Batch Class

global class EmailWithAttachment implements Database.Batchable <sObject>, Database.Stateful{
    public List<Contact> conList {get;set;}
    public String body{get;set;}
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id, FirstName, LastName, LeadSource, ConvertedDate isConverted FROM Lead';
        //system.debug('aaaaaaa'+query);
        return Database.getQueryLocator(query);
        
    }
    global void execute(Database.BatchableContext BC, Lead[] scope) {
        List<Contact> conList = new List<Contact>();
        for(Lead lead : scope) {
            conList = ([SELECT FirstName, LastName, Email, Phone
                        FROM Contact 
                        WHERE Id IN (SELECT ConvertedContactId FROM Lead)]);
        }
        system.debug('Contacts List'+conList);
        String.join(conList,',');
        messaging.SingleEmailMessage email = new messaging.SingleEmailMessage();
        body = 'Contact Details : ' +conList+ '';
        email.setPlainTextBody(body);
        email.setSubject('Contact Details from Converted Lead');
        email.setToAddresses(new string[]{'maddulasaivineeth@gmail.com'});
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
        //system.debug('Contacts'+conList);
    }
    global void Finish(Database.BatchableContext BC) {
        
    }

Can someone please help me write a test class for the same.

Thanks in Advance...
  • March 27, 2020
  • Like
  • 0
Hi, I have written a batch class where I would like to send an email to contact owner with the contact details created by lead conversion.

//Batch Class
global class LeadConversionEmail implements Database.Batchable <sObject>, Database.Stateful{
    //public List<Contact> conList {get;set;}
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id, LeadSource, ConvertedDate FROM Lead WHERE ConvertedContactId != NULL';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, Lead[] scope) {
        List<Contact> conList = new List<Contact>();
        for(Lead ld : scope) {
            conList.add([SELECT FirstName, LastName 
                         FROM Contact 
                         WHERE Id IN (SELECT ConvertedContactId FROM Lead)]);
        }
    }
    global void Finish(Database.BatchableContext BC) {
       messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        String body = 'FirstName ' +conList.FirstName+ 'LastName ' +conList.LastName+ 'done'; 
    }
}

I am getting errors at body saying Variable does not exist. Can you help me resolve the problem and how to send email to contact owner.

Thanks in Advance.
  • March 26, 2020
  • Like
  • 0
Hi, I was stuck at a point where I need to get the contacts created by lead conversion. Can someone tell me how to query those contacts when a lead is converted...
I am new to salesforce so please help me do this.

Thanks in advance...
  • March 25, 2020
  • Like
  • 0
I have a Batch Class where it sends an email when Expiry Date (Custom Date Field) is today. The mail body contains the list of opportunities whose Expiry Date is Today. I have created a list and added the opportunities whose Expiry Date is today. But I am stuck at calling Opportunity Name from the List. Can someone help me to solve this.
//Batch Class

global class OpportunityExpiryDate_New implements DataBase.Batchable <sObject> {
    global DataBase.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Name, Expiry_Date__c  FROM Opportunity WHERE Expiry_Date__c = TODAY';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<Opportunity> scope) {
        List<Opportunity> oppList = new List<Opportunity>();
        for(Opportunity opp : scope) {
            if(opp.Expiry_Date__c == date.today()) {
                oppList.add(opp);
            }
        }
        update oppList;
        messaging.SingleEmailMessage email = new messaging.SingleEmailMessage();
        String body = 'The Opportunity ' +oppList+ ' is expiring today.';
        email.setToAddresses(new String[]{'maddulasaivineeth@gmail.com'});
        email.setSubject('Opportunities Expiring Today');
        email.setPlainTextBody(body);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
    }
    global void finish(Database.BatchableContext BC) {   
    }
}
  • March 06, 2020
  • Like
  • 0