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

Following Custom Objects Are Available In The Organization: Interview Question For Salesforce
ChildObject__c ParentObject__c Click to see the full question. Relationship between ChildObject__c and ParentObject__c objects is Lookup relationship. In case of lookup relationship if we delete the...

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 Batch Apex And Its Methods ?
1. We can call the apex code by creating object for the class (or) if the variables or methods are static then we can call with class name. Apex Code in the trigger will execute automatically for...

When To Use Before Triggers And When To Use After Triggers?
1. Before Triggers: To perform the validations we should use before triggers. If you are updating any field on the same object on which you are writing the trigger and no need to explicitly include the...

Salesforce Job based training
Hi All, Who are genuinely searching for a Salesforce job-based training? , That Job-based training will be provided here. 1.We will provide Salesforce Best Realtime Training 2.We will provide...
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