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 2

S
Suresh Kumar Tavva
15/12/2016 0 0

Scenario3:-

// Amount In Words

before Insert, before update

for(Quote qu : Trigger.New)

{

    if(qu.amount_in_words__c!=null) {

    qu.Converted_Amount_In_Words__c  = ConvertRupees.ConvertFun((qu.amount_in_words__c));

    }}

Scenario 4:-

// Attachment in child     (Attachment Is an object in salesforce)

before Insert, before update

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

        for(Opportunity O : Trigger.new)

            {

            if(o.Record_Type_Name__c != 'Jewellery' && o.Record_Type_Name__c != 'Lifestyle' && o.Record_Type_Name__c != 'Watches')

                Oppid.add(O.id);

            }

List<Attachment> ca = [Select id from Attachment where  ParentId=:Oppid];

        for(Opportunity O: Trigger.new)

            {

             if(o.Record_Type_Name__c != 'Jewellery' && o.Record_Type_Name__c != 'Lifestyle' && o.Record_Type_Name__c != 'Watches')

                O.Total_No_of_Attachment__c = ca.size();

            }

Scerino 4:-

// NumberToWords ( Two objects Quote and QuoteLineitem)

before Insert, before update

If(TriggerMonitor.ExecutedTriggers.contains('NumberToWords'))

        return;

    TriggerMonitor.ExecutedTriggers.add('NumberToWords');

for(Quote qu:Trigger.New)

{

     if(qu.Quote_Currency__c!='INR')

     {

          if(qu.amount_in_words__c!=null)

        {

                   qu.Amount_converted_Words__c  =  EnglishNumberToWords.convert((qu.amount_in_words__c));

            qu.New_Total_Amount_in_Words__c=qu.Quote_Currency__c +' '+' '+ qu.Amount_converted_Words__c;

        }

        }

        else

        {

         if(qu.amount_in_words__c!=null)

        {

            qu.Amount_converted_Words__c  = ConvertRupees.ConvertFun((qu.amount_in_words__c));

            qu.New_Total_Amount_in_Words__c = qu.Quote_Currency__c +' '+' '+ qu.Amount_converted_Words__c;

        }

        }

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

       for(Integer j = 0; j < LN.size(); j++){

                //system.debug('PROOOOOOOOOOOOO'+cd[j].Product_Categeory__c);

               

                product_cat.add(LN[j].PricebookEntry.Product2.Product_Category__c);

              

            }

            system.debug('No of category...'+product_cat.size());

            system.debug('Name of category...'+product_cat);

            if(product_cat.size()<2 && product_cat.size()>0 )

            {

              List<Contract_Details__c> cd=[select id,Discount__c,Valid_From__c,Valid_To__c,Brand__c,Value_From__c,Value_To__c from Contract_Details__c

                where Contract_Number__c =: qu.Contract_Number__c and Brand__c=: LN[0].PricebookEntry.Product2.Product_Category__c

                         ];

                           

              system.debug('No of category...'+product_cat.size());

             for(Integer j = 0; j < cd.size(); j++){

             if(qu.Sent_to_Approval__c == false){

            if(qu.Discount_Corp__c <= cd[j].Discount__c){

                       system.debug('Valid Discount');

              

              if(qu.Price_After_Discount__c >= cd[j].Value_From__c && qu.Price_After_Discount__c <= cd[j].Value_To__c){

                       system.debug('Valid Values');

                     

                   if(qu.CreatedDate >= cd[j].Valid_From__c && qu.CreatedDate <= cd[j].Valid_To__c){

                       system.debug('valid date range');

                     

                       qu.Approval_Status_count_LineItem__c =' ';

                       qu.Approval_Status_Quote__c ='Approved';

                       qu.Quote_Status_watches_new__c =' ';

                       qu.Approved_QuoteLineItem__c = qu.Total_No_of_QuoteLineItem__c;

                       break;

                                     

                   } else{

                   qu.Approval_Status_count_LineItem__c ='Approval Required';

                   qu.Approval_Status_Quote__c ='Approval Required';

                   qu.Quote_Status_watches_new__c ='Approval Required';

               }

               } else{

                   qu.Approval_Status_count_LineItem__c ='Approval Required';

                   qu.Approval_Status_Quote__c ='Approval Required';

                   qu.Quote_Status_watches_new__c ='Approval Required';

               }

               }

               

                 else{

                   qu.Approval_Status_count_LineItem__c ='Approval Required';

                   qu.Approval_Status_Quote__c ='Approval Required';

                   qu.Quote_Status_watches_new__c ='Approval Required';

               }

               }

               }

            }

Scerino  5:-

//OpportunitySharingRule

After Update, After Insert

List<OpportunityShare> oppShareList = new List<OpportunityShare>();

    for(Opportunity o:Trigger.New) {

    if(o.Record_Type_Name__c != 'Jewellery' && o.Record_Type_Name__c != 'Lifestyle' && o.Record_Type_Name__c != 'Watches')

    {

        if(o.Member2__c != NULL) {

            OpportunityShare OppShare = New OpportunityShare (OpportunityId=O.Id,                                               

                                                  UserOrGroupId =O.Member2__c ,                                             

                                                  OpportunityAccessLevel = 'Edit'

                                                  );

            oppShareList.add(OppShare);

        }

    }}

    if(oppShareList.size() > 0 ) {

        insert oppShareList;

    }

Scerino 4:-

before insert, before update

//owner change (Opportunity Object)

List<RecordType> rtypes = [Select Name, Id From RecordType where sObjectType='Opportunity' and isActive=true];

        Map<String,String> Opprectype = new Map<String,String>{};

       

        for(RecordType rt: rtypes)

            {

                Opprectype.put(rt.Name,rt.Id);

            }

           

   

        List<User> Userlist = [Select Name, Id From User where  isActive=true];

        Map<String,String> Usermap = new Map<String,String>{};

        for(User u: Userlist)

            {

                Usermap.put(u.Name,u.Id);

            }

        for(Opportunity opp : Trigger.New)

            {

            if(opp.Record_Type_Name__c != 'Jewellery' && opp.Record_Type_Name__c != 'Lifestyle' && opp.Record_Type_Name__c != 'Watches')

            {

            {

                if(Trigger.isUpdate)

                    {

                        if(opp.CreatedDate.date() >= date.newInstance(2012, 2, 7))

                        {

&nb

0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

How To Schedule Batch Apex In Minutes/Hours?
To schedule the batch class in minutes/hours, in the finish method we should use System.schedule method which will take 3 parameters Job Name, Chrone Expression and schedulable class instance name respectively. ...

Assigning One permission to multiple users automatically without any manual work.
Hi Friends,I recently came across below new things I did in my project. Hope it helps you too.Description :How to Assign one permission set to multiple Users ? For example: If I want to assign ONE permission...

What is SFDC Architecture.
SFDC is built based on the MVC Pattern.Model - Which is handle the Database Objects View - Which will take care of the UI pages. Controllers- The business logic Implementation will be done here.

What Is The Difference Between Non-Static And Static?
By default all the variables and methods are non-static. Scope of the non-static variables or methods is within the scope of the same object. We can declare variables and methods as static...

What Is The Order Of Execution In Salesforce?
We are creating validation rules, workflow rules, assignment rules, auto-responsive rules, escalation ruels and apex triggers etc. If the condition is same for all the rules which will execute first and...
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