UrbanPro
true

Learn Salesforce Developer from the Best Tutors

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

Search in

Trigger Sceniors

S
Suresh Kumar Tavva
15/12/2016 0 0

Trigger Scenarios:- (Prepared By Suresh Kumar tvs)

Scenario one:-  (All Opportunity Triggers)

//Trigger to display error message when stage name is change from 'Order closed' to other values

Part one 1 (While trigger.old) :- 

if(Trigger.isupdate && Trigger.isBefore){

          for(Opportunity oldOpportunity:trigger.old){

             if(oldOpportunity.StageName == 'Order Closed'){

                  trigger.new[0].addError('An Opportunity cannot be edited once the opportunity stage is Order Closed');

             }

          }

Part 2(While Trigger.new):-

if(Trigger.isupdate && Trigger.isBefore){

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

                for(Opportunity newopportunity:Trigger.new){

                    opplistid.add(newopportunity.id);

                }

                list<Quote> Qlist = [select OpportunityId,Customization_Payment_Criteria__c,Approval_Status_Quote__c from Quote where OpportunityId=:opplistid];

                for(Opportunity newopportunity: Trigger.new){

                 Opportunity old=trigger.oldmap.get(newopportunity.Id);

                    if(newopportunity.Record_Type_Name__c=='Watches' || newopportunity.Record_Type_Name__c=='Jewellery'||newopportunity.Record_Type_Name__c=='Lifestyle'){

                        if((old.StageName != newopportunity.StageName)){

                            for(Quote qq:Qlist){

                                if(qq.OpportunityId==newopportunity.id && qq.Customization_Payment_Criteria__c =='Free Of Cost' && qq.Approval_Status_Quote__c!='Approved'){

                                    newopportunity.addError('cannot change Stage as Quote Customization Payment Criteria is Free of cost and quote is not approved');

                                }

                            }

                        }

                    }

                }

     }

Scenario Two:-

//Trigger on checking attachment size and displaying error for different Record type

if(Trigger.isAfter && Trigger.isupdate){

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

        for(Opportunity newopportunity:Trigger.new){

            oppId.add(newopportunity.id);

        }

        Integer Vattachmentcount = 0;       

        Integer Invoicecount = 0; 

            List<Attachment> ca = [Select id,Name from Attachment where  ParentId=:oppId limit 99];

            for(Integer i=0;i<ca.size();i++){

                if(ca[i].Name.indexOfIgnoreCase('validated')>=0 ){

                    Vattachmentcount++;

                }

                if(ca[i].Name.indexOfIgnoreCase('invoice')>=0 ){

                    Invoicecount++;

                }

            }

        for(Opportunity newOpportunity:Trigger.new){

            if(newOpportunity.Record_Type_Name__c == 'Jewellery' && newOppor

tunity.Customization_Status__c == 'Validated' && (newOpportunity.StageName == 'Proforma Invoice'||newOpportunity.StageName == 'Received PO/Order Won' ||newOpportunity.StageName == 'Payment/Delivery' ||newOpportunity.StageName == 'Order Closed' )&& Vattachmentcount == 0){

                newOpportunity.addError('Please upload the appropriate file with the keyword "validated" included within the file name');

            }

            if((newOpportunity.Record_Type_Name__c == 'Lifestyle' || newOpportunity.Record_Type_Name__c == 'Watches') && newOpportunity.Customization_Status__c == 'Validated' && (newOpportunity.StageName == 'Proforma Invoice'||newOpportunity.StageName == 'Received PO/Order Won' ||newOpportunity.StageName == 'Payment/Delivery' ||newOpportunity.StageName == 'Order Closed' ) && Vattachmentcount == 0){

                newOpportunity.addError('Please upload the appropriate file with the keyword "validated" included within the file name');

            }

            if(newOpportunity.Delivery_Status__c == 'Completed' && newOpportunity.StageName == 'Payment/Delivery' && Invoicecount == 0){

                newOpportunity.addError('Please upload the appropriate file with the keyword "Invoice" included within the file name');

            }

        }

    } 

}

0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

Trigger Sceniors - session 5
//Trigger Check Duplicate before insert, before update Set leadid = new Set(); Map<String,Lead> phonemap = new Map<String,Lead>(); Map<String,Lead> emailmap = new Map<String,Lead>();...
S

Trigger Sceniors - session 2
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)); ...
S

Trigger Sceniors - session 4
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>...
S

Trigger Sceniors - session 3
Scenario 7:- //Checking the model number with the existence values while inserting or updating before insert,before update //Variable Declaration List<Product__c> allProducts = new List<Product__c>(); ...
S
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