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

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...

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...

What is a standard direct mail workflow?
Many nonprofits have been doing direct mail for years or even decades, so we’ve all developed our own particular processes. Every organization is unique and has different direct mail needs and goals....
T

Thinksoft Infotech

0 0
0

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...

Difference Between Insert/Update And Database.Insert/ Database.Update
insert/update Database.insert/Database.update Assume that you are inserting 100 records. If any one of the record fail due to error then entire operation will fail. None of the records will be saved...
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