• Liam Lu 10
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
Hello

I am pretty new to salesforce. I am wondering am I able to related to two different objects in Task? Basically, if I create a task under my quote, I would like the task can be seen in the corresponding opportunity's task history as well in additional to the activity history under quote since quote has a relation with opportunity. I did a lot of searches but I did not find any helpful answer yet. Is there anyone can give me a hint on this, please? Thanks a lot in advance.
Hello I am writing a test calss and I need create a quote object for testing purpose. However, quote(Detail) has a master-detail relarionship with opportunity object (Master). There fore when I wrote "Quote.Opportunity.Id=Opportunity.ID", it reports "Deference a NULL value " Error. Is there anyone know why is this happening and how to fix it? Any help is appreciated. 

Here are my codes:
Opportunity O = new Opportunity();
        O.Name='sss';
        O.AccountId=A.ID;
        O.LeadSource='Other';
        O.Type='New Business';
        O.CloseDate=myDate;
        O.StageName='Qualify';
        O.CurrencyIsoCode='CAD';
        
        Insert O;
        
        Quote Q=new Quote();
        Q.Name='TestQuote';
        Q.Status='Deaft';
        Q.Payment_Terms__c='Payment Schedule';
        Q.FOB__c='Our Shop';
        Q.Freight__c='Collect';
        Q.Lead_Time__c='TBA';
        Q.Email='liam@shaverinc.com';
        Q.ShippingState='ON';
        Q.Opportunity.Id=O.Id;
        Insert Q;

Thank you!
Hello
I wrote a trigger that sends an email order confirmation to the contact when an order object is inserted. However, I need to write a test calss for the code coverage. I am not sure how to do such a test. Any help will be apprecated. Thanks in advance.

Here is my trigger
trigger OrderConfirmatiob on Order (before insert) {
        
        for(Order o : Trigger.New) {
        if(o.Contact_Email__c != NULL){
   
          List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();                    
 
            String[] toAddresses = new String[] {o.Contact_Email__c};
 
            mail.setToAddresses(toAddresses);
 
            mail.setSubject('Automated email: Order Confirmation');
            //mail.setTargetObjectId(o.Id);
            //mail.setSaveAsActivity(false);
            mail.setHtmlBody('Some Message' );
            //mail.setTemplateId(et.Id);

         emails.add(mail);
         Messaging.sendEmail(emails);
              //Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

        }
       }
    }

Here is what I have so far for the test class but it is not finished.

@isTest

private class TestOrderConfirmationEmail {

 public static void sendMail(string message) {

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {'liam@shaverinc.com'};
        mail.setToAddresses(toAddresses);

        mail.setSubject('My Subject');

        mail.setUseSignature(false);
        mail.setHtmlBody(message);

        // Send the email
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

    }   


    
    static testMethod void TestOrderEmail(){
        Account A = new Account(Name='ttt');
        insert A;


        Date myDate = Date.newInstance(2016, 2, 17);

        //Create a order
        Order od = new Order();
        od.P_O_No__c = 'testponumber';
        od.Order_Stage__c='Open';
        od.Account.id=A.id;
        od.EffectiveDate=myDate;
        
        Test.startTest();
        sendMail('This is a test');
        insert od;
        Test.stopTest();
    }
}

Not sure how to test such a email trigger. 
Hello I am writing a test calss and I need create a quote object for testing purpose. However, quote(Detail) has a master-detail relarionship with opportunity object (Master). There fore when I wrote "Quote.Opportunity.Id=Opportunity.ID", it reports "Deference a NULL value " Error. Is there anyone know why is this happening and how to fix it? Any help is appreciated. 

Here are my codes:
Opportunity O = new Opportunity();
        O.Name='sss';
        O.AccountId=A.ID;
        O.LeadSource='Other';
        O.Type='New Business';
        O.CloseDate=myDate;
        O.StageName='Qualify';
        O.CurrencyIsoCode='CAD';
        
        Insert O;
        
        Quote Q=new Quote();
        Q.Name='TestQuote';
        Q.Status='Deaft';
        Q.Payment_Terms__c='Payment Schedule';
        Q.FOB__c='Our Shop';
        Q.Freight__c='Collect';
        Q.Lead_Time__c='TBA';
        Q.Email='liam@shaverinc.com';
        Q.ShippingState='ON';
        Q.Opportunity.Id=O.Id;
        Insert Q;

Thank you!
Hello
I wrote a trigger that sends an email order confirmation to the contact when an order object is inserted. However, I need to write a test calss for the code coverage. I am not sure how to do such a test. Any help will be apprecated. Thanks in advance.

Here is my trigger
trigger OrderConfirmatiob on Order (before insert) {
        
        for(Order o : Trigger.New) {
        if(o.Contact_Email__c != NULL){
   
          List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();                    
 
            String[] toAddresses = new String[] {o.Contact_Email__c};
 
            mail.setToAddresses(toAddresses);
 
            mail.setSubject('Automated email: Order Confirmation');
            //mail.setTargetObjectId(o.Id);
            //mail.setSaveAsActivity(false);
            mail.setHtmlBody('Some Message' );
            //mail.setTemplateId(et.Id);

         emails.add(mail);
         Messaging.sendEmail(emails);
              //Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

        }
       }
    }

Here is what I have so far for the test class but it is not finished.

@isTest

private class TestOrderConfirmationEmail {

 public static void sendMail(string message) {

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {'liam@shaverinc.com'};
        mail.setToAddresses(toAddresses);

        mail.setSubject('My Subject');

        mail.setUseSignature(false);
        mail.setHtmlBody(message);

        // Send the email
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

    }   


    
    static testMethod void TestOrderEmail(){
        Account A = new Account(Name='ttt');
        insert A;


        Date myDate = Date.newInstance(2016, 2, 17);

        //Create a order
        Order od = new Order();
        od.P_O_No__c = 'testponumber';
        od.Order_Stage__c='Open';
        od.Account.id=A.id;
        od.EffectiveDate=myDate;
        
        Test.startTest();
        sendMail('This is a test');
        insert od;
        Test.stopTest();
    }
}

Not sure how to test such a email trigger.