UrbanPro
true

Learn Salesforce Developer from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Trigger Sceniors - session 4

S
Suresh Kumar Tavva
15/12/2016 0 0

Scenario 10:-

//Trigger Check Duplicate

before insert, before update

Set<ID> leadid = new Set<ID>();

    Map<String,Lead> phonemap = new Map<String,Lead>();

    Map<String,Lead> emailmap = new Map<String,Lead>();   

    for(Lead l : Trigger.New){

        if(phonemap.containsKey(l.Phone))

            l.adderror('Another Lead with the same Phone no is already available');

        else if(emailmap.containsKey(l.Email))

            l.adderror('Another Lead with the same Email is already available');

        else{

            if(l.ID != null)

                leadid.add(l.ID);

            if(l.Phone != null)

                phonemap.put(l.Phone,l);

            if(l.Email != null)

                emailmap.put(l.Email,l);   

        }

    }

   

    for(Lead L : [select ID,Phone,Email from Lead where ((Phone IN: phonemap.keyset() or Email IN: emailmap.keyset()) AND ID NOT IN: leadid)]){

        Lead l1 = phonemap.get(l.Phone);

        if(l1 != null)

            l1.adderror('Another Lead with the same Phone no is already available');

        else{

            Lead l2 = emailmap.get(l.email);

            if(l2 != null)

                l2.adderror('Another Lead with the same Email is already available');

        }

    }

Scenario 11:-

//OpportunityTrigger

before insert, before update, before delete, after insert, after update, after delete, after undelete

List<RecordType> recname = new List<RecordType>();

    TitanTrigger Titan=new TitanTrigger();    // titanTrigger is class

    if(Trigger.isBefore){

        if(Trigger.isUpdate || Trigger.isInsert){

            for(Opportunity currentopportunity:Trigger.new){

                Titan.Triggers.Attachmentsize.init(currentopportunity);

            }

            if(Trigger.isUpdate){

           for(Opportunity currentopportunity:Trigger.new){

                   Titan.Triggers.StageNameError.init(currentopportunity,Trigger.oldmap.get(currentopportunity.id));

                  Titan.Triggers.stagevalidation.init(currentopportunity,Trigger.oldmap.get(currentopportunity.id));

                }

            }

        }

    }

    if(Trigger.isBefore){

        if(Trigger.isUpdate || Trigger.isInsert){

            Titan.Triggers.Attachmentsize.Process(trigger.new);

             if(Trigger.isInsert){

                 if(TitanTrigger.recursiveFlag)

                     Titan.Triggers.ownerchange.Process(trigger.new,1);

             }

            if(Trigger.isUpdate){

               if(TitanTrigger.recursiveFlag)

               {

              

                recname=[select Id, Name, Description, DeveloperName, IsActive from RecordType where sobjecttype='Opportunity'  ];

                   if(recname[0].Name !='Jewllery' ||recname[0].Name !='Watches')

                   {

                  

                   system.debug('$$$$$$$$$$$$        '+recname[0].Name);

                       Titan.Triggers.ownerchange.Process(trigger.new,0);

                       Titan.Triggers.stagevalidation.Process(trigger.new);

                   }

               }

            }

        }

    }

Scenario 11:-

//sendInfoToQuote (By using Payment tracking bank details)

before insert, before update

List<Quote> QL = New List<Quote>();

    set<id> OppId = new set<id>();

        for(Payment_Tracker__c q1:Trigger.New){

            oppId.add(q1.Opportunity__c);

        }

    for(Payment_Tracker__c pt:Trigger.new){

        For(Quote Q:[select id,OpportunityId,Bank_Name__c,Cheque_Date__c,Cheque_No__c,Location_of_The_Bank__c,RTGS_No__c,

            Advance_Received__c from Quote where opportunityId =:oppId]){

                if(PT.Opportunity__c== Q.opportunityId && pt.Payment_Type__c=='Advance')

                {

                    Q.Bank_Name__c = PT.Bank_Name__c;

                    Q.Cheque_Date__c= PT.Cheque_Date__c;

                    Q.Cheque_No__c=PT.Cheque_No__c;

                    Q.Location_of_The_Bank__c= PT.Location_of_The_Bank__c;

                    Q.RTGS_No__c= PT.RTGS_No__c;

                    Q.Advance_Received__c= PT.Amount_Recieved__c;

                    QL.add(Q);

                                }

                        }

             }

        update QL;

}

Scenario 13:-

//Trigger Update Completed Date

before insert,before update

for(Task t : Trigger.New){

        if(t.Status == 'Completed')

            t.Completed_Date_del__c  = System.today();

    }

 

 

0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

What Are The Map Methods Available In Apex?
//Map holds key and value pair. //Syntax: Map mapName = new Map(); /*Map countryISTCodeMap = new Map(); countryISTCodeMap.put('India','91'); countryISTCodeMap.put('USA','001'); countryISTCodeMap.put('India','911');//replaces...

Java To Salesforce Connection
Java to Salesforce Connection Step 1: Generate or Obtain the Web Service WSDL To generate the WSDL file for your organization: Log in to your Enterprise, Unlimited, or Developer Edition Salesforce...

What is Mixed-DML-Operation Error And How To Avoid?
If we perform DML operation on standard/custom object and global objects(User, UserRole, Group, GroupMember, Permission Set, etc...) in same transaction this error will come. To avoid this error, we should...

What Is SOQL And SOSL?
1. SOQL: Salesforce Object Query Language SOQL: Salesforce Object Query Language SOQL Purpose: To fetch info. from an object and related objects. We can write query on one object while querying...

Difference Between Data Loader And Import Wizard In Salesforce
Difference between Dataloader and Import Wizard in Salesforce: Dataloader Import Wizard It supports more than 50000 records. It supports only up to 50000. It supports...
X

Looking for Salesforce Developer Classes?

The best tutors for Salesforce Developer Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Salesforce Developer with the Best Tutors

The best Tutors for Salesforce Developer Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more