• Harvey Jethro
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 7
    Replies
Hi All,

I created the Apex class below to create attachments using the blob class. The attachment are from the HTML version of emails. 

I'm getting the attachemnts but the first coloum of the HTML table is removed.

Thanks!

Additionally, 

I found out that I can parse incoming HTML email content from this link https://developer.salesforce.com/forums/?id=906F0000000934IIAQ. 
The issue I'm having with this solution is that Blob will not accept array of strings. 
global class EmailtooCaseExample implements Messaging.InboundEmailHandler {
   
  
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.Inboundenvelope env) 
    {
         String myHtmlBody = email.HtmlBody;
        final String className = 'EmailtooCase';
        String METHOD_NAME='handleInboundEmail';
        
            
        String caseNum='';
        String toAddress='';
        String toAddresses='';
        String ccAddresses='';
        String forwardingEmails='';
       
        
        
        String myBody = email.plainTextBody;
       
        
        
      
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
   
         
        try{
                                   
                                   
                                    Attachment newment = new Attachment(
                                    ParentId = '5XX77111116MqZqANK',
                                    Name = 'letstest.pdf',
                                    ContentType = 'application-pdf',
                                    Body = blob.topdf(email.HtmlBody));
                                 
                               Database.insert(newment);                   
                            
           }
                             
        catch(DmlException e) {System.debug('The following exception has occurred: ' + e.getMessage());
           }

        return result;
    }
    
    

}

The Actual HTML TableThe Corrupted Table
I have a Parent object (Contact) and a Child object (Customer__c). The Child object's text field (Corp__c) values in order of weight are: "Very Viable",  "Averagely Viable", "Somewhat Viable", "Not Viable" and "Indifferent". If a parent record has two Child records so that Corp__c for the two records are "Averagely Viable" and "Not Viable", then I want a picklist field on the parent to update as "Averagely Viable" (since "Averagely Viable" has more weight than "Not Viable").
My first question is :
Can I write a trigger on a managed package (The Custom Object Definition is managed)?

Secondly, I've written a trigger for newly created Customer records for a start but it is just not working. 

trigger CorpUpdate on Customer__c (after insert) {
    if(Trigger.isInsert){
                          try {
                     
                    for (Customer__c co : Trigger.new){
                        Contact po = [SELECT Id, picklist__c FROM Contact WHERE Id = :co.npe5__Contact__c];               
                      List<Customer__c> l_co = [SELECT Id,Corp__c ,npe5__Contact__c FROM Customer__c
                       WHERE npe5__Contact__c = :po.Id];
                        for(Customer__c am_co : l_co) {
                            if(am_co.Corp__c  == 'Very Viable' || am_co.Corp__c  == 'Averagely Viable') {
 
                            am_co.Corp__c   = 'Very Viable';
                        }
     
                        else if (am_co.Corp__c  == 'Very Viable' || am_co.Corp__c  == 'Somewhat Viable') {
                         am_co.Corp__c   = 'Very Viable';      
                       }
                      else if(am_co.Corp__c  == 'Very Viable' || am_co.Corp__c == 'Not Viable' )
                        {
                        am_co.Corp__c   = 'Very Viable';
                        }       
                    else if(am_co.Corp__c  == 'Very Viable' || am_co.Corp__c  == 'Indifferent' )
                     {
                        am_co.Corp__c   = 'Very Viable';
                    }
                    else if(am_co.Corp__c  == 'Averagely Viable' || am_co.Corp__c  == 'Somewhat Viable' )
                    {
                        am_co.Corp__c   = 'Averagely Viable';
                    }
                    else if(am_co.Corp__c  == 'Averagely Viable' || am_co.Corp__c  == 'Not Viable' )
                    {
                        am_co.Corp__c   = 'Averagely Viable';
                    }
                    else if(am_co.Corp__c  == 'Averagely Viable' || am_co.Corp__c  == 'Indifferent' )
                    {
                        am_co.Corp__c   = 'Averagely Viable';
                    }
                    else if(am_co.Corp__c  == 'Somewhat Viable' || am_co.Corp__c  == 'Not Viable' )
                    {
                    am_co.Corp__c   = 'Somewhat Viable';
                    }
                    else if(am_co.Corp__c  == 'Somewhat Viable' || am_co.Corp__c  == 'Indifferent' )
                    {
                    am_co.Corp__c   = 'Somewhat Viable';
                     }
                    else if(am_co.Corp__c  == 'Not Viable' || am_co.Corp__c  == 'Indifferent' )
                    {
                     am_co.Corp__c   = 'Not Viable';
                    }
                    else {
                  am_co.Corp__c = 'Indifferent' ;
                  }
                 po.picklist__c = l_co.Corp__c;
           }             
           update po;         
      }
      
            } catch (Exception e) {
                System.debug(e);
            }
        }
   
  
}


     

I'm a newbie when it comes to Triggers any help would be greatly appreciated!
Hi all,
I'm currently having an issue with writing the test class for the attached try and catch. The code selects one or more parent records (Department__c) and creates detail records depending on the number of selected parent records. I've tried all my abilities and did a lot of online research but the nested for loop inside the try and catch is not covered. Please, see below for the code snippet. Your assistance will be appreciated.

        try{
            if(selectedBranchReport1.size() > 0){            
            List<Store__c> con1 = new List<store__c>();
                              
              for(Integer i = 0; i < selectedBranchReport1.size(); i++) {
               
                for(Integer j = 0; j < bLs.size(); j++)              
                {   
                   
                    bLs[j].Dpt__c = selectedBranchReport1[j].Id;
                    con1.add(bLs[j]);
                   
                }
               }
                   if(con1 != null){
                    upsert bLs;
                                   
Hi everyone!

We need to track students late payment. When they are accepted to our school, the Representatives will toggle "Acceptance Letter Issued" stage. When the students pay their fees, the Reps will toggle "Registered" as the students are ready to be enrolled.

We have a deadline for payment as well. If Reps don't toggle a different stage after "Acceptance Letter Issued" stage after the deadline, we want a custom field to indicate that the student is late on paying their fees.

What would be the best practice to accomplish this project? Please give me some advice.

Thank you!
Hello everyone!
I have a problem.
I'd like to prevent removing data in the Account's phone field, by using Apex code. I know you can do this in the UI, but I need to do it this way.
I've already done this:

Trigger:
trigger AccountTrigger2 on Account (before update) {
    AccountTriggerHandler handler = new AccountTriggerHandler();
 
    if (Trigger.IsUpdate && Trigger.IsBefore) {
        handler.onBeforeUpdate(Trigger.New, Trigger.OldMap);
    }
}


Handler:
Public class AccountTriggerHandler {

    public void onBeforeUpdate(List<Account> accountList, Map<Id, Account> accountOldMap) {
        
        for(Account aItem : accountList) {
            Account oldAccountItem = accountOldMap.get(aItem.Id);
            if(aItem.phone == null && oldAccountItem.phone != null) {
                aItem.phone = oldAccountItem.phone;
            }
        }
    }

}
This works well when testing in the UI, but the problems come with the test:
@isTest
public class AccountTriggerHandlerTest {

    @isTest
    public static void onBeforeUpdateTest(){
        Account test = new Account(name='Test 1', phone='1234');
        insert test;
        
        test.phone = NULL;
        update test;
        
        System.assertNotEquals(NULL, test.phone);
    }
    
}
I'd expect the phone to have 1234, but it has NULL, failing the test.
It says: System.AssertException: Assertion Failed: Same value: null
Any idea?

Best regards!
Hi all,
I'm currently having an issue with writing the test class for the attached try and catch. The code selects one or more parent records (Department__c) and creates detail records depending on the number of selected parent records. I've tried all my abilities and did a lot of online research but the nested for loop inside the try and catch is not covered. Please, see below for the code snippet. Your assistance will be appreciated.

        try{
            if(selectedBranchReport1.size() > 0){            
            List<Store__c> con1 = new List<store__c>();
                              
              for(Integer i = 0; i < selectedBranchReport1.size(); i++) {
               
                for(Integer j = 0; j < bLs.size(); j++)              
                {   
                   
                    bLs[j].Dpt__c = selectedBranchReport1[j].Id;
                    con1.add(bLs[j]);
                   
                }
               }
                   if(con1 != null){
                    upsert bLs;
                                   
The challenge is:

You've been given a requirement to keep Contact addresses in sync with the Account they belong to. Use Process Builder to create a new process that updates all child Contact addresses when the address of the Account record is updated. This process:Can have any name.
Must be activated.
Must update Contact mailing address fields (Street, City, State, Post Code, Country) when the parent Account shipping address field values are updated.

I start with Accounts when records is created or edited.
Filter criteria where accounts shipping address (street, city, state, zip code) is changed (used "or" logic).

I am stuck on the next step "add action".  I started with action type "Update Records".
On objects, I can't seem to change Accounts to Contacts.  Why?