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

Before Take Salesforce Training Need To Ask Below Things
In every platform technology will be follow below things: i. Software Development Life Cycle--------SDLC having diffrent METHADOLOGIES (Salesforce SDLC -- Agile and Agile with SCRUM) What is the difference...

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

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

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

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