• Ckevin1984
  • NEWBIE
  • 0 Points
  • Member since 2010

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

Hi all,

I'm going to give my colleagues a presentation about the introduction of Vmforce. What content should i include to make this presentation clear and brief. Thanks a lot to any help.

After I watched the demo video of the VMforce, i found that my account does not have the vmforce for java in the Deployment. Do i need to have a special vmforce accout to get access?

I have written a trigger and try to change the trigger to bulk trigger version. Can anyone help me, i feel confused about bulk trigger. You can just make some change in one recordTypeId and post back as a reply. Thank you very much in advance. Here is my whole trigger looks like.

 

trigger TimeSheetTrigger on Timesheet__c (after delete, after insert,after update)
{
double sumTotalHours = 0.0;

Campaign[] sheetsToUpdateCampaign = new Campaign[]{};
Case[] sheetsToUpdateCase = new Case[]{};
Contract[] sheetsToUpdateContract = new Contract[]{};
Job__c[] sheetsToUpdateJob = new Job__c[]{};
Opportunity[] sheetsToUpdateOpportunity = new Opportunity[]{};
Project__c [] sheetsToUpdateProject = new Project__c[]{};


//***********************************************
//Code for updating existing records and new records
//***********************************************

if(Trigger.isInsert)
{
Timesheet__c [] teNew = trigger.new;

for(Timesheet__c te : teNew)
{
//The selected RecordType is Campaign
if(te.RecordTypeId == '012200000001Xyp')
{
for (Campaign timesheet : [select Id,Name, Hours__c from Campaign ])
{
//Sum all the timesheet entries
for (Timesheet__c timeEntries: [select Id, Hours__c from Timesheet__c where Campaign__c = :timesheet.Id ])
{
sumTotalHours += timeEntries.Hours__c;
}

timesheet.Hours__c = sumTotalHours;

//add timesheet to list to be updated outside of the loop
sheetsToUpdateCampaign.add(timesheet);
update sheetsToUpdateCampaign;
}
}

//The selected RecordType is Case
if(te.RecordTypeId == '012200000001X36')
{
for (Case timesheet : [select Id, Hours__c from Case ])
{

//Sum all the timesheet entries
for (Timesheet__c timeEntries: [select Id, Hours__c from Timesheet__c where Case__c = :timesheet.Id])
{
sumTotalHours += timeEntries.Hours__c;
}

timesheet.Hours__c = sumTotalHours;

//add timesheet to list to be updated outside of the loop
sheetsToUpdateCase.add(timesheet);
update sheetsToUpdateCase;
}
}
//The selected RecordType is Contract
if(te.RecordTypeId == '012200000001Xyk')
{
for (Contract timesheet : [select Id,Name, Total_Contract_Hours__c from Contract ])
{

//Sum all the timesheet entries
for (Timesheet__c timeEntries: [select Id, Hours__c from Timesheet__c where Contract__c = :timesheet.Id])
{
sumTotalHours += timeEntries.Hours__c;
}

timesheet.Total_Contract_Hours__c = sumTotalHours;

//add timesheet to list to be updated outside of the loop
sheetsToUpdateContract.add(timesheet);
update sheetsToUpdateContract;
}
}
//The selected RecordType is Job
if(te.RecordTypeId == '012200000001X3B')
{
for (Job__c timesheet : [select Id,Name, Hours__c from Job__c ])
{

//Sum all the timesheet entries
for (Timesheet__c timeEntries: [select Id, Hours__c from Timesheet__c where Job__c = :timesheet.Id])
{
sumTotalHours += timeEntries.Hours__c;
}

timesheet.Hours__c = sumTotalHours;

//add timesheet to list to be updated outside of the loop
sheetsToUpdateJob.add(timesheet);
update sheetsToUpdateJob;
}
}

//The selected RecordType is Opportunity
if(te.RecordTypeId == '012200000001YBG')
{
for (Opportunity timesheet : [select Id,Name, Hours__c from Opportunity ])
{

//Sum all the timesheet entries
for (Timesheet__c timeEntries: [select Id, Hours__c from Timesheet__c where Opportunity__c = :timesheet.Id])
{
sumTotalHours += timeEntries.Hours__c;
}

timesheet.Hours__c = sumTotalHours;

//add timesheet to list to be updated outside of the loop
sheetsToUpdateOpportunity.add(timesheet);
update sheetsToUpdateOpportunity;
}
}

//The selected RecordType is Project
if(te.RecordTypeId == '012200000001X31')
{
for (Project__c timesheet : [select Id,Name, Hours__c from Project__c ])
{

//Sum all the timesheet entries
for (Timesheet__c timeEntries: [select Id, Hours__c from Timesheet__c where Project__c = :timesheet.Id])
{
sumTotalHours += timeEntries.Hours__c;
}

timesheet.Hours__c = sumTotalHours;

//add timesheet to list to be updated outside of the loop
sheetsToUpdateProject.add(timesheet);
update sheetsToUpdateProject;
}
}
}


}

//***********************************************
//Code for updating when a record is updated
//***********************************************

else if(Trigger.isUpdate)
{
//sum total both old and new
Timesheet__c [] oldTime = Trigger.old;
Timesheet__c [] newTime = Trigger.new;
Double newSum = 0.0;
Double oldSum = 0.0;

for(Timesheet__c newTe: newTime)
{
for(Timesheet__c oldTe : oldTime)
{

//Selected RecordType is Campaign
if(newTe.RecordTypeId == '012200000001Xyp')
{
Campaign oldTimesheet = [Select Id, Name, Hours__c from Campaign where id = :oldTe.Campaign__c];
Campaign newTimesheet = [Select Id, Name, Hours__c from Campaign where id = :newTe.Campaign__c];

Timesheet__c [] oldSumHours = [Select Id,Name, Hours__c from Timesheet__c where Campaign__c = :oldTimesheet.Id];
Timesheet__c [] newSumHours = [Select Id, Name, Hours__c  from Timesheet__c where Campaign__c = :newTimesheet.Id];

//sum premiums from child objects
for(Timesheet__c oldSumHour : oldSumHours)
{
oldSum += oldSumHour.Hours__c;
}

for(Timesheet__c newSumHour : newSumHours)
{
newSum += newSumHour.Hours__c;

}
oldTimesheet.Hours__c= oldSum;
newTimesheet.Hours__c = newSum;

sheetsToUpdateCampaign.add(newTimesheet);
if(newTimesheet.Id != oldTimesheet.Id)
{
sheetsToUpdateCampaign.add(oldTimesheet);
}
}

//Selected RecordType is Case
if(newTe.RecordTypeId == '012200000001X36')
{
Case oldTimesheet = [Select Id, Hours__c from Case where id = :oldTe.Case__c];
Case newTimesheet = [Select Id, Hours__c from Case where id = :newTe.Case__c];

Timesheet__c [] oldSumHours = [Select Id,Name, Hours__c from Timesheet__c where Case__c = :oldTimesheet.Id];
Timesheet__c [] newSumHours = [Select Id, Name, Hours__c  from Timesheet__c where Case__c = :newTimesheet.Id];

//sum premiums from child objects
for(Timesheet__c oldSumHour : oldSumHours)
{
oldSum += oldSumHour.Hours__c;
}

for(Timesheet__c newSumHour : newSumHours)
{
newSum += newSumHour.Hours__c;
}
oldTimesheet.Hours__c= oldSum;
newTimesheet.Hours__c = newSum;

sheetsToUpdateCase.add(newTimesheet);
if(newTimesheet.Id != oldTimesheet.Id)
{
sheetsToUpdateCase.add(oldTimesheet);
}
}

//Selected RecordType is Contract
if(newTe.RecordTypeId == '012200000001Xyk')
{
Contract oldTimesheet = [Select Id, Name, Total_Contract_Hours__c from Contract where id = :oldTe.Contract__c];
Contract newTimesheet = [Select Id, Name, Total_Contract_Hours__c from Contract where id = :newTe.Contract__c];

Timesheet__c [] oldSumHours = [Select Id,Name, Hours__c from Timesheet__c where Contract__c = :oldTimesheet.Id];
Timesheet__c [] newSumHours = [Select Id, Name, Hours__c  from Timesheet__c where Contract__c = :newTimesheet.Id];

//sum premiums from child objects
for(Timesheet__c oldSumHour : oldSumHours)
{
oldSum += oldSumHour.Hours__c;
}

for(Timesheet__c newSumHour : newSumHours)
{
newSum += newSumHour.Hours__c;

}
oldTimesheet.Total_Contract_Hours__c= oldSum;
newTimesheet.Total_Contract_Hours__c = newSum;

sheetsToUpdateContract.add(newTimesheet);
if(newTimesheet.Id != oldTimesheet.Id)
{
sheetsToUpdateContract.add(oldTimesheet);
}
}

//Selected RecordType is Job
if(newTe.RecordTypeId == '012200000001X3B')
{
Job__c oldTimesheet = [Select Id, Name, Hours__c from Job__c where id = :oldTe.Job__c];
Job__c newTimesheet = [Select Id, Name, Hours__c from Job__c where id = :newTe.Job__c];

Timesheet__c [] oldSumHours = [Select Id,Name, Hours__c from Timesheet__c where Job__c = :oldTimesheet.Id];
Timesheet__c [] newSumHours = [Select Id, Name, Hours__c  from Timesheet__c where Job__c = :newTimesheet.Id];

//sum premiums from child objects
for(Timesheet__c oldSumHour : oldSumHours)
{
oldSum += oldSumHour.Hours__c;
}

for(Timesheet__c newSumHour : newSumHours)
{
newSum += newSumHour.Hours__c;

}
oldTimesheet.Hours__c= oldSum;
newTimesheet.Hours__c = newSum;

sheetsToUpdateJob.add(newTimesheet);
if(newTimesheet.Id != oldTimesheet.Id)
{
sheetsToUpdateJob.add(oldTimesheet);
}
}
//Selected RecordType is Opportunity
if(newTe.RecordTypeId == '012200000001YBG')
{
Opportunity oldTimesheet = [Select Id, Name, Hours__c from Opportunity where id = :oldTe.Opportunity__c];
Opportunity newTimesheet = [Select Id, Name, Hours__c from Opportunity where id = :newTe.Opportunity__c];

Timesheet__c [] oldSumHours = [Select Id,Name, Hours__c from Timesheet__c where Opportunity__c = :oldTimesheet.Id];
Timesheet__c [] newSumHours = [Select Id, Name, Hours__c  from Timesheet__c where Opportunity__c =

:newTimesheet.Id];

//sum premiums from child objects
for(Timesheet__c oldSumHour : oldSumHours)
{
oldSum += oldSumHour.Hours__c;
}

for(Timesheet__c newSumHour : newSumHours)
{
newSum += newSumHour.Hours__c;

}
oldTimesheet.Hours__c= oldSum;
newTimesheet.Hours__c = newSum;

sheetsToUpdateOpportunity.add(newTimesheet);
if(newTimesheet.Id != oldTimesheet.Id)
{
sheetsToUpdateOpportunity.add(oldTimesheet);
}
}

//Selected RecordType is Project
if(newTe.RecordTypeId == '012200000001X31')
{
Project__c oldTimesheet = [Select Id, Name, Hours__c from Project__c where id = :oldTe.Project__c];
Project__c newTimesheet = [Select Id, Name, Hours__c from Project__c where id = :newTe.Project__c];

Timesheet__c [] oldSumHours = [Select Id,Name, Hours__c from Timesheet__c where Project__c = :oldTimesheet.Id];
Timesheet__c [] newSumHours = [Select Id, Name, Hours__c  from Timesheet__c where Project__c = :newTimesheet.Id];

//sum premiums from child objects
for(Timesheet__c oldSumHour : oldSumHours)
{
oldSum += oldSumHour.Hours__c;
}

for(Timesheet__c newSumHour : newSumHours)
{
newSum += newSumHour.Hours__c;

}
oldTimesheet.Hours__c= oldSum;
newTimesheet.Hours__c = newSum;

sheetsToUpdateProject.add(newTimesheet);
if(newTimesheet.Id != oldTimesheet.Id)
{
sheetsToUpdateProject.add(oldTimesheet);
}
}

}
}

//commit the changes to Salesforce
if(newTime[0].RecordTypeId == '012200000001Xyp')
update sheetsToUpdateCampaign;
if(newTime[0].RecordTypeId == '012200000001X36')
update sheetsToUpdateCase;
if(newTime[0].RecordTypeId == '012200000001Xyk')
update sheetsToUpdateContract;
if(newTime[0].RecordTypeId == '012200000001X3B')
update sheetsToUpdateJob;
if(newTime[0].RecordTypeId == '012200000001YBG')
update sheetsToUpdateOpportunity;
if(newTime[0].RecordTypeId == '012200000001X31')
update sheetsToUpdateProject;
}

//***********************************************
//Code for updating when a record is deleted
//***********************************************

else if(Trigger.isDelete)
{

Timesheet__c [] teOld = trigger.old;

for(Timesheet__c te: teOld)
{
if(te.RecordTypeId == '012200000001Xyp')
{
for (Campaign timesheet: [select Id, Name, Hours__c from Campaign])
{
for (Timesheet__c timeEntries: [select Id, Hours__c from Timesheet__c where Campaign__c = :timesheet.Id])
{
sumTotalHours += timeEntries.Hours__c;
}

timesheet.Hours__c = sumTotalHours;

sheetsToUpdateCampaign.add(timesheet);
}
}

if(te.RecordTypeId == '012200000001X36')
{
for (Case timesheet: [select Id, Hours__c from Case])
{
for (Timesheet__c timeEntries: [select Id, Hours__c from Timesheet__c where Case__c = :timesheet.Id])
{
sumTotalHours += timeEntries.Hours__c;
}

timesheet.Hours__c = sumTotalHours;

sheetsToUpdateCase.add(timesheet);
}
}

if(te.RecordTypeId == '012200000001Xyk')
{
for (Contract timesheet: [select Id, Name, Total_Contract_Hours__c from Contract])
{
for (Timesheet__c timeEntries: [select Id, Hours__c from Timesheet__c where Contract__c = :timesheet.Id])
{
sumTotalHours += timeEntries.Hours__c;
}

timesheet.Total_Contract_Hours__c = sumTotalHours;

sheetsToUpdateContract.add(timesheet);
}
}

if(te.RecordTypeId == '012200000001X3B')
{
for (Job__c timesheet: [select Id, Name, Hours__c from Job__c])
{
for (Timesheet__c timeEntries: [select Id, Hours__c from Timesheet__c where Job__c = :timesheet.Id])
{
sumTotalHours += timeEntries.Hours__c;
}

timesheet.Hours__c = sumTotalHours;

sheetsToUpdateJob.add(timesheet);
}
}

if(te.RecordTypeId == '012200000001YBG')
{
for (Opportunity timesheet: [select Id, Name, Hours__c from Opportunity])
{
for (Timesheet__c timeEntries: [select Id, Hours__c from Timesheet__c where Opportunity__c = :timesheet.Id])
{
sumTotalHours += timeEntries.Hours__c;
}

timesheet.Hours__c = sumTotalHours;

sheetsToUpdateOpportunity.add(timesheet);
}
}

if(te.RecordTypeId == '012200000001X31')
{
for (Project__c timesheet: [select Id, Name, Hours__c from Project__c])
{
for (Timesheet__c timeEntries: [select Id, Hours__c from Timesheet__c where Project__c = :timesheet.Id])
{
sumTotalHours += timeEntries.Hours__c;
}

timesheet.Hours__c = sumTotalHours;

sheetsToUpdateProject.add(timesheet);
}
}

}

//commit the changes to Salesforce
if(teOld[0].RecordTypeId == '012200000001Xyp')
update sheetsToUpdateCampaign;
if(teOld[0].RecordTypeId == '012200000001X36')
update sheetsToUpdateCase;
if(teOld[0].RecordTypeId == '012200000001Xyk')
update sheetsToUpdateContract;
if(teOld[0].RecordTypeId == '012200000001X3B')
update sheetsToUpdateJob;
if(teOld[0].RecordTypeId == '012200000001YBG')
update sheetsToUpdateOpportunity;
if(teOld[0].RecordTypeId == '012200000001X31')
update sheetsToUpdateProject;
}     
}

I met a problem when i run the test method on my trigger.Can anyone help me to find out the problem.Thanks for any help

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, TimeSheetTrigger: execution of AfterInsert caused by: System.ListException: Duplicate id in list: 701R0000000EUYBIA4 Trigger.TimeSheetTrigger: line 61, column 1: []

Just need to have a test method for a bulk trigger, any example will be ok. thanks very much for any help

if i have the sentence Timesheet__c [] teNew = trigger.new  in my code. How can i know the number of Timesheet it has

I am writing a trigger about the "Timesheet" object and other six objects which have the lookup relationship with the 'Timesheet' and also the Record Types of 'Timesheet' .  There is a field named Hours in the 'Timesheet' and Hours are also in all the other six objects. When i create a new 'Timesheet'  i need to choose the RecordType first. For example, it is a Project Timesheet. Then, when i put number  in the Hours field and click Save button. The Hours of Project should also be updated. I have tested my trigger in a single object, it does work. The problem comes when i need to make it works for six objects. I need to write a if statement to judge which recordType is selected. How can i get the value of the selected recordType? Thanks very much for any help

Can i do the rollup summary in the other object in a Look-up relationship just like doing the rollup summary in the parent object in the Master-detail relationship. And if it is possible, can you tell me the differences between the two object types. Waiting for your helps. 

How can i reach the last record in the for loop as following:

for (Timesheet__c timeSheet: [select Total_Hours__c, Hours__c from Timesheet__c])

I want to do some operation in the last timesheet. Thanks in advance for any help.

Hi all,

I have a object named Timesheet, it has two fields : TotalHours and Hours. What i want is after i add a new Timesheet and enter numbers in the Hours field and click save button, the TotalHours field will show the accumulated Hours till now. But the code below doesn't work properly. Anyone helps me, thank a lot .

 

trigger TimeSheetTrigger on Timesheet__c (after delete, after insert)
{
    double TotalHours = 0.0;
    for (Timesheet__c timeSheet: [select Hours__c from Timesheet__c ])
    {
        TotalHours += timeSheet.Hours__c;
        if(timeSheet.Hours__c != NULL)
        {
            timeSheet.Total_Hours__c = TotalHours;
            update timeSheet;
        }
    }       
}

 

Hi all,

I am a newer to apex, here is the trigger i wrote having the error message  "maximum trigger depth exceeded" .

 

trigger TimeSheetTrigger on Timesheet__c (after delete, after insert, after update)
{
    double TotalHours = 0.0;
    for (Timesheet__c timeSheet: [select Id, Hours__c from Timesheet__c ])
    {
        TotalHours += timeSheet.Hours__c;
        if(timeSheet.Hours__c != NULL)
        {
            timeSheet.Total_Hours__c = TotalHours;
            update timeSheet;
        }
    }       
}

How can i reach the last record in the for loop as following:

for (Timesheet__c timeSheet: [select Total_Hours__c, Hours__c from Timesheet__c])

I want to do some operation in the last timesheet. Thanks in advance for any help.

Hi all,

I have a object named Timesheet, it has two fields : TotalHours and Hours. What i want is after i add a new Timesheet and enter numbers in the Hours field and click save button, the TotalHours field will show the accumulated Hours till now. But the code below doesn't work properly. Anyone helps me, thank a lot .

 

trigger TimeSheetTrigger on Timesheet__c (after delete, after insert)
{
    double TotalHours = 0.0;
    for (Timesheet__c timeSheet: [select Hours__c from Timesheet__c ])
    {
        TotalHours += timeSheet.Hours__c;
        if(timeSheet.Hours__c != NULL)
        {
            timeSheet.Total_Hours__c = TotalHours;
            update timeSheet;
        }
    }       
}

 

Hi all,

I am a newer to apex, here is the trigger i wrote having the error message  "maximum trigger depth exceeded" .

 

trigger TimeSheetTrigger on Timesheet__c (after delete, after insert, after update)
{
    double TotalHours = 0.0;
    for (Timesheet__c timeSheet: [select Id, Hours__c from Timesheet__c ])
    {
        TotalHours += timeSheet.Hours__c;
        if(timeSheet.Hours__c != NULL)
        {
            timeSheet.Total_Hours__c = TotalHours;
            update timeSheet;
        }
    }       
}