• Chris Bettini
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 1
    Likes Given
  • 3
    Questions
  • 1
    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;           
              
             }
}


 
public with sharing class PositionHistSearchController {

    public String positionhist { get; set; }
  
  // the soql without the order and limit
  private String soql {get;set;}
  // the collection of contacts to display
  public List<PositionHistory__c> positionhistlist {get;set;}
  
  // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }
  
  // the current field to sort by. defaults to last name
  public String sortField {
    get  { if (sortField == null) {sortField = 'Name'; } return sortField;  }
    set;
  }
  
  // format the soql for display on the visualforce page
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }

  // init the controller and display some sample data when the page loads
  public PositionHistSearchController() {
    soql = 'select Name, Investor__r.Name, product__r.name, Balance_Date__c, Balance__c from PositionHistory__c where Name != null';
    runQuery();
  }
  
  // toggles the sorting of query from asc<-->desc
  public void toggleSort() {
    // simply toggle the direction
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
    // run the query again
    runQuery();
  }
  
  // runs the actual query
  public void runQuery() {
        
    try {
      positionhistlist = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    } catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
    }

  }
  
  // runs the search with parameters passed via Javascript
  public PageReference runSearch() {
    
    String Name = Apexpages.currentPage().getParameters().get('name');
    String Investor = Apexpages.currentPage().getParameters().get('investor');
    String effectiveDate = Apexpages.currentPage().getParameters().get('asofDate');
    String product = Apexpages.currentPage().getParameters().get('product');
        
    soql = 'select Name, Investor__r.Name, product__r.name, Balance_Date__c, Balance__c from PositionHistory__c where Name != null';
    if (!Name.equals(''))
      soql += ' and (name LIKE \'%'+ Name +'%\' or investor__r.Name LIKE \'%'+ Name +'%\')';
    if (!effectiveDate.equals(''))
      soql += ' and asofDate = ' + effectiveDate ;
    if (!product.equals(''))
      soql += ' and product__r.Name LIKE \'%'+ product +'%\'' ;
 

    // run the query again
    runQuery();

    return null;
  }
I know I can pass the Contact ID from the active page and show a related list, but having trouble figuring out how to show the related list one more level down. For the active contact I need to show the list of his clients and each clients investments.

Financial Advisor (Contact)
    Client list (master-detail to Contact)
         Client Investments (master-detail to Client)

Any help and insight is much appreciated! thanks!

 
I know I can pass the Contact ID from the active page and show a related list, but having trouble figuring out how to show the related list one more level down. For the active contact I need to show the list of his clients and each clients investments.

Financial Advisor (Contact)
    Client list (master-detail to Contact)
         Client Investments (master-detail to Client)

Any help and insight is much appreciated! thanks!

 
I'm getting an error when trying to query SQL Server and insert into SFDC using Data Loader.    Invalid Fetch Size.
I'm connecting using ODBC so not sure where I can set Featch size.
2014-06-19 11:03:24,097 ERROR [CountInsertDB] action.AbstractAction handleExcept
ion (AbstractAction.java:200) - Exception occured during loading
com.salesforce.dataloader.exception.DataAccessObjectInitializationException: Dat
abase error encountered during setup of the database configuration: queryEmploye
rCounts.  Sql error: Invalid Fetch Size.
        at com.salesforce.dataloader.dao.database.DatabaseReader.setupQuery(Data
baseReader.java:149)
        at com.salesforce.dataloader.dao.database.DatabaseReader.open(DatabaseRe
ader.java:110)
        at com.salesforce.dataloader.dao.database.DatabaseReader.open(DatabaseRe
ader.java:98)
        at com.salesforce.dataloader.action.AbstractAction.execute(AbstractActio
n.java:116)
        at com.salesforce.dataloader.controller.Controller.executeAction(Control
ler.java:124)
        at com.salesforce.dataloader.process.ProcessRunner.run(ProcessRunner.jav
a:149)
        at com.salesforce.dataloader.process.ProcessRunner.run(ProcessRunner.jav
a:100)
        at com.salesforce.dataloader.process.ProcessRunner.main(ProcessRunner.ja
va:253)
Caused by: java.sql.SQLException: Invalid Fetch Size
        at sun.jdbc.odbc.JdbcOdbcStatement.setFetchSize(Unknown Source)
        at org.apache.commons.dbcp.DelegatingStatement.setFetchSize(DelegatingSt
atement.java:279)
        at org.apache.commons.dbcp.DelegatingStatement.setFetchSize(DelegatingSt
atement.java:279)
        at com.salesforce.dataloader.dao.database.DatabaseReader.setupQuery(Data
baseReader.java:141)
        ... 7 more
22227 [CountInsertDB] ERROR com.salesforce.dataloader.action.InsertAction  - Exc
eption occured during loading
com.salesforce.dataloader.exception.DataAccessObjectInitializationException: Dat
abase error encountered during setup of the database configuration: queryEmploye
rCounts.  Sql error: Invalid Fetch Size.
        at com.salesforce.dataloader.dao.database.DatabaseReader.setupQuery(Data
baseReader.java:149)
        at com.salesforce.dataloader.dao.database.DatabaseReader.open(DatabaseRe
ader.java:110)
        at com.salesforce.dataloader.dao.database.DatabaseReader.open(DatabaseRe
ader.java:98)
        at com.salesforce.dataloader.action.AbstractAction.execute(AbstractActio
n.java:116)
        at com.salesforce.dataloader.controller.Controller.executeAction(Control
ler.java:124)
        at com.salesforce.dataloader.process.ProcessRunner.run(ProcessRunner.jav
a:149)
        at com.salesforce.dataloader.process.ProcessRunner.run(ProcessRunner.jav
a:100)
        at com.salesforce.dataloader.process.ProcessRunner.main(ProcessRunner.ja
va:253)
Caused by: java.sql.SQLException: Invalid Fetch Size
        at sun.jdbc.odbc.JdbcOdbcStatement.setFetchSize(Unknown Source)
        at org.apache.commons.dbcp.DelegatingStatement.setFetchSize(DelegatingSt
atement.java:279)
        at org.apache.commons.dbcp.DelegatingStatement.setFetchSize(DelegatingSt
atement.java:279)
        at com.salesforce.dataloader.dao.database.DatabaseReader.setupQuery(Data
baseReader.java:141)
        ... 7 more
2014-06-19 11:03:24,122 ERROR [CountInsertDB] progress.NihilistProgressAdapter d
oneError (NihilistProgressAdapter.java:58) - Database error encountered during s
etup of the database configuration: queryEmployerCounts.  Sql error: Invalid Fet
ch Size.
22252 [CountInsertDB] ERROR com.salesforce.dataloader.action.progress.NihilistPr
ogressAdapter  - Database error encountered during setup of the database configu
ration: queryEmployerCounts.  Sql error: Invalid Fetch Size.
I'm getting an error when trying to query SQL Server and insert into SFDC using Data Loader.    Invalid Fetch Size.
I'm connecting using ODBC so not sure where I can set Featch size.
2014-06-19 11:03:24,097 ERROR [CountInsertDB] action.AbstractAction handleExcept
ion (AbstractAction.java:200) - Exception occured during loading
com.salesforce.dataloader.exception.DataAccessObjectInitializationException: Dat
abase error encountered during setup of the database configuration: queryEmploye
rCounts.  Sql error: Invalid Fetch Size.
        at com.salesforce.dataloader.dao.database.DatabaseReader.setupQuery(Data
baseReader.java:149)
        at com.salesforce.dataloader.dao.database.DatabaseReader.open(DatabaseRe
ader.java:110)
        at com.salesforce.dataloader.dao.database.DatabaseReader.open(DatabaseRe
ader.java:98)
        at com.salesforce.dataloader.action.AbstractAction.execute(AbstractActio
n.java:116)
        at com.salesforce.dataloader.controller.Controller.executeAction(Control
ler.java:124)
        at com.salesforce.dataloader.process.ProcessRunner.run(ProcessRunner.jav
a:149)
        at com.salesforce.dataloader.process.ProcessRunner.run(ProcessRunner.jav
a:100)
        at com.salesforce.dataloader.process.ProcessRunner.main(ProcessRunner.ja
va:253)
Caused by: java.sql.SQLException: Invalid Fetch Size
        at sun.jdbc.odbc.JdbcOdbcStatement.setFetchSize(Unknown Source)
        at org.apache.commons.dbcp.DelegatingStatement.setFetchSize(DelegatingSt
atement.java:279)
        at org.apache.commons.dbcp.DelegatingStatement.setFetchSize(DelegatingSt
atement.java:279)
        at com.salesforce.dataloader.dao.database.DatabaseReader.setupQuery(Data
baseReader.java:141)
        ... 7 more
22227 [CountInsertDB] ERROR com.salesforce.dataloader.action.InsertAction  - Exc
eption occured during loading
com.salesforce.dataloader.exception.DataAccessObjectInitializationException: Dat
abase error encountered during setup of the database configuration: queryEmploye
rCounts.  Sql error: Invalid Fetch Size.
        at com.salesforce.dataloader.dao.database.DatabaseReader.setupQuery(Data
baseReader.java:149)
        at com.salesforce.dataloader.dao.database.DatabaseReader.open(DatabaseRe
ader.java:110)
        at com.salesforce.dataloader.dao.database.DatabaseReader.open(DatabaseRe
ader.java:98)
        at com.salesforce.dataloader.action.AbstractAction.execute(AbstractActio
n.java:116)
        at com.salesforce.dataloader.controller.Controller.executeAction(Control
ler.java:124)
        at com.salesforce.dataloader.process.ProcessRunner.run(ProcessRunner.jav
a:149)
        at com.salesforce.dataloader.process.ProcessRunner.run(ProcessRunner.jav
a:100)
        at com.salesforce.dataloader.process.ProcessRunner.main(ProcessRunner.ja
va:253)
Caused by: java.sql.SQLException: Invalid Fetch Size
        at sun.jdbc.odbc.JdbcOdbcStatement.setFetchSize(Unknown Source)
        at org.apache.commons.dbcp.DelegatingStatement.setFetchSize(DelegatingSt
atement.java:279)
        at org.apache.commons.dbcp.DelegatingStatement.setFetchSize(DelegatingSt
atement.java:279)
        at com.salesforce.dataloader.dao.database.DatabaseReader.setupQuery(Data
baseReader.java:141)
        ... 7 more
2014-06-19 11:03:24,122 ERROR [CountInsertDB] progress.NihilistProgressAdapter d
oneError (NihilistProgressAdapter.java:58) - Database error encountered during s
etup of the database configuration: queryEmployerCounts.  Sql error: Invalid Fet
ch Size.
22252 [CountInsertDB] ERROR com.salesforce.dataloader.action.progress.NihilistPr
ogressAdapter  - Database error encountered during setup of the database configu
ration: queryEmployerCounts.  Sql error: Invalid Fetch Size.