Monday, 12 July 2021

Validate duplicate status on opportunity

 



trigger opportunityTrigger on Opportunity (){

 opportunityTriggerHandler.validateOpportunity(Trigger.New, Trigger.old);

}


public class opportunityTriggerHandler{


  public static void validateOpportunity(List<Opportunity> oppList){

  Set<String> accountIdset = new Set<String>();

  for(Opportunity opp : oppList){

     if(opp.AccountId != null){

         accountIdset.add(opp.AccountId);

    }

  }

 

  Map<String,String> opportunityMap = new Map<String,String>();

  

  for(Opportunity opp : [SELECT Id,StageName FROM Opportunity where stageName != null && accountId !=null And accountId IN :accountIdset LIMIT 49999]){

     opportunityMap.add(opp.AccountId,opp.stageName);

  }

    for(Opportunity opp: oppList)){

      if(opp.containsKey(opp.AccountId) && opp.get(opp.AccountId)== opp.stageName){

         opp.stageName.addError('StageName already exists for this account');

     }

   }

 }

}

Thursday, 17 June 2021

Check value exist in array using Javascript

var preHSValues = userRole.HealthSystem.split(",");  

for (var i in hsOptions) {

                            var checkExistingValue = hsOptions.find(

                                opt => opt.value === preHSValues[i]

                            );

                            if (checkExistingValue) {

                                hsValuesNew.push(preHSValues[i]);

                            }

}

Tuesday, 15 June 2021

Apex OOPs Concepts

 Object means a real-world / run time entity such as marker, car, table, chair, etc. Object-Oriented Programming is a methodology or way to design a program using classes and objects. It eases software development and its maintenance by providing some beautiful concepts as followed.

  • Classes
  • Objects
  • Encapsulation
  • Polymorphism
  • Inheritance
  • Abstraction

Object

Any real world entity that has state and behavior is known as an object. For example: marker, book, table, chair, mouse, car etc.

Technically, we can say object is an instance of a class or in other words you can say it is an implementation of a class.

Class

Class is a concept or prototype or template i.e. it is a logical entity.

Technically, we can say that we create an individual object of a class.

Encapsulation

It is a binding of code and data together into a single unit known as encapsulation. For example, a capsule, it is wrapped with different types medicines into single unit.

An apex class is the example of encapsulation.

Polymorphism

One name many forms known as polymorphism. Real world example of polymorphism: A person at the same time can have different characteristic. Like a woman at the same time is a mother, a wife, an employee and a daughter etc.

In Apex, we use method overloading and method overriding to achieve polymorphism.

Inheritance

When one class acquires all the properties and behaviors of super/parent class it is known as inheritance. It provides code reusability as well as we can used to achieve runtime polymorphism.

Note: Without inheritance we cannot achieve runtime polymorphism.

Abstraction

Hiding internal complexity and showing functionality is known as abstraction. For example: Car Drive, we don’t know the internal processing.

In Apex, we use abstract class and interface to achieve abstraction.


http://salesforcedrillers.com/learn-salesforce/lwc-interview-questions/