• Edward Prignano
  • NEWBIE
  • 0 Points
  • Member since 2015
  • VP
  • Safe Home Control, Inc

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
I have two triggers that I copied and pasted that work perfectly, but I don't know the first thing about writing a test class to move them in to production. Can anyone help out please? Here are my two triggers:
 
trigger QuoteCreator on Opportunity (after insert) {
for (Opportunity o : Trigger.new) {
Quote q = new Quote();
q.name = 'Quote-' + o.name;
q.opportunityId = o.id;
insert q;
}
}
 
trigger AddEquipment on Opportunity (before insert, after insert) {
    Pricebook2 standardBook = [SELECT Id FROM Pricebook2 WHERE IsStandard = true];
    if(Trigger.isBefore) {
        for(Opportunity record: Trigger.new) {
            record.Pricebook2Id = standardBook.Id;
        }
    }
    if(Trigger.isAfter) {
        OpportunityLineItem[] lines = new OpportunityLineItem[0];
        PricebookEntry entry = [SELECT Id, UnitPrice FROM PricebookEntry WHERE Pricebook2Id = :standardBook.Id AND Product2.ProductCode = 'L5000ADTLB'];
        for(Opportunity record: Trigger.new) {
            lines.add(new OpportunityLineItem(PricebookEntryId=entry.Id, OpportunityId=record.Id, UnitPrice=entry.UnitPrice, Quantity=1));
        }
        insert lines;
    }
    if(Trigger.isAfter) {
        OpportunityLineItem[] lines = new OpportunityLineItem[0];
        PricebookEntry entry = [SELECT Id, UnitPrice FROM PricebookEntry WHERE Pricebook2Id = :standardBook.Id AND Product2.ProductCode = '5816WMWH'];
        for(Opportunity record: Trigger.new) {
            lines.add(new OpportunityLineItem(PricebookEntryId=entry.Id, OpportunityId=record.Id, UnitPrice=entry.UnitPrice, Quantity=1));
        }
        insert lines;
    }
}

Thank you!
I have two triggers that I copied and pasted that work perfectly, but I don't know the first thing about writing a test class to move them in to production. Can anyone help out please? Here are my two triggers:
 
trigger QuoteCreator on Opportunity (after insert) {
for (Opportunity o : Trigger.new) {
Quote q = new Quote();
q.name = 'Quote-' + o.name;
q.opportunityId = o.id;
insert q;
}
}
 
trigger AddEquipment on Opportunity (before insert, after insert) {
    Pricebook2 standardBook = [SELECT Id FROM Pricebook2 WHERE IsStandard = true];
    if(Trigger.isBefore) {
        for(Opportunity record: Trigger.new) {
            record.Pricebook2Id = standardBook.Id;
        }
    }
    if(Trigger.isAfter) {
        OpportunityLineItem[] lines = new OpportunityLineItem[0];
        PricebookEntry entry = [SELECT Id, UnitPrice FROM PricebookEntry WHERE Pricebook2Id = :standardBook.Id AND Product2.ProductCode = 'L5000ADTLB'];
        for(Opportunity record: Trigger.new) {
            lines.add(new OpportunityLineItem(PricebookEntryId=entry.Id, OpportunityId=record.Id, UnitPrice=entry.UnitPrice, Quantity=1));
        }
        insert lines;
    }
    if(Trigger.isAfter) {
        OpportunityLineItem[] lines = new OpportunityLineItem[0];
        PricebookEntry entry = [SELECT Id, UnitPrice FROM PricebookEntry WHERE Pricebook2Id = :standardBook.Id AND Product2.ProductCode = '5816WMWH'];
        for(Opportunity record: Trigger.new) {
            lines.add(new OpportunityLineItem(PricebookEntryId=entry.Id, OpportunityId=record.Id, UnitPrice=entry.UnitPrice, Quantity=1));
        }
        insert lines;
    }
}

Thank you!
Hi Experts,
     I would like to know the exact difference between 15 and 18 digits record id. Most of us say, 15 digit(case sensitive) and 18 digit(case insensitive).

Let's consider a small example,
While if you query record from Developer Console you will get 18 digit record id. Consider the below retrieved 18 digit id,

001i000001AWbWuGTA(Retrieved from query)

If 18 digit case insensitive means,

001i000001AWbWugta (this id same to the above retrieved ID)? If yes, then if you queried record with this id means, you will get no result or no rows found..!

So if both 15 and 18 are unique means what is the real time use and difference between these two ID's.

Thanks in advance..!