• Jingyuan Xie
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
hi everyone, i had an after trigger to help on copy specific attachment from proposal to its parent opportunity, the trigger code is like this

trigger CopyAttachmentsToOpps on Attachment (after insert) {

    // collect a set of Proposal 'parent' IDs from the attachments inserted
    Set<Id> proposalIds = new Set<Id>();
    for(Attachment file : Trigger.new) {
// only collect those that are for the proposal object (others can be ignored)
    
        if(file.ParentId.getSObjectType() == Apttus_Proposal__Proposal__c.getSObjectType() && file.Name.containsIgnoreCase('quote English 20')) {
            proposalIds.add(file.ParentId);
        }
    }

    if(!proposalIds.isEmpty()) {

        // find the Opportunity to which the Proposal relates
        Map<Id,Apttus_Proposal__Proposal__c> proposalMap = new Map<Id,Apttus_Proposal__Proposal__c>([Select Apttus_Proposal__Opportunity__c From Apttus_Proposal__Proposal__c Where Id IN :proposalIds ]);        

        List<Attachment> attachments = new List<Attachment>();

        for(Attachment file : Trigger.new) 
        {
            Attachment newFile = file.clone();
            newFile.ParentId = proposalMap.get(file.ParentId).Apttus_Proposal__Opportunity__c;
            attachments.add(newFile);
        }
        // insert the cloned attachments
        insert attachments;
    }


}

i want to write an test class to deploy it into produciton, here is so far i did ,it only coverage 30% how can i improve that?

@isTest 
public class TestCopyAttachmentsToOpps {
    static testMethod void testCopyattachs() {

       // create quote attachment from scratch

       Attachment att   = new attachment();
       att.body  =  Blob.valueOf('Unit Test Attachment Body 1');
       att.name = 'quote english hahahah';
       att.ParentId= 'a5no0000000GxEz';
       insert att;
       
 Map<Id,Apttus_Proposal__Proposal__c> proposalMap = new Map<Id,Apttus_Proposal__Proposal__c>([Select Apttus_Proposal__Opportunity__c From Apttus_Proposal__Proposal__c Where Id ='a5no0000000GxEz' ]);        

        List<Attachment> attachments = new List<Attachment>();
            attachment newfile= new attachment();
            newFile.ParentId = '006o000000NEmIB';
            newfile.body=att.body;
            newfile.name=att.name;
        insert attachments;
    }


}
Hello everyone , i am trying to write a trigger before oppty creation or update , populate account's ultimated parent account if it present, but not having any luck with my code, and i don't know how to fetch account's ultimated parent account based on account hirechy please help to review ,big thanks!

trigger populateultimateparentaccount on opportunity(Before Insert, Before Update) 
{
    Map <Id, Id> ultimateaccountMap = new Map <Id, Id> ();

    for (Opportunity account : trigger.new)
    {
        ultimateaccountMap.put(account.xxxxxxx, null);
    }

    for (Account account : [SELECT Id, xxxxxx FROM Account WHERE xxxxx IN :ultimateaccountMap.keySet()])
    {
        ultimateaccountMap.put(ultimateaccountMap.get(account.xxxxxx), account.Id);
    }

    List <opportunity> NewOppToUpdate = new List <opportunity> ();

    for (opportunity account : trigger.new)
    {
        if (ultimateaccountMap.containsKey(account.xxxx) 
        {
            // Existing account ultimate parent found
            Opportunity newopportunity = new Opportunity(Id = ultimateaccountMap.get(account.xxxx));
  

    update newopportunity;
}
Hi all,
I had an existing VF email template that display a table show all related(Child)Cases for case, see the code here, i also want to add one more filter that only display all closed(case status=closed) related cases within the table . To make this i created a apex class for fetching list of closed cases , but i dont know how to refer this into a component that conbine the email template table so that i can invoke the component in me email template , can anyone help give some light on this? thanks

<messaging:emailTemplate recipientType="Contact"
  relatedToType="case"
  subject=" XXX report for Case Number: {!relatedTo.casenumber}"
  replyTo="XXX">
  <messaging:htmlEmailBody >
    <html>
      <body>
        <STYLE type="text/css">
          TH {font-size: 11px; font-face: arial;background: #CCCCCC;
               border-width: 0;  text-align: center } 
          TD  {font-size: 11px; font-face: verdana } 
          TABLE {border: solid #000000; border-width: 1;border="1"}
          TR {border: solid #000000; border-width: 1}
        </STYLE>
        <font face="arial" size="2">
          <p>Dear {!recipient.name},</p>
          <p>Below is the detail of your parentcase: {!relatedTo.casenumber}.</p>
          <table border="0" >
            <tr > 
               <th>Childcase #</th>
               <th>Problem Found</th>
               <th>Status</th>
            </tr>
            <apex:repeat var="cx" value="{!relatedTo.cases}">
              <tr>
                <td>{!cx.casenumber}</td>
                <td>{!cx.Problem_Found__c}</td>
                <td>{!cx.status}</td>
              </tr>
            </apex:repeat>   
              
          </table>
                   
          <p />
        </font>
       
      </body>
       
    </html>
  </messaging:htmlEmailBody> 
   </messaging:emailTemplate>
 
Hello everyone , i am trying to write a trigger before oppty creation or update , populate account's ultimated parent account if it present, but not having any luck with my code, and i don't know how to fetch account's ultimated parent account based on account hirechy please help to review ,big thanks!

trigger populateultimateparentaccount on opportunity(Before Insert, Before Update) 
{
    Map <Id, Id> ultimateaccountMap = new Map <Id, Id> ();

    for (Opportunity account : trigger.new)
    {
        ultimateaccountMap.put(account.xxxxxxx, null);
    }

    for (Account account : [SELECT Id, xxxxxx FROM Account WHERE xxxxx IN :ultimateaccountMap.keySet()])
    {
        ultimateaccountMap.put(ultimateaccountMap.get(account.xxxxxx), account.Id);
    }

    List <opportunity> NewOppToUpdate = new List <opportunity> ();

    for (opportunity account : trigger.new)
    {
        if (ultimateaccountMap.containsKey(account.xxxx) 
        {
            // Existing account ultimate parent found
            Opportunity newopportunity = new Opportunity(Id = ultimateaccountMap.get(account.xxxx));
  

    update newopportunity;
}