+ Start a Discussion
I've successfully plotted the accounts on Google Map with Lightning Component and it works in Sandbox...but don't know how to write a test code for the ApexClass.

I describe the codes below and hope anyone can help with the test code part. Thank you!

Component (MapNearbyAccount.cmp)
<aura:component controller="MapNearbyAccountController" implements="flexipage:availableForAllPageTypes,force:hasRecordId">
    <aura:attribute name="mapMarkers" type="Object"/>
    <aura:attribute name="selectedMarkerValue" type="String" />
    <aura:handler name="init" value="{! this }" action="{! c.init }"/>
    <div class="slds-box slds-theme--default">
                       mapMarkers="{! v.mapMarkers }"
                       markersTitle="accounts nearby"
                       onmarkerselect="{!c.handlerMarkerSelect}" />
Controller (MapNearbyAccount.js)
    init: function (cmp, event, helper) {
        var recordId = cmp.get("v.recordId");     
        var action = cmp.get("c.getAccounts");
        action.setParams({recordId :recordId});
        cmp.set('v.mapMarkers', [{location: {}}]);

        action.setCallback(this, function(response){
            var accounts = response.getReturnValue();
            var markers = [];
            for(var i = 0; i < accounts.length; i++){
                var acc = accounts[i];
                    location: {
                        Country : acc.BillingCountry,
                        State : acc.BillingState,
                        City: acc.BillingCity,
                        Street: acc.BillingStreet
                    icon : "standard:account",
                    value: acc.Id,
                    title: acc.Name,
            if(markers.length != 0){
                cmp.set('v.mapMarkers', markers);


    handlerMarkerSelect: function (cmp, event, helper) {
ApexClass (MapNearbyAccountController)
public class MapNearbyAccountController {
    public static List<Account> getAccounts(String BillingCity, String BillingState, String recordId){
        Account acct = [SELECT Id, Name, BillingCountry, BillingState, BillingCity, BillingStreet, Industry FROM Account WHERE Id =:recordId];
        return [SELECT Id, Name, BillingCountry, BillingState, BillingCity, BillingStreet,Description
                FROM Account 
                WHERE BillingState = :acct.BillingState AND BillingCity LIKE :('%' + acct.BillingCity + '%') AND Industry = :acct.Industry LIMIT 10];
public class MapNearbyAccountControllerTest {
    static void testMapNearbyAccountController() {
        Account acc1 = new Account();
        insert acc1;
        MapNearbyAccountController ctrl = new MapNearbyAccountController();
            List<Account> getAccounts = ctrl.getAccounts();
Best Answer chosen by MasahiroY
Maharajan CMaharajan C
Hi  Masahiro,

Please use the below test class:
public class MapNearbyAccountControllerTest {
    static void testMapNearbyAccountController() {
        Account acc1 = new Account();
        insert acc1;
        List<Account> getAccounts = MapNearbyAccountController.getAccounts('Shibuya','Tokyo',acc1.Id);

I have been looking at other posts for my questions on how Apex batch works when there is an Error. Somehow I am not able to clear my self. I have couple of questions. Can someone please clarify.

1. Assume a batch process has 3 iterations processing 200 records each. The batch process is doing an insert and I am using Database.Insert with AllorNone parameter set to False. Assume there was an error during the second iteration while processing 101 record.I understand that all the records in the first iteration will be committed and also the 100 records in the second iteration. My question is will the batch process continue to process other records in the second iteration and also the third iteration.

2. Assume all the 3 iterations (execute method) completed without any error but some error occured in the Finish method. Finish method just sends an email. How does this work, considering that I am using Database.Insert and AllorNone parameter set to False. My understanding is that all the records will be committed to the database but user will not be receiving email that the batch was successfull or not. I am confused how this scenario will work in the real time.
Best Answer chosen by Mallik
Alexander TsitsuraAlexander Tsitsura
Hello Mallik,

1. OK. The first execute method successfully processed records, and this records committed to the database.
The second execute method successfully processed too, because of the "Database.Insert" method without the AllOrNone parameter is not throwing an exception. This method returns the list of SaveResults records. It means that successfully inserted only 199 records(1 fail #101).
But if you use the insert method or the Database.insert with AllOrNone parameter the second execute method failed, and all inserted/updated records in the second "execute" method will be rollback. And exceptions did not stop process "execute" method; this means that after an exception in the second batch execute method; the third batch "execute" method will process.

2. You are right. The start, execute and finish methods process in an asynchronous mode, and if the finish method failed, no an email message received. After each successfully processed "execute" methods, all records will have to be committed to the database. 

User 444User 444 
1. If I deploy a profile from autorabbit from dev to qa sandbox, will it deploy apex classes access, vf page access and other object settings in qa? Do i need to do anything manually in qa box again?

2. Is there a way to assign apex classes to a profile through data loader?
Best Answer chosen by User 444
Sai PraveenSai Praveen (Salesforce Developers) 

You may have to add those apex classes and Vf pages in additional to the Profiles because the profile metadata only get the basic details of the profiles. If you need any additional access like field-level permissions or Object permissions or Apex Class Access you have to add those as well in the deployment.

Regarding the second question Did you try data loading on SetUpEntityAccess object?

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.



Hello Salesforce Experts,


Anyone please let me know how to write valition rule for URL ?

Else someone please provide regular expression string for URL ?



Best Answer chosen by Admin (Salesforce Developers) 

A small syntax change. 

The following rule worked for me.




Hope this helps.


Satish Kumar

Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.

Shahab KhanShahab Khan 

I have a number field (Number, 0) but when i put valuee 10000 in it it will diplay it as 10,000 i want to display it without comma.
I have selected number field because i need to select Max number from it and add 1 in Max number for new entry.
Can any body help me how i can do it.

Best Answer chosen by Shahab Khan
Grazitti TeamGrazitti Team
Hi Shahab,

Create a new custom field, where type is "formula" and the formula return type is "text".

In the formula, use the TEXT() function, and pass the existing number field value into this formula. For example, if your number field is MyNumber_c then your formula would be: TEXT( MyNumber_c )

Your users will enter values into the existing number field, but you can use the formula field (which doesn't display thousands separators)

And don't forget to mark this answer as best, if answer this helps you :-)

Grazitti Team
Web: www.grazitti.com
vinod kumar 794vinod kumar 794 

   i write a test method for a controller.but i get only  71% code coverage.

  i am facing  problem to write the test method for get set method.please help me

 here is my code:
public class eiException extends exception{
    public String code{get; set;}
    public String text{get; set;}
    public String severity{get; set;}
    public String category{get; set;}
    public String subcategory{get; set;}
    public String dataState{get; set;}
    public Boolean retryAllowed{get; set;}
    public String additionalInformation{get; set;}
    public eiException(Dom.XmlNode node){
        dom.XmlNode p;
        p=node.getChildElement('code', eiEnvelope.namespace);
        if(p != null){code = p.getText();}
        p=node.getChildElement('text', eiEnvelope.namespace);
        if(p != null){text = p.getText();}
        p=node.getChildElement('severity', eiEnvelope.namespace);
        if(p != null){severity = p.getText();}
        p=node.getChildElement('category', eiEnvelope.namespace);
        if(p != null){category = p.getText();}
        p=node.getChildElement('subcategory', eiEnvelope.namespace);
        if(p != null){subcategory = p.getText();}
        p=node.getChildElement('dataState', eiEnvelope.namespace);
        if(p != null){dataState = p.getText();}
        p=node.getChildElement('retryAllowed', eiEnvelope.namespace);
        if(p != null){retryAllowed = p.getText().equalsIgnoreCase('true');}
        p=node.getChildElement('additionalInformation', eiEnvelope.namespace);
        if(p != null){additionalInformation = p.getText();}
    public static testmethod void testeiException() {
        DOM.Document doc = new DOM.Document();
        dom.XmlNode envelope= doc.createRootElement('Envelope',null,null);
        dom.XmlNode body= envelope.addChildElement('code', null, null);

        eiException eiEx = new eiException(body);
Best Answer chosen by vinod kumar 794
Prateek Prasoon 25Prateek Prasoon 25

To achieve more test coverage for your eiException class, you need to add test methods to cover the getter and setter methods. Here is an example of how you can test these methods:
static void testGettersAndSetters() {
    eiException ex = new eiException();
    ex.code = '123';
    ex.text = 'Test Exception';
    ex.severity = 'Error';
    ex.category = 'General';
    ex.subcategory = 'Unknown';
    ex.dataState = 'Invalid';
    ex.retryAllowed = true;
    ex.additionalInformation = 'Additional info';
    System.assertEquals('123', ex.code);
    System.assertEquals('Test Exception', ex.text);
    System.assertEquals('Error', ex.severity);
    System.assertEquals('General', ex.category);
    System.assertEquals('Unknown', ex.subcategory);
    System.assertEquals('Invalid', ex.dataState);
    System.assertEquals(true, ex.retryAllowed);
    System.assertEquals('Additional info', ex.additionalInformation);
This test method creates an instance of the eiException class and sets values for all the properties using the getter and setter methods. Then it uses the System.assertEquals method to verify that the values are set correctly.
Note that you may need to update your eiException constructor to include an empty constructor to initialize the properties before the setter methods are called. You can do this by adding the following code:
public eiException() {
    // Initialize properties
    code = '';
    text = '';
    severity = '';
    category = '';
    subcategory = '';
    dataState = '';
    retryAllowed = false;
    additionalInformation = '';

If you find this answer helpful, please mark it as the best answer.
Ratheven SivarajahRatheven Sivarajah 
I am writing a trigger where I am bringing in a Date/Field field from case. It has a letter in it 2023-02-10T16:15:35.000+0000 and when I try to subtract it with "DateTime.now()" I get an error "Date/time expressions must use Integer or Double or Decimal ".

This is my code 
trigger CaseTrigger on Case (before update) {
     for(Case cases: Trigger.new){ 
         if(cases.stopped_time__c != null){
             cases.Total_amount_of_time_in_Hours__c= (DateTime.now()-cases.stopped_time__c );
Best Answer chosen by Ratheven Sivarajah
Hello Ratheven,
cases.Total_amount_of_time_in_Hours__c= (DateTime.now().getTime()-cases.ClosedDate.getTime() )/(1000.0 * 60.0 * 60.0);

In this code, we use the getTime method to convert the DateTime objects to the number of milliseconds, and then divide that number by the number of milliseconds in an hour to get the total number of hours.

I hope this will help.
fiona gentryfiona gentry 
Created a new Custom object ,now i want to create this Custom Object as Tab in the App ,but when i create a "Lightning App",can't see the Custom object in Navigation Items,I checked in profiles as well ,i had full access to the custom object as i am salesforce admin

User-added image
Your help is highly appreciated

Best Answer chosen by fiona gentry
mukesh guptamukesh gupta
Hi Fiona,

First you need to create a tab for object, steps are given below :

Go to setup->App Setup->Create->Tabs->Click on New button
Now you are able to add this tab to application, steps are given below :
Go to setup-> App Setup-> Create-> Apps-> Click on your application->click on edit button-> select & add your tab

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.



How can I access the first element in a set?  Example in a list, you can use this to get the first element in the list  


Integer x = xList.get(0);


What would be a quick equivalent way of doing this in a set?

Best Answer chosen by Admin (Salesforce Developers) 
string firstElement = null;
for (string setElement : setElements) {
        firstElement = setElement;

 This would be (marginally) faster, since you break early.


You can also:


string firstelement =
 (new list<string>(setelements) )[0] );

 Just make sure setElements.isEmpty() is false.

Hi, I wrote a trigger and a test class, but when testing I get below error: 

System.DmlException: Update failed. First exception on row 0 with id 003M000000Zc1NaIAJ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PopulateContactAreaCode: execution of BeforeUpdate
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.PopulateContactAreaCode: line 5, column 1: []

trigger PopulateContactAreaCode on Contact (before insert, before update) {

    for(Contact contact : Trigger.new)
        string AreaCode = CountryRegion__c.getInstance(contact.MailingCountry).Area_Code__c;
        contact.Area_Code__c = AreaCode;

test class:
public class PopulateContactAreaCodeTest
    static testMethod void attTriggerTest1()
        Account acct = new Account(id = '001M000000iLhTL', Name = 'Test Account ', Mailing_Country__c = 'Afghanistan');
        update acct;      
        Contact con = new Contact(id = '003M000000Zc1Na', LastName = 'Test Contact', Account = acct, Email = 'test@test.com', Mailing_Country__c = 'Afghanistan', MailingCountry = 'Afghanistan');
        update con;
        delete con;

any idea what I added wrong?

thank you in advance
Best Answer chosen by SFTerr
James LoghryJames Loghry

Because you're running a unit test, it doesn't see any data, and therefore no custom settings exist.  You'll need to insert the custom setting before you insert the Contact record.  Here's an example:

static testMethod void attTriggerTest1()
        insert new CountryRegion__c(Name='Afghanistan',Area_Code__c='123');

        Account acct = new Account(id = '001M000000iLhTL', Name = 'Test Account ', Mailing_Country__c = 'Afghanistan');
        update acct;     
        Contact con = new Contact(id = '003M000000Zc1Na', LastName = 'Test Contact', Account = acct, Email = 'test@test.com', Mailing_Country__c = 'Afghanistan', MailingCountry = 'Afghanistan');
        update con;
        delete con;