Apex trigger to add dr. Salutation on lead record. - Salesforce

No comments
Handler class:



public class LeadsTriggerHandler {
public static void createLead(List<Lead> lstLead)
{
     for( Lead ldcreate: lstLead)
    {

       if( ldcreate.Is_Doctor__c == True)
       {
          ldcreate.Salutation = 'Dr.';
       }
   }
}
}

Trigger:


trigger LeadsTrigger on Lead (before insert , before update) {

     LeadsTriggerHandler.createLead(Trigger.new);

}

No comments :

Post a Comment

Trigger to avoid recursive trigger call on contact object (create contact) - Salesforce

No comments
Handler class:


public class ContactInsertHandler {     public static void createContact()     {         Contact cont = new Contact();         cont.LastName = 'Dharmik';         insert cont;     }          private static boolean run = true;               public static boolean runOnce(){          if(run) {         run=false;      return true;     }     else {             return run;       }     } }

Trigger:


trigger InsertContact on Contact (after insert) {
    
    if(ContactInsertHandler.runOnce())
    {
        ContactInsertHandler.createContact();
        
    }
}

No comments :

Post a Comment

Apex trigger to sum up (Count) amount from all the related Opportunity and set in custom field.

No comments
Handler class:

public class CustomRollUp {
  
    
    public static void docount()
    {
        list<Opportunity> setopportunity = [ select Id, Name, Amount from Opportunity where 
StageName = 'Closed Won' and RecordTypeId = '0127F00000166iGQAQ' ];
        Double j = 0;
        for( Opportunity op : setopportunity)
        {
            
            j += op.Amount;
        }
   
        list<Fund__c> updaterecord = new list<Fund__c>();
         for (Fund__c f1 : [ select id from Fund__c ] )
        {
             f1.Total_opportunity_amount__c = j;
             updaterecord.add(f1);
        }
        
        update updaterecord;
    }
    
}


Trigger:

trigger CustomRollUp on Opportunity ( after insert , after update, after delete , after undelete) {
     CustomRollUp.docount();
}

No comments :

Post a Comment

Apex trigger to set contact record detail same as account details - salesforce (i.e contact lastname = account lastname)

No comments
Handler class:

public class AccountTrigger {
    public static void createContact(List<Account> accounts) {
        
         List<Contact> contact = new List<Contact>();
        for(Account acc : accounts){
            Contact con = new Contact(LastName = acc.name,
                        AccountId=acc.id,
                        MailingStreet=acc.BillingStreet,
                        MailingCity=acc.BillingCity,
                        MailingState=acc.BillingState,
                        MailingPostalCode=acc.BillingPostalCode,
                        MailingCountry=acc.BillingCountry,
                        Fax=acc.Fax);
            contact.add(con);
        }
        insert contact; 
    }

}

Trigger:

trigger AccountTrigger on Account (after insert , after update ) {

    AccountTriggerHandler.createContact(Trigger.new);   
}

No comments :

Post a Comment

Apex trigger to show error message if sum of Opportunity amount is greater then 100000 of logged in user.

No comments
Trigger:

trigger LimitTotalAmountInOpportunity on Opportunity (before insert) {

         LimitTotalAmountInOpportunityHandler.LimitAmount(Trigger.new);
}


Handler Class:

public class LimitTotalAmountInOpportunityHandler {
public static void LimitAmount(list<Opportunity> OpportunityList)
{
        double totalamount = 0;
       for(opportunity objopportunity : [select Amount from opportunity where createdDate = today                and createdById =: UserInfo.getUserId()]){
             if(objopportunity.amount != null)
                    totalamount += objopportunity.amount;
         }

for(opportunity objopportunity : OpportunityList){
      if(objopportunity.amount != null)
            totalamount += objopportunity.amount;
              if(totalAmount > 100000){
                  objopportunity.addError('Total Amount Limit Exceded');
              }
  }
}
}

No comments :

Post a Comment