• Basil Choudhry
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
I'm trying to get an opportunity to be sent to be approved when a checkbox is ticked (the checkbox will be ticked by various workflows).

This is the code I've cobbled together from various sources:

trigger OpportunitySubmitForApproval1 on Opportunity (after update) {

for (Opportunity a : trigger.new) {
if (a.Send_for_Approval__c == TRUE) {
    Approval.ProcessSubmitRequest app = new Approval.ProcessSubmitRequest();
    ID addendumId = a.Id;

      Approval.ProcessSubmitRequest request = new Approval.ProcessSubmitRequest();
            request.setObjectId(addendumId);
            Approval.ProcessResult requestResult = Approval.process(request);
  }
}
}


This is working fine for me in Sandbox. However, I'm having trouble making a test class to bring it over to production. The test class I've cobbled together is 
@isTest
public class OpportunitySubmitForApproval1Test {
    static testMethod void testApprovalSuccess() {

        Opportunity opp = new Opportunity();
        opp.Name = 'Test Opp';
        opp.Amount = 100;
        opp.CloseDate = Date.today();
        opp.Probability = 10;
        opp.StageName = 'Prospecting';
        opp.Send_for_Approval__c = FALSE;
        // insert the new opp
        insert opp;
        // change the probability of the opp so the trigger submits it for approval
    opp.Probability = 40;
        opp.Send_for_Approval__c = TRUE;
    // update the opp which should submit it for approval
    update opp;

        // ensure that the opp was submitted for approval
        List < ProcessInstance > processInstances = [select Id, Status from ProcessInstance where TargetObjectId = :opp.id];
    System.assertEquals(processInstances.size(),1);

    }


}
I've got an email template with various merge fields, one of which is the Event Time, however, it refuses to push the event time through into the email. Other non-event merge fields work fine (Contact name, User name, account name etc). It appears that the issue is because Events don't have a standard parent-child relationship with other objects and because you can't send an email directly from an Event but have to do it from an Account/Opportunity.

All I want to be able to do is book an event, and then have an email template that includes the date & time of the event to send to the customer.

Is there a workaround that can be used for this?
Hi,

I've just made our first trigger in the sandbox, it's working fine and it's quite simple. But when I try to deploy it I get various errors about test coverage. I understand that these are saying I need to test the code, but after some googling I'm not sure: do I need to add this test to the trigger itself, what does the test need to look like?

This is the trigger:

trigger ChangeOpportunityToProposalSent on Task (after insert) {

    ID OppId;
        Set<ID> setSTRIDs = new Set<ID>();
        for (Task tasks:Trigger.New){
          //if (tasks.What.Type== 'Opportunity')
        
           setSTRIDs.add(tasks.WhatId);
           Opportunity opp= [SELECT StageName FROM Opportunity WHERE ID IN:setSTRIDs];
           if(tasks.Subject=='RE: Your Tailored Proposal'){opp.StageName='Proposal Sent';}
           update opp;
       
         }

Any help would be greatly appreciated.
I've got an email template with various merge fields, one of which is the Event Time, however, it refuses to push the event time through into the email. Other non-event merge fields work fine (Contact name, User name, account name etc). It appears that the issue is because Events don't have a standard parent-child relationship with other objects and because you can't send an email directly from an Event but have to do it from an Account/Opportunity.

All I want to be able to do is book an event, and then have an email template that includes the date & time of the event to send to the customer.

Is there a workaround that can be used for this?
I'm trying to get an opportunity to be sent to be approved when a checkbox is ticked (the checkbox will be ticked by various workflows).

This is the code I've cobbled together from various sources:

trigger OpportunitySubmitForApproval1 on Opportunity (after update) {

for (Opportunity a : trigger.new) {
if (a.Send_for_Approval__c == TRUE) {
    Approval.ProcessSubmitRequest app = new Approval.ProcessSubmitRequest();
    ID addendumId = a.Id;

      Approval.ProcessSubmitRequest request = new Approval.ProcessSubmitRequest();
            request.setObjectId(addendumId);
            Approval.ProcessResult requestResult = Approval.process(request);
  }
}
}


This is working fine for me in Sandbox. However, I'm having trouble making a test class to bring it over to production. The test class I've cobbled together is 
@isTest
public class OpportunitySubmitForApproval1Test {
    static testMethod void testApprovalSuccess() {

        Opportunity opp = new Opportunity();
        opp.Name = 'Test Opp';
        opp.Amount = 100;
        opp.CloseDate = Date.today();
        opp.Probability = 10;
        opp.StageName = 'Prospecting';
        opp.Send_for_Approval__c = FALSE;
        // insert the new opp
        insert opp;
        // change the probability of the opp so the trigger submits it for approval
    opp.Probability = 40;
        opp.Send_for_Approval__c = TRUE;
    // update the opp which should submit it for approval
    update opp;

        // ensure that the opp was submitted for approval
        List < ProcessInstance > processInstances = [select Id, Status from ProcessInstance where TargetObjectId = :opp.id];
    System.assertEquals(processInstances.size(),1);

    }


}
I've got an email template with various merge fields, one of which is the Event Time, however, it refuses to push the event time through into the email. Other non-event merge fields work fine (Contact name, User name, account name etc). It appears that the issue is because Events don't have a standard parent-child relationship with other objects and because you can't send an email directly from an Event but have to do it from an Account/Opportunity.

All I want to be able to do is book an event, and then have an email template that includes the date & time of the event to send to the customer.

Is there a workaround that can be used for this?
Hi,

I've just made our first trigger in the sandbox, it's working fine and it's quite simple. But when I try to deploy it I get various errors about test coverage. I understand that these are saying I need to test the code, but after some googling I'm not sure: do I need to add this test to the trigger itself, what does the test need to look like?

This is the trigger:

trigger ChangeOpportunityToProposalSent on Task (after insert) {

    ID OppId;
        Set<ID> setSTRIDs = new Set<ID>();
        for (Task tasks:Trigger.New){
          //if (tasks.What.Type== 'Opportunity')
        
           setSTRIDs.add(tasks.WhatId);
           Opportunity opp= [SELECT StageName FROM Opportunity WHERE ID IN:setSTRIDs];
           if(tasks.Subject=='RE: Your Tailored Proposal'){opp.StageName='Proposal Sent';}
           update opp;
       
         }

Any help would be greatly appreciated.