• ArunDavidNSI
  • NEWBIE
  • 5 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 6
    Replies

I have two buttons on the contact screen.  Log a Call and Log a Meeting.  When these are selected the corresponding screen to log a call or meeting comes up.

Upon saving the call or meeting a trigger is called on insert /update/delete.  This trigger updates a Status field on the contact record.  The updates works however, the contact screen will not show this field as updated until I hit F5.   I have reproduced this in Both FireFox and Chrome.

 

Thanks in advance for your help.

Lawrence

  • July 10, 2013
  • Like
  • 0

I've got an after insert\after update trigger running off the Account object which is upsertting a new child record (object name : "SubsidiariesAndBrands__c"). It's running fine, but for some reason I can't get this test class to work properly. 

 

Here is the whole test class : 

 

public with sharing class AutoCreateSubsOnAccountTriggerTest {

    static testMethod void testAutoCreateSubsOnAccountTriggerTest() {
        // Set up test User.
        User testUser = generateTestUser();

        // Generate Account
        Account acc = new Account(Name = testUser.Id);
 
        // Start test and insert sub
        Test.startTest();
        insert acc;
        Test.stopTest();

        // Get the subs from the DB to ensure they were created
        List<SubsidiariesAndBrands__c> subs = [SELECT
                                                 Id
                                             FROM
                                                 SubsidiariesAndBrands__c
                                             WHERE
                                                 Parent_Account__c = :acc.Id
        ];

        // There should be 1 sub
        System.assert(1 == subs.size(), 'One sub object is expected');
    }

    private static User generateTestUser(){
        // using the System Admin profile because it will always be there
        Profile sysAdmin = [SELECT 
                               Id 
                            FROM 
                               Profile 
                            WHERE 
                               Name = 'System Administrator'
                            LIMIT 1
        ];
 
        // Generate the user
        User newUser = new User(
            UserName = 'unit.tester@example.com',
            LastName = 'Test',
            FirstName = 'Jane',
            CompanyName = 'TestCo',
            Title = 'Developer',
            Email = 'unit.tester@example.com',
            ProfileId = sysAdmin.Id,
            emailencodingkey = 'UTF-8',
            languagelocalekey = 'en_US',
            localesidkey = 'en_US',
            timezonesidkey = 'America/Los_Angeles'
        );

        // Insert that user
        insert newuser;

        return newuser;
    }
}

 It's error-ing out on the line I underlined, with the error message of : "System.AssertException: Assertion Failed: One sub object is expected"


I guess for some reason the sub record isn't being created. I can't figure out why. 

 

 

Here is the actual trigger if you need it : 

 

 

trigger AutoCreateSubOnAccount on Account (after insert, after update) {
         public string type{get;set;}
List <SubsidiariesAndBrands__c> subToInsert = new List <SubsidiariesAndBrands__c> ();
      
    for (Account o : Trigger.new) { 
         
        type = o.Auto_Formula_Record_Type__c;
          System.debug('xxx type string xxx ' + type );
                   
        SubsidiariesAndBrands__c v = new SubsidiariesAndBrands__c (); //instantiate the object to put values for future record
        
                  
        v.Parent_Account__c= o.id; 
        v.Name = o.Name;
        v.SubName__c = o.Name;
        v.Industry__c = o.Industry; 
        v.Subsidary_Brand_Account_Number__c = o.Account_Number__c;
        v.ParentRecName__c = type;
                
        subToInsert.add(v);
      
    }
    
    try {
       if (type == 'Ultimate Parent') 
        upsert subToInsert SubName__c; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
    
}

 

 

Thank you very much for your help and input.

 

I'm using the standardSetController to implement pagination in a VF page.  In my controller I have a property totalPages that returns an integer.  The problem is that the value is not rounding up.  For example, if I have a resultSize of 200 and a pageSize of 5, the totalPages should be 40.  If I have a resultSize of 7 and pageSize of 5, the totalPages should be 2.

 

I've been digging thru the math methods trying to get the value to round up correctly.

 

I've tried the following:

 

 

Decimal totalPages = Decimal.valueOf(setCtrl.getResultSize() / setCtrl.getPageSize()).round(RoundingMode.UP);
			return totalPages.intValue();

 It is not rounding up.  Can anyone help with how I can get my totalPages to round up correctly?

 

Thanks for any help.

I'm trying to loop through a local list a number of times.  It seems like it works when I have a single record but not when I have more.  I suspect that my multiple 'for' loops don't start from the begining of the list each time.

Can anyone tell me where I'm going wrong?

 

Thanks,

 

Kevin

 

Integer SpeakingRecordCount;
Boolean PastLeadershipBoard;
Boolean EmeritusTrustee;
Boolean LeadershipBoard;


try {

// Store Contact record ID
map< id, contact > contacts = new map< id, contact >();
map< id, account > accounts = new map< id, account >();
       
if (trigger.isinsert || trigger.isupdate) 
    {
     
       // Create trigger for new or selected npe5__Affiliation__c  record
       for(npe5__Affiliation__c  record:trigger.new)        
       {

        // Build local list of Affiliation records 
       List<npe5__Affiliation__c > affl = new List <npe5__Affiliation__c>();
       affl=[Select id, npe5__Contact__c, npe5__Organization__c ,Type__c, npe5__Status__c, npe5__Role__c from npe5__Affiliation__c  
       WHERE npe5__Contact__c = :record.npe5__Contact__c AND npe5__Organization__c = :record.npe5__Organization__c ];

        // Loop through the local Affiliation list to parse results for Contact Record


        for (npe5__Affiliation__c li: affl) {
            if (li.npe5__Contact__c == record.npe5__Contact__c 
                && li.Type__c.contains('Board') && li.npe5__Status__c == 'Current' )
                LeadershipBoard = TRUE;
            else {
                LeadershipBoard = FALSE;
            }
        }
        
        for (npe5__Affiliation__c li: affl) {
            if (li.npe5__Contact__c == record.npe5__Contact__c 
                && li.Type__c.contains('Board') && li.npe5__Status__c == 'Former' )
                PastLeadershipBoard = TRUE;
            else {
                PastLeadershipBoard = FALSE;
            }
        }
        
     // Construct Contact record update with results  
        contacts.put(record.npe5__contact__c, new contact(id=record.npe5__contact__c, Leadership_Board__C = LeadershipBoard, Past_Leadership_Board__c = PastLeadershipBoard ));               

     // Update Contact record
        update contacts.values(); 


        }   
    }

 

 

Hi,

 

I have 3 objects:

Analysis (Parent of Project)

             Project (Parent of Project Analysis)

                        Project Analysis

On change of any field in Analysis, I need to mass update the Projects records for which I use a custom button. The code as follows:

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

var records = {!GETRECORDIDS($ObjectType.Project1__c)}; 
var newRecords = []; 

if (records[0] == null) 

alert("Please select at least one row") 

else 

for (var n=0; n<=records.length; n++) { 
var t = new sforce.SObject("Project1__c"); 
t.id = records[n]; 
newRecords.push(t); 

result = sforce.connection.update(newRecords); 

window.location.reload(); 
}

 

The code updates the changes in Project records. But on this update of Project records a trigger needs to  work on Project Analysis records as follows. But in my case Project analysis records will be changed to 0 records. Meaning the update trigger code as follows is not working due to some reason:

 

trigger EqupdProjectAnalysis on Project1__c(after update)
 {
    List<Project_Analysis__c> ProjectAnalysis = new List <Project_Analysis__c> {};
    for (Project1__c p : trigger.new)
    {
       if(p.Start_Date_check__c == 1)
        {
          Project1__c[] updrec = [select id,start_Date_check__c from Project1__c pj where id = :p.id]; 
          for(Project1__c p1:updrec)
          {
         
          p1.start_Date_check__c=0;
          update p1;
          }
          Project_Analysis__c[] objsToDelete = [select id from Project_Analysis__c ol1 where ol1.Project1__c = :p.id];  
          delete objsToDelete; 
        }
        if(p.Start_Date_check__c == 1)
        {
          if ((p.Project_Type__c!='Master')&&(p.EPC_Awarding_Date__c !=null))
             {
                Integer i = 0;
                date Date1= p.EPC_Awarding_Date__c ;
                date myDate1=Date1;
                Decimal x=0;
                Decimal y=0;
                for (i=0;i< p.No_of_Months__c; i++) 
                {
                   
                    if((myDate1>=p.EPC_Awarding_Date__c) && (myDate1 < p.EndDate__c))
                   {
                       if(myDate1<=p.Q1__c)
                       {
                           x=p.Eq_Q1_month__c;
                         }
                       else if(myDate1<=p.Q2__c)
                       {
                           x=p.Eq_Q2_month__c;
                        }
                        else if(myDate1<p.Q3__c)
                       {
                           x=p.Eq_Q3_month__c;
                        }
                       else if(myDate1>=p.Q3__c)
                       {
                           x=p.Eq_Q4_month__c;
                        } 
                       }
                     else
                     {
                         x=0;
                     }
                   
                   if((myDate1>=p.EPC_Awarding_Date__c) && (myDate1 < p.EndDate__c))
                  {
                       if(myDate1<=p.Q1_FM__c)
                       {
                           y=p.FM_Q1_month__c;
                          
                       }
                       else if(myDate1<=p.Q2_FM__c)
                       {
                           y=p.FM_Q2_month__c;
                        }
                        else if(myDate1<p.Q3_FM__c)
                       {
                           y=p.FM_Q3_month__c;
                        }
                       else if(myDate1>=p.Q3_FM__c)
                       {
                           y=p.FM_Q4_month__c;
                        } 
                      }
                     else
                     {
                         y=0;
                     }
                   
                  ProjectAnalysis.add(new Project_Analysis__c(Project1__c= p.Id,Amount_per_month__c=x,FM__c=y,Date__c = myDate1));       
                  MyDate1=MyDate1.addMonths(1); 
                 }               
                }
           }
         }
         try
         {
               insert ProjectAnalysis;
          }
          catch (Exception Ex)
          {    
               system.debug(Ex);
          }
     }

 

Note: If I individually edit and save the project record, project analysis records are populated correctly.

 

Any help is greatly appreciated.

 

Thanks,

Liz