• olaitan adesoji
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
This trigger creates an opposing relationship between contacts in a juntion object when an initial one is created.  eg. i create a link from Bob to Jon, and the trigger creates the link Jon to Bob.  It also creates a comma separated string of the contact ids on each of the respective contacts each time a junction record is created or deleted. I cant seem to get past 41% coverage and not having any luck with the string concatenation part in the test class.  
trigger teamLinkUpdate on TeamMemberLink__c (before insert, after insert, after delete) {
    
    if(Trigger.isAfter){
        if(Trigger.isInsert){
                try {
                    for (TeamMemberLink__c t : Trigger.new){
                        Contact c = [SELECT Id, TeamMemberLinks_List__c  FROM Contact WHERE Id = :t.ContactLink1__c];
                        
                        List<TeamMemberLink__c> l_co = [SELECT ContactLink2__c FROM TeamMemberLink__c WHERE ContactLink1__c = :c.Id];
                        String[] stringList = new String[0];
                        for(TeamMemberLink__c lstr : l_co) {
                            String strId = String.valueOf(lstr.ContactLink2__c);
                            stringList.add(strId);  
                        }
                       String result = String.join(stringList, ', ');                   
                       c.TeamMemberLinks_List__c  = result;
    
                        update c;
                    }
                } catch (Exception e) {
                    System.debug(e);
                }
            for (TeamMemberLink__c t : Trigger.new){
                        List<TeamMemberLink__c> tchk = [Select Id from TeamMemberLink__c where ContactLink2__c = :t.ContactLink1__c];
                        if(tchk.isEmpty()){
                        
                            List<TeamMemberLink__c> rel = new List<TeamMemberLink__c>();
                                TeamMemberLink__c tnew = new TeamMemberLink__c(ContactLink1__c = t.ContactLink2__c, ContactLink2__c = t.ContactLink1__c);
                            rel.add(tnew);
                            insert rel;
                           
                        }
                }
            }
        if(Trigger.isDelete){
                try {
                    for (TeamMemberLink__c t : Trigger.old){
                        Contact c = [SELECT Id, TeamMemberLinks_List__c  FROM Contact WHERE Id = :t.ContactLink1__c];
                        
                        List<TeamMemberLink__c> l_co = [SELECT ContactLink2__c FROM TeamMemberLink__c WHERE ContactLink1__c = :c.Id];
                        String[] stringList = new String[0];
                        for(TeamMemberLink__c lstr : l_co) {
                            String strId = String.valueOf(lstr.ContactLink2__c);
                            stringList.add(strId);  
                        }
                       String result = String.join(stringList, ', ');                   
                       c.TeamMemberLinks_List__c  = result;
    
                        update c;
                    }
                } catch (Exception e) {
                    System.debug(e);
                }
            
            }
    }
}
test class
@isTest
public class teamLinkUpdateTest {
	static testMethod void testUpdate()
    {	
              
        TeamMemberLink__c tm = new TeamMemberLink__c();
        tm.ContactLink1__c = '0034A00002lPY13QAG';
        tm.ContactLink2__c = '003G000002DpiytIAB';
        insert tm;           
              
             }
}


 
Just getting more practice with formulas but have run into an obstacle. Hopefully I'm overthinking it, but I'm writing a throw away formula:

IF( AnnualRevenue >= 1000000, NumberOfEmployees, " ???  ")

The goal is to throw an error message telling the user if the "AnnualRevenue" is greater than or equal to one million, then the "NumberOfEmployees" field is mandatory, else do nothing. What value do I need to enter in the "false" field? I've tried using "null" however there needs to be an actual value. Is using an "IF" statement the wrong route to take for this goal?

Any assistance is more than welcome. Thanks in adnvacned!!
In my visualforce having StandardController ="Contact" and created a custom button using html <div> tag now  I would like to save the details by clicking this custom button using StandardAction save .How to call the standard action on Html tag . 
 FYI:
<apex:page  standardController="Contact">
    <style>
    #header {
        /*line-height:30px; text-transform: uppercase;*/
    background-color:#fff000;
    height:20px;
    width:50px;
    float:left;
    padding:5px; 
     color: red;
    font-family: "Times New Roman", Times, serif;    
     text-align: center;   
    border-radius: 15px;   
}
        #header:hover{
        cursor:pointer; 
        background-color:#ff9933;
        opacity:0.5;
        }
     </style> 
    <apex:form id="fm">
        <apex:pageBlock>
            <apex:pageBlockButtons>
               <div id="header">
                   save
                   <apex:actionSupport event="onclick" action="{!save}" rerender="fm"/>
                </div>
               
      </apex:pageBlockButtons>      
            <apex:pageBlockSection>
                <apex:inlineEditSupport>
                    <apex:outputField value="{!Contact.lastName}"/>
                    <apex:outputField value="{!Contact.firstName}"/>
                </apex:inlineEditSupport>
            </apex:pageBlockSection>
        </apex:pageBlock
    </apex:form>
</apex:page>