-
ChatterFeed
-
1Best Answers
-
1Likes Received
-
0Likes Given
-
41Questions
-
53Replies
Determine what Qtr something was created?
For example: if I run a report today (11/9/15 - Qtr4) the report needs to show eveything created since Aug. I was thinkning about creating a custome formula field on the Opportunity record with an output of a checkbox with a simple True/False result, but i can not come up with the logic.
Any thoughts?
- tmbarry
- November 09, 2015
- Like
- 0
Error: Compile Error: Method does not exist or incorrect signature: TriggerHandlerTask()
My Class is:
public class TriggerHandlerTask { public TriggerHandlerTask(){} public void UpdateTaskType(Task[] newTasks){ for (Task t1 : NewTasks){ /* Developer : Todd Barry Created : Last Modified : 05/18/2015 Test Class : Objective : When a PSS or COS BCC's to salesforce, this will ensure the correct Activity Type is set */ // Only update the task type if a type value has not already been selected If (t1.type==null){ if(t1.subject.contains('email') || t1.subject.contains('Email')){ t1.type='Email';} if(t1.subject.contains('meet') || t1.subject.contains('Meet')){ t1.type='Meeting'; } else if(t1.subject.contains('visit')|| t1.subject.contains('Visit')) t1.type='Office Visit'; if(t1.subject.contains('call') || t1.subject.contains('Call')) t1.type='Phone Call'; else if(t1.subject!= null) t1.type='Other'; } // This update is for emails BCC to salesforce. if(t1.subject.contains('email:') || t1.subject.contains('Email:')){ t1.Activity_type_01__c='Email';} } }}
And my Trigger is:
trigger UpdateTaskType on Task (before insert, before Update) { If(Trigger.isBefore){ if(Trigger.isInsert){ TriggerHandlerTask Handler = TriggerHandlerTask(); Handler.UpdateTaskType(Trigger.new); } If(Trigger.isUpdate){ } } Else If(Trigger.isAfter){ if(Trigger.isInsert){ } If(Trigger.isUpdate){ } } }But i keep getting this error: Error: Compile Error: Method does not exist or incorrect signature: TriggerHandlerTask() at line 6 column 38
What am I missing?
- tmbarry
- May 18, 2015
- Like
- 0
Change the Posting User of a Chatter Item
The problem is, that the chatter post comes from the person who won the opportunity, so it looks like they are patting themselves on the back. I created a user called Sales Operations. How do I make all these automated posts come from this Sales Operations user?
<pre>
trigger CreateChatterEntry on Opportunity (before Update) {
For(opportunity opp : Trigger.new){
// Check to see if the Oppty was previously Marked Closed Won
Opportunity beforeUpdate = System.Trigger.oldMap.get(opp.Id);
if(beforeUpdate.IsWon != opp.IsWon){
String ownerIds = opp.Oppty_Owner_Name__c;
String oppName = opp.name;
Set<ID> ownerId = new Set<ID>();
ownerId.add(opp.ownerId);
Map<ID,User> userMap = new Map<ID,User>([SELECT ID, Name, FirstName FROM User WHERE ID In : ownerid]); //This is our user map
User uName = userMap.get(opp.ownerId);
// Get a list of All the Current Chatter Group Names
List<CollaborationGroup> Grps = [Select Name, Id FROM CollaborationGroup];
Map<string, String> GrpName = new Map<string, string>{};
for(CollaborationGroup gn: Grps)
Grpname.put(gn.name,gn.id);
// If the Oppty is marked Closed Won, Create Chatter entry.
If(opp.iswon ==true){
FeedItem fitem = new FeedItem ();
fitem.type = 'LinkPost';
fitem.ParentId = grpName.get('Salesforce.com Users'); //Select What Chatter group to post message in.
fitem.LinkUrl = '/' + opp.id; //This is the url to take the user to the activity
fitem.Title = oppName + ' Opportunity'; //This is the title that displays for the LinkUrl
//fitem.Body = ('Congratulations to ' + uName.name + ' on winning ' + oppname + '! Nice Job '+ uName.firstname+'.');
fitem.Body = ('Congratulations to ' + uName.name + ' on winning ' + oppname + '!');
Insert fitem;
} }
}}
</pre>
- tmbarry
- April 07, 2014
- Like
- 1
Need to pull an existing User Record
I am trying to create a test class for a new trigger and it involves a lookup to a user record. In my test class, do i have to create a new user entry, or is there a way to to reference any existing users in the org for the test?
- tmbarry
- August 30, 2013
- Like
- 0
Error: Compile Error: Illegal assignment from Schema.SObjectField to String at line 7 column 1
Can someone help with this error message?
trigger SD_Member_Check_Member_Status on SD_Member__c (after insert, after update) { // If Master Status = Ineligible // And Post Referral to CC Status = (In Treatment OR No Contact 30 Days OR No Contact 60 Days) For (SD_Member__c SD : Trigger.new){ String MS1 = SD_Member__c.Master_status__c; If(MS1 == 'Ineligible'){ } } }
The Issue is this line:
String MS1 = SD_Member__c.Master_status__c;
The Master_Status__c field is a Formula (Text) field and the formula is:
If(
TEXT( Post_Referral_to_CC_Status__c ) = "Graduated","Graduated",
If(
TEXT( Member_Eligibility_Status__c ) = "Ineligible-Cov", "Ineligible",
If(
AND (TEXT( Member_Eligibility_Status__c ) = "Ineligible-Geo",TEXT (Record_Invalid__c) <> "Override: Eligible Plan/Geo"), "Ineligible",
If(
AND (TEXT( Member_Eligibility_Status__c ) = "Ineligible-Plan",TEXT (Record_Invalid__c) <> "Override: Eligible Plan/Geo"), "Ineligible",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "In Treatment - Active","In Treatment",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "In Treatment - No Contact 30 Days","In Treatment",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "In Treatment - No Contact 60 Days","In Treatment",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "In Treatment","In Treatment",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "No Contact 30 Days","In Treatment",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "No Contact 60 Days","In Treatment",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "Ineligible - Medically Excluded","Ineligible",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "Deceased","Ineligible",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "Requires Higher Level of Care","Ineligible",
If(
TEXT( Member_Eligibility_Status__c )="Ineligible-LUSD","Ineligible",
If(
TEXT( Member_Eligibility_Status__c )="Ineligible-NonSD","Ineligible",
If(
TEXT( Catasys_Medical_Exclusion_Status__c )<>"Medically Targeted","Ineligible",
if(
AND (Len(TEXT( Record_Invalid__c ))>0,TEXT (Record_Invalid__c) <> "Override: Eligible Plan/Geo" ), "Ineligible",
"Outreach Candidate"
)))))))))))))))))
- tmbarry
- August 29, 2013
- Like
- 0
Error Error: Compile Error: Variable does not exist:
I have a trigger that works fine. This trigger pulls weekly updates from a child object and updates fields on the Opportunity record. There are three items on the Weekly Update object: Status Update, Risks, & Next Steps.
trigger UpdateOpportunityStatusFromWeeklyUpdate on Weekly_Update__c (after insert, after Update) { for (Weekly_Update__c WU : Trigger.new) { Date dt=wu.date__c; String strOppId = wu.Opportunity_Name__c; List<RecordType> rtypes = [Select Name, Id From RecordType where sObjectType='Opportunity' and isActive=true]; //Create a map between the Record Type Name and Id for easy retrieval Map<String,String> opptyRecordTypes = new Map<String,String>{}; for(RecordType rt: rtypes) opptyRecordTypes.put(rt.Name,rt.Id); for (Opportunity opp : [SELECT id, name, RecordTypeId FROM Opportunity WHERE id =: strOppId]){ If(opp.RecordTypeId ==opptyRecordTypes.get('MMA') || opp.RecordTypeId ==opptyRecordTypes.get('MMA - Market Monitoring')) { String strA = dT.month() + '/' + dt.day() + '/' + dt.year()+' - ' + wu.rptOwnerName__c + ': '+ wu.Status_Update__c ; String strB = dT.month() + '/' + dt.day() + '/' + dt.year()+' - ' + wu.rptOwnerName__c + ': '+ wu.Risks__c ; String strC = dT.month() + '/' + dt.day() + '/' + dt.year()+' - ' + wu.rptOwnerName__c + ': '+ wu.Next_Steps__c ; Opportunity O = new Opportunity(Id=wu.Opportunity_Name__c, Opportunity_Update__c=stra, Opportunity_Next_Steps_v2__c = strc, Opportunity_Risks__c=strb, rptStatusUpateDate__c=dt); update O;} Else { String strA = dT.month() + '/' + dt.day() + '/' + dt.year()+ ' - '+ wu.Status_Update__c ; String strB = dT.month() + '/' + dt.day() + '/' + dt.year()+ ' - '+ wu.Risks__c ; String strC = dT.month() + '/' + dt.day() + '/' + dt.year()+ ' - '+ Next1 ; Opportunity O = new Opportunity(Id=wu.Opportunity_Name__c, Opportunity_Update__c=stra, Opportunity_Next_Steps_v2__c = strc, Opportunity_Risks__c=strb, rptStatusUpateDate__c=dt); update O;} }} }
The only draw back to this code is, if one of the three fields (Status Update, Risks, & Next Steps) is Null it updates the Opportunty reocrd with the word 'Null'
Opportunity Next Steps |
|
So I wrote an if statement to check to see if the value was null and replace the value with 'No Report'
trigger UpdateOpportunityStatusFromWeeklyUpdate on Weekly_Update__c (after insert, after Update) { for (Weekly_Update__c WU : Trigger.new) { Date dt=wu.date__c; String strOppId = wu.Opportunity_Name__c; List<RecordType> rtypes = [Select Name, Id From RecordType where sObjectType='Opportunity' and isActive=true]; //Create a map between the Record Type Name and Id for easy retrieval Map<String,String> opptyRecordTypes = new Map<String,String>{}; for(RecordType rt: rtypes) opptyRecordTypes.put(rt.Name,rt.Id); /* ****Here is my New Code*** */ If(wu.Status_Update__c == ''){ String Update1 = 'No Report';} Else { String Update1 = wu.Status_Update__c;} If(wu.Risks__c == ''){ String Risk1 = 'No Report';} Else { String Risk1 = wu.Risks__c;} If(wu.Next_Steps__c == ''){ String Next1 = 'No Report';} Else { String Next1 = wu.Next_Steps__c;} for (Opportunity opp : [SELECT id, name, RecordTypeId FROM Opportunity WHERE id =: strOppId]){ If(opp.RecordTypeId ==opptyRecordTypes.get('MMA') || opp.RecordTypeId ==opptyRecordTypes.get('MMA - Market Monitoring')) { String strA = dT.month() + '/' + dt.day() + '/' + dt.year()+' - ' + wu.rptOwnerName__c + ': '+ wu.Status_Update__c ; String strB = dT.month() + '/' + dt.day() + '/' + dt.year()+' - ' + wu.rptOwnerName__c + ': '+ wu.Risks__c ; String strC = dT.month() + '/' + dt.day() + '/' + dt.year()+' - ' + wu.rptOwnerName__c + ': '+ wu.Next_Steps__c ; Opportunity O = new Opportunity(Id=wu.Opportunity_Name__c, Opportunity_Update__c=stra, Opportunity_Next_Steps_v2__c = strc, Opportunity_Risks__c=strb, rptStatusUpateDate__c=dt); update O;} Else { String strA = dT.month() + '/' + dt.day() + '/' + dt.year()+ ' - '+ Update1 ; String strB = dT.month() + '/' + dt.day() + '/' + dt.year()+ ' - '+ Risk1 ; String strC = dT.month() + '/' + dt.day() + '/' + dt.year()+ ' - '+ Next1 ; Opportunity O = new Opportunity(Id=wu.Opportunity_Name__c, Opportunity_Update__c=stra, Opportunity_Next_Steps_v2__c = strc, Opportunity_Risks__c=strb, rptStatusUpateDate__c=dt); update O;} }} }
But I am getting an error message stating: Error: Compile Error: Variable does not exist: Update1 at line 41 column 77
Which is this line:
String strA = dT.month() + '/' + dt.day() + '/' + dt.year()+ ' - '+ Update1 ;
I am sure my error is because I put my new If statements in the wrong spot:
/* ****Here is my New Code*** */ If(wu.Status_Update__c == ''){ String Update1 = 'No Report';} Else { String Update1 = wu.Status_Update__c;} If(wu.Risks__c == ''){ String Risk1 = 'No Report';} Else { String Risk1 = wu.Risks__c;} If(wu.Next_Steps__c == ''){ String Next1 = 'No Report';} Else { String Next1 = wu.Next_Steps__c;}
Any thoughts on how to fix this. The multiple IF statements are screwing me up!
- tmbarry
- August 22, 2013
- Like
- 0
Too many DML rows: 10001
I know I am missing something simple here, but I getting a:
Apex script unhandled trigger exception by user/organization: 0055000000118E4/00D50000000784t
Update_NCOA_Address_v01: System.LimitException: Too many DML rows: 10001
Error Message.
1. Can someone spot my error?
2. Is there a way to put into the code or error message which record(s) triggered the error?
trigger Update_NCOA_Address_v01 on printsf__Collateral_Send_History__c(after insert, after update) { // Update the appropriate SD_Member__c record with NCOA address from PrintSF List<SD_Member__c > recordsToUpdate = new List<SD_Member__c >(); For(printsf__Collateral_Send_History__c CSH: Trigger.new) { // Get the SD Member Id from the recipient id field //String strSDId = CSH.printsf__Recipient_ID__c; // Check to see if it is an SD Member Entry If(CSH.printsf__Recipient_ID__c!=null){ If(CSH.printsf__NCOA_Result__c == 'None') { SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c, NCOA_Error_Code__c = CSH.printsf__NCOA_Result__c, NCOA_Error_Description__c = CSH.printsf__NCOA_Result_Description__c); recordsToUpdate.add(SD); } If(CSH.printsf__NCOA_Result__c == 'Fowarded') { SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c); recordsToUpdate.add(SD); } If(CSH.printsf__NCOA_Result__c == 'Failed') { SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c, Address_Bad__c = True); recordsToUpdate.add(SD); } update recordsToUpdate; } }}
Thanks for the help.
- tmbarry
- August 09, 2013
- Like
- 0
Update Multiple Child records from a Parent Record
I am trying to update a field on a child record - Participation_Level_Tiers__c.Total_Regist__c from a field on the Parent record Account.Total_Registrants__c
trigger UpdatePricing on Account (after insert, after update) { ////////////////////////////////////// // Created 07/18/2013 by Todd Barry /////////////////////////////////// for( Account parent: Trigger.new) { List<Participation_Level_Tiers__c> children = [ SELECT Total_Regist__c from Participation_Level_Tiers__c where Account__c = :parent.Id]; List<Account> currentacct = [Select Total_Registrants__c from Account Where account.id = :parent.Id]; List<Participation_Level_Tiers__c> childrenToUpdate = new List<Participation_Level_Tiers__c>(); For (Participation_Level_Tiers__c thischild: children ) { thischild.Total_Regist__c = currentacct[0].Total_Registrants__c; childrentoupdate.add(thischild); } IF(childrenToUpdate != null) { update childrentoupdate; } }}
The trigger saves fine, but when I update the Account record nothing happens?
Any thoughts?
Also, how would I use a debug statement and where would i put it to see the Account.Total_Registrants__c value being pulled?
- tmbarry
- July 18, 2013
- Like
- 0
Trigger Doing funny things.
I created a simple trigger to increment a numeric value on an object if a certain task is created.
trigger UpdateSentMail_01 on Task (after insert){ // Tasks that meet criteria, and new tasks to create Task[] qualifiedTasks = new Task[0], newTasks = new Task[0]; // Map of SD Members Map<Id,SD_Member__c> members = new Map<Id,SD_Member__c>(); // Find qualifying tasks for(Task record:Trigger.new) if(Record.subject!=null && record.subject.contains('Print Sf Order Submitted') && record.status == 'Completed') qualifiedtasks.add(record); // Obtain member ID values for(Task record:qualifiedtasks) members.put(record.whatid,null); // If there are any membes to query, do so. if(!members.isempty()) members.putall([select id, letter_counter__c from SD_Member__c where id in :members.keyset()]); double i = 0; for(Task record:qualifiedtasks) { // Get the current Letter Counter value i = members.get(record.whatid).letter_counter__c; // Increase the Letter Counter by 1 i=i+1; members.get(record.whatid).Send_Monthly_Letter__c=False; } update members.values(); for(Task record:qualifiedtasks) { members.get(record.whatid).Send_Monthly_Letter__c=True; members.get(record.whatid).Make_1st_Follow_Up_Call__c=False; members.get(record.whatid).Make_2nd_Follow_Up_Call__c=False; members.get(record.whatid).Make_3rd_Follow_Up_Call__c=False; members.get(record.whatid).Letter_Counter__c=i; } update members.values(); }
Before I entered the test tasks using excel connector here is what my test data looked like:
Record ID | First Name | Last Name | Letter Counter |
a02W000000A8SgfIAF | Test | Record_0115 | 17 |
a02W000000A8SggIAF | Test | Record_0155 | 1 |
a02W000000A8SghIAF | Test | Record_0135 | 8 |
a02W000000A8SgiIAF | Test | Record_0175 | 21 |
a02W000000A8SgjIAF | Test | Record_0195 | 14 |
a02W000000A8SglIAF | Test | Record_0116 | 16 |
a02W000000A8SgmIAF | Test | Record_0156 | 0 |
a02W000000A8SgnIAF | Test | Record_0136 | 9 |
a02W000000A8SgoIAF | Test | Record_0176 | 22 |
a02W000000A8SgpIAF | Test | Record_0196 | 15 |
a02W000000A8SgqIAF | Test | Record_0117 | 17 |
a02W000000A8SgrIAF | Test | Record_0157 | 0 |
a02W000000A8SgsIAF | Test | Record_0137 | 10 |
a02W000000A8SgtIAF | Test | Record_0177 | 23 |
a02W000000A8SguIAF | Test | Record_0197 | 16 |
a02W000000A8Sh0IAF | Test | Record_0118 | 18 |
a02W000000A8Sh1IAF | Test | Record_0158 | 0 |
a02W000000A8Sh2IAF | Test | Record_0138 | 11 |
a02W000000A8Sh3IAF | Test | Record_0178 | 24 |
a02W000000A8Sh4IAF | Test | Record_0198 | 17 |
a02W000000A8ShAIAV | Test | Record_0119 | 19 |
a02W000000A8ShBIAV | Test | Record_0159 | 0 |
a02W000000A8ShEIAV | Test | Record_0199 | 18 |
a02W000000A8ShCIAV | Test | Record_0139 | 12 |
a02W000000A8ShDIAV | Test | Record_0179 | 25 |
Now, after entering in my test tasks, each record should have increment by 1. Instead I got this:
Record ID | First Name | Last Name | Letter Counter |
a02W000000A8SgfIAF | Test | Record_0115 | 13 |
a02W000000A8SggIAF | Test | Record_0155 | 13 |
a02W000000A8SghIAF | Test | Record_0135 | 13 |
a02W000000A8SgiIAF | Test | Record_0175 | 13 |
a02W000000A8SgjIAF | Test | Record_0195 | 13 |
a02W000000A8SglIAF | Test | Record_0116 | 13 |
a02W000000A8SgmIAF | Test | Record_0156 | 13 |
a02W000000A8SgnIAF | Test | Record_0136 | 13 |
a02W000000A8SgoIAF | Test | Record_0176 | 13 |
a02W000000A8SgpIAF | Test | Record_0196 | 13 |
a02W000000A8SgqIAF | Test | Record_0117 | 13 |
a02W000000A8SgrIAF | Test | Record_0157 | 13 |
a02W000000A8SgsIAF | Test | Record_0137 | 13 |
a02W000000A8SgtIAF | Test | Record_0177 | 13 |
a02W000000A8SguIAF | Test | Record_0197 | 13 |
a02W000000A8Sh0IAF | Test | Record_0118 | 13 |
a02W000000A8Sh1IAF | Test | Record_0158 | 13 |
a02W000000A8Sh2IAF | Test | Record_0138 | 13 |
a02W000000A8Sh3IAF | Test | Record_0178 | 13 |
a02W000000A8Sh4IAF | Test | Record_0198 | 13 |
a02W000000A8ShAIAV | Test | Record_0119 | 13 |
a02W000000A8ShBIAV | Test | Record_0159 | 13 |
a02W000000A8ShEIAV | Test | Record_0199 | 13 |
a02W000000A8ShCIAV | Test | Record_0139 | 13 |
a02W000000A8ShDIAV | Test | Record_0179 | 13 |
Since I didn't want to include all 700 test records, another block of records had their Letter_counter__c field set to all 3s and another group all 11.
Any ideas what is happening?
- tmbarry
- July 16, 2013
- Like
- 0
Getting Weird results from my Trigger
I created a simple trigger that whenever we create a "mailing" task, after the task is marked "completed" it updates the letter counter on a custom object.
trigger UpdateSentMail_02 on Task (after Insert, after update){ double i = 0; // Tasks that meet criteria, and new tasks to create Task[] qualifiedTasks = new Task[0], newTasks = new Task[0]; // Map of SD Members Map<Id,SD_Member__c> members = new Map<Id,SD_Member__c>(); // Find qualifying tasks for(Task record:Trigger.new) if(Record.subject!=null && record.subject.contains('Print Sf Order Submitted') && record.status == 'Completed') qualifiedtasks.add(record); // Obtain member ID values for(Task record:qualifiedtasks) members.put(record.whatid,null); // If there are any membes to query, do so. if(!members.isempty()) members.putall([select id, letter_counter__c from SD_Member__c where id in :members.keyset()]); for(Task record:qualifiedtasks) { // Get the current Letter Counter value i = members.get(record.whatid).letter_counter__c; // Increase the Letter Counter by 1 i=i+1; members.get(record.whatid).Send_Monthly_Letter__c=False; } update members.values(); for(Task record:qualifiedtasks) { members.get(record.whatid).Letter_Counter__c=i; } update members.values(); }
When I run it one record at a time, that is, I go into SF and create each task by hand it runs fine. But if I try and upload 500 to 1000 tasks using Excel connector or Data loader, nothing happens.
Any ideas?
- tmbarry
- July 09, 2013
- Like
- 0
Update an Account Record Field from a Child record, Based on an Account Update
I am trying update a field on a on an account record from a value on a child record. Normally I would use a Roll Up summary field, but my Child record criteria field is a formula field and I cannot use a formula field as a roll up summary criteria.
My scenario is this. On the account field I have a field : "number of lives", a simple numeric field. The then have a child object that have pricing values depending on the # of lives from the parent account. Each Child record has a Min # of Lives Field and a Max # of Lives Field and if the Account.number of lives falls between the two, a formula field on the Pricing record returns a value of true.
Whichever record has the true value, I want to return the Pricing__c.Total__c to the Account.Total_Price__c field. Since the Number of lives updates on the Account record, I built the trigger on the account record:
trigger UpdatePricing on Account (before update) { For (Account acct:Trigger.new){ String AcctId = acct.id; List<Account> AccountToUpdate = new List<Account>(); For(Pricing__c pri: [Select id, Total__c from Pricing__c where Account__c =: acctid and Active__c = 'True' ]){ //AccountToUpdate.Total_Price__c = pri.total__c; Update AccountToUpdate; } } }
But I can not for the life of me figure out how to make this work. This is one of the error messages I am getting:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UpdatePricing caused an unexpected exception, contact your administrator: UpdatePricing: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 001i000000Crwx6AAB; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 001i000000Crwx6) is currently in trigger UpdatePricing, therefore it cannot recursively update itself: []: Trigger.UpdatePricing: line 10, column 1
Any help would be greatly appreciate.
- tmbarry
- June 20, 2013
- Like
- 0
Access a field on a Child record
Hello All,
I am trying to write a trigger to update the fields on an object based on the completion of a task.
trigger UpdateSentMail_02 on Task (after Insert, after update){ Integer i = 0; // Tasks that meet criteria, and new tasks to create Task[] qualifiedTasks = new Task[0], newTasks = new Task[0]; // Map of SD Members Map<Id,SD_Member__c> members = new Map<Id,SD_Member__c>(); // Find qualifying tasks for(Task record:Trigger.new) if(Record.subject!=null && record.subject.contains('Print Sf Order Submitted') && record.status == 'Completed') qualifiedtasks.add(record); // Obtain member ID values for(Task record:qualifiedtasks) members.put(record.whatid,null); // If there are any membes to query, do so. if(!members.isempty()) members.putall([select id from SD_Member__c where id in :members.keyset()]); for(Task record:qualifiedtasks) { members.get(record.whatid).Send_Monthly_Letter__c=False; } update members.values(); // Get the current Letter Counter value i == (members.get(record.whatid).letter_counter__c); // Increase the Letter Counter by 1 i=i+1; for(Task record:qualifiedtasks) { members.get(record.whatid).Send_Monthly_Letter__c=True; members.get(record.whatid).Make_1st_Follow_Up_Call__c=False; members.get(record.whatid).Make_2nd_Follow_Up_Call__c=False; members.get(record.whatid).Make_3rd_Follow_Up_Call__c=False; members.get(record.whatid).Letter_Counter__c=i; } update members.values(); }
I issue I am havin is with this line:
// Get the current Letter Counter value i == (members.get(record.whatid).letter_counter__c); // Increase the Letter Counter by 1 i=i+1;
I need to get the orginal SD_Member__c.Letter_Counter__c value so I can increase it by one. I was hoping it was as simple as my code above, but I am getting the following error message:
|
Any ideas how I can get the Letter_counter__c value?
- tmbarry
- June 18, 2013
- Like
- 0
Interesting Error Meeasge
I wrote the following trigger to update a set of fields.
trigger Decide_Which_Address_to_Use on SD_Member__c (before update) { For (SD_Member__c SD : Trigger.new){ // Determine if there is a bad address and which one it is. If(sd.address_bad__c==True){ If(SD.Mailing_Address__c.touppercase()==SD.Address__c.touppercase() && SD.Mailing_City__c.touppercase()==SD.City__c.touppercase()&&SD.Mailing_Zip__c==SD.Zip__c){ sd.Bad_HP_Address__c = SD.Mailing_Address__c; sd.bad_HP_City__c = sd.Mailing_city__c; sd.bad_HP_State__c = sd.mailing_state__c; sd.Bad_HP_Zip__c = SD.Mailing_Zip__c; sd.address_bad__c=False;} If(SD.Mailing_Address__c.touppercase()==SD.Pref_Address__c.touppercase() && SD.Mailing_City__c.touppercase()==SD.Pref_city__c.touppercase()&&SD.Mailing_Zip__c==SD.Pref_Zip__c){ sd.Bad_Pref_Adrs_Address__c = SD.Mailing_Address__c; sd.Bad_Pref_Adrs_City__c = sd.Mailing_city__c; sd.Bad_Pref_Adrs_State__c = sd.mailing_state__c; sd.Bad_Pref_Adrs_Zip__c = SD.Mailing_Zip__c; sd.address_bad__c=False;} If(SD.Mailing_Address__c.touppercase()==SD.NCOA_Address__c.touppercase() && SD.Mailing_City__c.touppercase()==SD.NCOA_city__c.touppercase()&&SD.Mailing_Zip__c==SD.NCOA_Zip__c){ sd.Bad_NCOA_Address__c = SD.Mailing_Address__c; sd.Bad_NCOA_City__c = sd.Mailing_city__c; sd.Bad_NCOA_State__c = sd.mailing_state__c; sd.Bad_NCOA_Zip__c = SD.Mailing_Zip__c; sd.address_bad__c=False; }} } }
And it worked fine in my sandbox.
When I moved it to production, I get the following error.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger Update_NCOA_Address_v01 caused an unexpected exception, contact your administrator: Update_NCOA_Address_v01: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a025000000HuNUiAAN; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Decide_Which_Address_to_Use: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.Decide_Which_Address_to_Use: line 12, column 1: []: Trigger.Update_NCOA_Address_v01: line 41, column 1
So I went back in to my sandbox and change the trigger to (after Update), then I got the error in my sandbox account.
So why does Before Update, give me an error in Production and not Sandbox?
- tmbarry
- June 11, 2013
- Like
- 0
Comparing the values of two field in upper case
I need to compare the values of two text fields, one is always upper case, one is not. How do I use the Upper() function in a trigger?
trigger Decide_Which_Address_to_Use on SD_Member__c (before update) { For (SD_Member__c SD : Trigger.new){ // Determine if there is a bad address and which one it is. If(sd.address_bad__c==True){ If(SD.Mailing_Address__c==SD.Address__c){
// I tried this, but it didn't work // If(Upper(SD.Mailing_Address__c)==Upper(SD.Address__c)
- tmbarry
- June 11, 2013
- Like
- 0
Developer script exception
Hello All,
I am getting a Developer script exception error on one of my triggers. The error states:
Apex script unhandled trigger exception by user/organization: XXXXXXXXXXXXXX/xxxxxxxxxxxxxx
Update_NCOA_Address_v01: System.LimitException: Too many DML statements: 151
trigger Update_NCOA_Address_v01 on printsf__Collateral_Send_History__c (after insert, after update) { // Update the appropriate SD_Member__c record with NCOA address from PrintSF For(printsf__Collateral_Send_History__c CSH : Trigger.new){ // Get the SD Member Id from the recipient id field //String strSDId = CSH.printsf__Recipient_ID__c; If(CSH.printsf__NCOA_Result__c=='None'){ SD_Member__c SD = New SD_Member__c (id=CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c, NCOA_Error_Code__c = CSH.printsf__NCOA_Result__c, NCOA_Error_Description__c = CSH.printsf__NCOA_Result_Description__c); Update SD;} If(CSH.printsf__NCOA_Result__c=='Fowarded'){ SD_Member__c SD = New SD_Member__c (id=CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c); Update SD;} If(CSH.printsf__NCOA_Result__c=='Failed'){ SD_Member__c SD = New SD_Member__c (id=CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c, Address_Bad__c = True); Update SD;} }}
What happens is, I send a between 3,000 and 5,000 records to a third party print vendor and they return their validity check results, the "none", "fowarded" or "failed" to their printsf_collateral_send_history__c object. As each record returns, the trigger updates fields on my custom object SD_Member__c.
I thought I had "bulkified" the trigger, but maybe not.
Thanks for the help,
Todd B.
- tmbarry
- June 07, 2013
- Like
- 0
Create a time delayed Task from a trigger.
Is it possible to have a trigger create a task with a due date 7 days out and the task not show up until the Due Date, similar to a time based work flow? In this instance time based work flow will not work for what I need. I am able to create the task and set the Due Date to seven days out, but I can not keep it from showing up until the actual due date.
Thoughts?
- tmbarry
- May 21, 2013
- Like
- 0
System.NullPointerException: Attempt to de-reference a null object - Not sure Why this Happening.
I wrote a trigger to create a task when a certain field is updated. The trigger works fine and as expected. However, everytime I run the test class I get the following error:
System.DmlException: Update failed. First exception on row 0 with id a0NW0000000ddmlMAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Create_Make_1st_Call: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.Create_Make_1st_Call: line 43, column 1: [] Class.TestClass_SD_Member_Mailing_History.myUnitTest: line 39, column 1
Here is my Test Class:
@isTest class TestClass_SD_Member_Mailing_History { static testMethod void myUnitTest() { // TO DO: implement unit test // Create SD Member Record SD_Member__c sd = New SD_Member__c(First_Name__c = 'John', Last_Name__c = 'Smith', Ins_ID_Member__c = '123456', Ins_ID_Suscriber__c = '456789', address__c = '123 Main Stret', city__c = 'Aster', state__c = 'CT', zip__c = '06001', name = 'John Smith', Lost_Contact_Follow_Up__c = False, Mailing_Cycle__c='Week 2.1'); insert sd; // Create Mailing Order printsf__Collateral_Order_History__c PO = new printsf__Collateral_Order_History__c(Name='Dummy Order 02', printsf__Order_Number__c=2); Insert po; // Create SD Mailing History Item printsf__Collateral_Send_History__c MH = new printsf__Collateral_Send_History__c(Name='Test Mailer Entry XYZ', printsf__Recipient_ID__c = sd.id, printsf__Send_History_ID__c = 123654, printsf__Order__c = po.id); Insert MH; //Test Order Execute logic for send "make first Call" task SD_Member_Mailing_History__c SDMH = New SD_Member_Mailing_History__c(Mailer_History_Item__c =MH.id , SD_Member_Stakeholders__c = sd.id); Insert SDMH; SDMH.Order_Executed__c = True; system.debug(sd.id); Update SDMH; }}
Here is my trigger.
trigger Create_Make_1st_Call on SD_Member_Mailing_History__c (After Update) { //This is the real one!!!!!! // Variables Date CallDate1 = DateTime.now().addDays(-10000).date(); // Create my own Right Text Function public String right(String s, Integer i) { if (s == null || s == '' || i <=0 ) { return ''; } else if (i >= s.length()) { return s; } else { return s.subString(s.length() - i, s.length()); } } //----------------------------------------------------------------------- // Find Entries that meet criteria and new Entries to create SD_Member_Mailing_History__c [] qualifiedEntry = new SD_Member_Mailing_History__c[0]; Task [] newTask = new Task[0]; // Map of SD Member Ids Map<Id,SD_Member__c> members = new Map<Id,SD_Member__c>(); // Find qualifing Entries For (SD_Member_Mailing_History__c record:trigger.new) If(record.Order_executed__c ==True) qualifiedEntry.add(record); //Obtain SD Member Ids For(SD_Member_Mailing_History__c record:qualifiedEntry) members.put(record.SD_Member_Id__c,null); // If there are any members to query, do so. If(!members.isempty()) members.putall([Select id, Mailing_Cycle__c, Ownerid from SD_Member__c where id in :members.keyset()]); // For each qualifing record, create a task. For(SD_Member_Mailing_History__c record:qualifiedEntry){ // Check to see what mailing cycle the SD Member is in to determine when to make the follow up call If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='1') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+3,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='2') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+4,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='3') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+5,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='4') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+6,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='5') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+7,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='6') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+8,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='7') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+9,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='8') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+10,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='9') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+11,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); //Old Activity Date Logic //ActivityDate=DateTime.now().addDays(11).date() } } // Insert new task records into database. insert newtask; }
Everything was working fine until I changed one line of code in my trigger.
I change the if statements from
newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=DateTime.now().addDays(11).date(),Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid));
To
newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+11,Status='Not Started'
Any Ideas
- tmbarry
- May 21, 2013
- Like
- 0
I'm getting Confused, Querying too many objects.
Here is my delema,
I am working with a third part print vendor to do mailings. They have created two objects:
- printsf__Collateral_Order_History__c - For every order I place they create one entry in this table.
- printsf__Collateral_Send_History__c - this table is a child of the previous table and for every order I place they create one entry per person that receives the mailing, roughly 500 per week.
- I have a thrid table SD_Member__c - this contains all the information regarding the people being mailed too
- Finally, I have a fourth table - SD_Member_Mailing_History__c that links the printsf__Collateral_Send_History__c and the SD_Member__c. This way I can click on a SD_Member__C record and see all the mailing he/she has been a part of.
OK see here's what happens. I send an order to the printer and he creates an the vendor creates an entry in the printsf__Collateral_Order_History__c. He verifies each entry and once verified, he creates an entry in the printsf__Collateral_Send_History__c. After a day or two he mails all my letters and updates a field on the printsf__Collateral_Order_History__c table printsf__Date_Completed__c with the mailing date. Once that date is updated, I need to create a follow task for each SD_Member__s for the record owner to make a follow up call. There is a Date_Mailed__c field on the printsf__Collateral_Send_History__c table, but it's a fomula field looking back at the printsf__Collateral_Order_History__c.printsf__Date_Completed__c field.
So my delema, when the vendor updates the printsf__Collateral_Order_History__c table printsf__Date_Completed__c I need to query all the related printsf__Collateral_Send_History__c, then query the SD_Member_Mailing_History__c table to determine all the SD_Member__C ids so I can create a new task for each SD_Member__C record.
My code so far is as follows:
trigger Not_Sure_If_This_Will_Work on printsf__Collateral_Order_History__c (after update) { // Set Variables printsf__Collateral_Order_History__c [] MailingOrder = new printsf__Collateral_Order_History__c[0]; //printsf__Collateral_Send_History__c [] MailingHistory = new printsf__Collateral_Send_History__c[0]; Task [] newTask = new Task[0]; // Map of SD Member Ids Map<Id,SD_Member__c> members = new Map<Id,SD_Member__c>(); // Map All History Itemss Map<id,printsf__Collateral_Send_History__c> HistoryEntry = New Map<id,printsf__Collateral_Send_History__c>(); // Identify Correct Mail Order For (printsf__Collateral_Order_History__c record:trigger.new) If(record.printsf__Date_Completed__c<>null) MailingOrder.add(record); //Obtain all the Correct Mail History Items For (printsf__Collateral_Order_History__c record:MailingOrder) HistoryEntry.put(record.id,null); //If there are any History Items to query, query them. If(!HistoryEntry.isempty()) HistoryEntry.putall([select id, printsf__Recipient_ID__c from printsf__Collateral_Send_History__c where printsf__Order__c in :HistoryEntry.keyset()]); string strid = HistoryEntry.get(record.id).printsf__Recipient_ID__c; // For each History Item, Create a task For(printsf__Collateral_Order_History__c record:MailingOrder){ newtask.add(new task(Subject='This Worked!!!')); Insert newtask; } }
I monkeyed this together to see if could figure it out, but right now it only creates one task. I'm guessing that's based on the one printsf__Collateral_Order_History__c and not all the related printsf__Collateral_Send_History__c entries.
ANY HELP WOULD BE APPRECIATED as I already spent a week on this.
- tmbarry
- May 16, 2013
- Like
- 0
How to Bulkify a Trigger
I recently wrote a trigger that when a Task with a certain subject is closed, create a new follow up task. Everything was working fine until one of my users bulk loaded a few hundred records and I received an error message. Now I need to bulkify this trigger and have no idea how.
trigger Send_Qtrly_Update_02_v02 on Task (after insert, after update) { for (Task t : Trigger.new){ // Today's Date plus 90 days for scheduling next call DateTime dT = System.now()+90; Date myDate = date.newinstance(dT.year(), dT.month(), dT.day()); // Today's Date for updating the Last_Outreach_Call_Made__c field on the Provider_Facility__c record. DateTime dT1 = System.now(); Date TodayDate = date.newinstance(dT1.year(), dT1.month(), dT1.day()); // Step 1 - Get the Outreach_Agent__c id to assign the task too. This logic is used incase the Outreach value on the Provider // Facilty changes in the future. For (Provider_Facility__c prov: [ Select id, Outreach_Agent__c from Provider_Facility__c Where id =: t.whatid]){ // Now Check to see if the Task meets the right citeria if (t.Subject == 'Quarterly Outreach Call' && t.IsClosed==True) { // Insert a recurring task Task t1 = new task(Whatid=t.whatid, Subject='Quarterly Outreach Call', ActivityDate=myDate, Ownerid=prov.Outreach_Agent__c ); insert t1; // Update the Last_Outreach_Call_Made__c field on the Provider_Facility__c record Provider_Facility__c prov01 = New Provider_Facility__c(id=t.WhatId, Last_Outreach_Call_Made__c=TodayDate); Update prov01; }} } }
Can someone point me in the right direction on how to do this?
Any help would be much appreciated. It seems like everytime I learn how to do something, I need to re-learn it to better fit the Apex framework.
- tmbarry
- April 18, 2013
- Like
- 0
Workflow no longer working...
I created a workflow about a year ago to fire off a task when a condition is met. It has been working flawlessly for a year. But two weeks ago, it starting acting up. Normally we update 300 to 400 records on a Monday or Tuesday using Excel Connector or Data Loaders (both have always worked fine for us) and then the workflow fires off. But two weeks , it only fired off the workflow for roughly 50 items and then I received 350 of these error messages:
Subject: Salesforce.com workflow could not perform a pending action
Details:
Object Type: SD Member & Stakeholders
Record: XXXXXXXXXXXX
https://na3.salesforce.com/XXXXXXXXXX
Workflow Rules attempted: Make 1st Follow Up Call v1 https://na3.salesforce.com/XXXXXXXXXX
Workflow Actions attempted: Make 1st Follow Up Call https://na3.salesforce.com/XXXXXXXXXX
Error Number: 1904646325-6064 (-1072421861)
Date: 11 Apr 2013 18:48:50 GMT
Here is a snaphot of the workflow:
Any idea why a workflow would just stop working? I have not made any changes to my production evniroment.
I logged the issue with Salesforce support, but so far they have just bumped me up to tier 2 support, but still no answer.
Thanks for any help you can provide.
- tmbarry
- April 17, 2013
- Like
- 0
Change the Posting User of a Chatter Item
The problem is, that the chatter post comes from the person who won the opportunity, so it looks like they are patting themselves on the back. I created a user called Sales Operations. How do I make all these automated posts come from this Sales Operations user?
<pre>
trigger CreateChatterEntry on Opportunity (before Update) {
For(opportunity opp : Trigger.new){
// Check to see if the Oppty was previously Marked Closed Won
Opportunity beforeUpdate = System.Trigger.oldMap.get(opp.Id);
if(beforeUpdate.IsWon != opp.IsWon){
String ownerIds = opp.Oppty_Owner_Name__c;
String oppName = opp.name;
Set<ID> ownerId = new Set<ID>();
ownerId.add(opp.ownerId);
Map<ID,User> userMap = new Map<ID,User>([SELECT ID, Name, FirstName FROM User WHERE ID In : ownerid]); //This is our user map
User uName = userMap.get(opp.ownerId);
// Get a list of All the Current Chatter Group Names
List<CollaborationGroup> Grps = [Select Name, Id FROM CollaborationGroup];
Map<string, String> GrpName = new Map<string, string>{};
for(CollaborationGroup gn: Grps)
Grpname.put(gn.name,gn.id);
// If the Oppty is marked Closed Won, Create Chatter entry.
If(opp.iswon ==true){
FeedItem fitem = new FeedItem ();
fitem.type = 'LinkPost';
fitem.ParentId = grpName.get('Salesforce.com Users'); //Select What Chatter group to post message in.
fitem.LinkUrl = '/' + opp.id; //This is the url to take the user to the activity
fitem.Title = oppName + ' Opportunity'; //This is the title that displays for the LinkUrl
//fitem.Body = ('Congratulations to ' + uName.name + ' on winning ' + oppname + '! Nice Job '+ uName.firstname+'.');
fitem.Body = ('Congratulations to ' + uName.name + ' on winning ' + oppname + '!');
Insert fitem;
} }
}}
</pre>
- tmbarry
- April 07, 2014
- Like
- 1
Determine what Qtr something was created?
For example: if I run a report today (11/9/15 - Qtr4) the report needs to show eveything created since Aug. I was thinkning about creating a custome formula field on the Opportunity record with an output of a checkbox with a simple True/False result, but i can not come up with the logic.
Any thoughts?
- tmbarry
- November 09, 2015
- Like
- 0
Error: Compile Error: Method does not exist or incorrect signature: TriggerHandlerTask()
My Class is:
public class TriggerHandlerTask { public TriggerHandlerTask(){} public void UpdateTaskType(Task[] newTasks){ for (Task t1 : NewTasks){ /* Developer : Todd Barry Created : Last Modified : 05/18/2015 Test Class : Objective : When a PSS or COS BCC's to salesforce, this will ensure the correct Activity Type is set */ // Only update the task type if a type value has not already been selected If (t1.type==null){ if(t1.subject.contains('email') || t1.subject.contains('Email')){ t1.type='Email';} if(t1.subject.contains('meet') || t1.subject.contains('Meet')){ t1.type='Meeting'; } else if(t1.subject.contains('visit')|| t1.subject.contains('Visit')) t1.type='Office Visit'; if(t1.subject.contains('call') || t1.subject.contains('Call')) t1.type='Phone Call'; else if(t1.subject!= null) t1.type='Other'; } // This update is for emails BCC to salesforce. if(t1.subject.contains('email:') || t1.subject.contains('Email:')){ t1.Activity_type_01__c='Email';} } }}
And my Trigger is:
trigger UpdateTaskType on Task (before insert, before Update) { If(Trigger.isBefore){ if(Trigger.isInsert){ TriggerHandlerTask Handler = TriggerHandlerTask(); Handler.UpdateTaskType(Trigger.new); } If(Trigger.isUpdate){ } } Else If(Trigger.isAfter){ if(Trigger.isInsert){ } If(Trigger.isUpdate){ } } }But i keep getting this error: Error: Compile Error: Method does not exist or incorrect signature: TriggerHandlerTask() at line 6 column 38
What am I missing?
- tmbarry
- May 18, 2015
- Like
- 0
Need to pull an existing User Record
I am trying to create a test class for a new trigger and it involves a lookup to a user record. In my test class, do i have to create a new user entry, or is there a way to to reference any existing users in the org for the test?
- tmbarry
- August 30, 2013
- Like
- 0
Error: Compile Error: Illegal assignment from Schema.SObjectField to String at line 7 column 1
Can someone help with this error message?
trigger SD_Member_Check_Member_Status on SD_Member__c (after insert, after update) { // If Master Status = Ineligible // And Post Referral to CC Status = (In Treatment OR No Contact 30 Days OR No Contact 60 Days) For (SD_Member__c SD : Trigger.new){ String MS1 = SD_Member__c.Master_status__c; If(MS1 == 'Ineligible'){ } } }
The Issue is this line:
String MS1 = SD_Member__c.Master_status__c;
The Master_Status__c field is a Formula (Text) field and the formula is:
If(
TEXT( Post_Referral_to_CC_Status__c ) = "Graduated","Graduated",
If(
TEXT( Member_Eligibility_Status__c ) = "Ineligible-Cov", "Ineligible",
If(
AND (TEXT( Member_Eligibility_Status__c ) = "Ineligible-Geo",TEXT (Record_Invalid__c) <> "Override: Eligible Plan/Geo"), "Ineligible",
If(
AND (TEXT( Member_Eligibility_Status__c ) = "Ineligible-Plan",TEXT (Record_Invalid__c) <> "Override: Eligible Plan/Geo"), "Ineligible",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "In Treatment - Active","In Treatment",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "In Treatment - No Contact 30 Days","In Treatment",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "In Treatment - No Contact 60 Days","In Treatment",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "In Treatment","In Treatment",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "No Contact 30 Days","In Treatment",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "No Contact 60 Days","In Treatment",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "Ineligible - Medically Excluded","Ineligible",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "Deceased","Ineligible",
If(
TEXT( Post_Referral_to_CC_Status__c ) = "Requires Higher Level of Care","Ineligible",
If(
TEXT( Member_Eligibility_Status__c )="Ineligible-LUSD","Ineligible",
If(
TEXT( Member_Eligibility_Status__c )="Ineligible-NonSD","Ineligible",
If(
TEXT( Catasys_Medical_Exclusion_Status__c )<>"Medically Targeted","Ineligible",
if(
AND (Len(TEXT( Record_Invalid__c ))>0,TEXT (Record_Invalid__c) <> "Override: Eligible Plan/Geo" ), "Ineligible",
"Outreach Candidate"
)))))))))))))))))
- tmbarry
- August 29, 2013
- Like
- 0
Error Error: Compile Error: Variable does not exist:
I have a trigger that works fine. This trigger pulls weekly updates from a child object and updates fields on the Opportunity record. There are three items on the Weekly Update object: Status Update, Risks, & Next Steps.
trigger UpdateOpportunityStatusFromWeeklyUpdate on Weekly_Update__c (after insert, after Update) { for (Weekly_Update__c WU : Trigger.new) { Date dt=wu.date__c; String strOppId = wu.Opportunity_Name__c; List<RecordType> rtypes = [Select Name, Id From RecordType where sObjectType='Opportunity' and isActive=true]; //Create a map between the Record Type Name and Id for easy retrieval Map<String,String> opptyRecordTypes = new Map<String,String>{}; for(RecordType rt: rtypes) opptyRecordTypes.put(rt.Name,rt.Id); for (Opportunity opp : [SELECT id, name, RecordTypeId FROM Opportunity WHERE id =: strOppId]){ If(opp.RecordTypeId ==opptyRecordTypes.get('MMA') || opp.RecordTypeId ==opptyRecordTypes.get('MMA - Market Monitoring')) { String strA = dT.month() + '/' + dt.day() + '/' + dt.year()+' - ' + wu.rptOwnerName__c + ': '+ wu.Status_Update__c ; String strB = dT.month() + '/' + dt.day() + '/' + dt.year()+' - ' + wu.rptOwnerName__c + ': '+ wu.Risks__c ; String strC = dT.month() + '/' + dt.day() + '/' + dt.year()+' - ' + wu.rptOwnerName__c + ': '+ wu.Next_Steps__c ; Opportunity O = new Opportunity(Id=wu.Opportunity_Name__c, Opportunity_Update__c=stra, Opportunity_Next_Steps_v2__c = strc, Opportunity_Risks__c=strb, rptStatusUpateDate__c=dt); update O;} Else { String strA = dT.month() + '/' + dt.day() + '/' + dt.year()+ ' - '+ wu.Status_Update__c ; String strB = dT.month() + '/' + dt.day() + '/' + dt.year()+ ' - '+ wu.Risks__c ; String strC = dT.month() + '/' + dt.day() + '/' + dt.year()+ ' - '+ Next1 ; Opportunity O = new Opportunity(Id=wu.Opportunity_Name__c, Opportunity_Update__c=stra, Opportunity_Next_Steps_v2__c = strc, Opportunity_Risks__c=strb, rptStatusUpateDate__c=dt); update O;} }} }
The only draw back to this code is, if one of the three fields (Status Update, Risks, & Next Steps) is Null it updates the Opportunty reocrd with the word 'Null'
Opportunity Next Steps |
|
So I wrote an if statement to check to see if the value was null and replace the value with 'No Report'
trigger UpdateOpportunityStatusFromWeeklyUpdate on Weekly_Update__c (after insert, after Update) { for (Weekly_Update__c WU : Trigger.new) { Date dt=wu.date__c; String strOppId = wu.Opportunity_Name__c; List<RecordType> rtypes = [Select Name, Id From RecordType where sObjectType='Opportunity' and isActive=true]; //Create a map between the Record Type Name and Id for easy retrieval Map<String,String> opptyRecordTypes = new Map<String,String>{}; for(RecordType rt: rtypes) opptyRecordTypes.put(rt.Name,rt.Id); /* ****Here is my New Code*** */ If(wu.Status_Update__c == ''){ String Update1 = 'No Report';} Else { String Update1 = wu.Status_Update__c;} If(wu.Risks__c == ''){ String Risk1 = 'No Report';} Else { String Risk1 = wu.Risks__c;} If(wu.Next_Steps__c == ''){ String Next1 = 'No Report';} Else { String Next1 = wu.Next_Steps__c;} for (Opportunity opp : [SELECT id, name, RecordTypeId FROM Opportunity WHERE id =: strOppId]){ If(opp.RecordTypeId ==opptyRecordTypes.get('MMA') || opp.RecordTypeId ==opptyRecordTypes.get('MMA - Market Monitoring')) { String strA = dT.month() + '/' + dt.day() + '/' + dt.year()+' - ' + wu.rptOwnerName__c + ': '+ wu.Status_Update__c ; String strB = dT.month() + '/' + dt.day() + '/' + dt.year()+' - ' + wu.rptOwnerName__c + ': '+ wu.Risks__c ; String strC = dT.month() + '/' + dt.day() + '/' + dt.year()+' - ' + wu.rptOwnerName__c + ': '+ wu.Next_Steps__c ; Opportunity O = new Opportunity(Id=wu.Opportunity_Name__c, Opportunity_Update__c=stra, Opportunity_Next_Steps_v2__c = strc, Opportunity_Risks__c=strb, rptStatusUpateDate__c=dt); update O;} Else { String strA = dT.month() + '/' + dt.day() + '/' + dt.year()+ ' - '+ Update1 ; String strB = dT.month() + '/' + dt.day() + '/' + dt.year()+ ' - '+ Risk1 ; String strC = dT.month() + '/' + dt.day() + '/' + dt.year()+ ' - '+ Next1 ; Opportunity O = new Opportunity(Id=wu.Opportunity_Name__c, Opportunity_Update__c=stra, Opportunity_Next_Steps_v2__c = strc, Opportunity_Risks__c=strb, rptStatusUpateDate__c=dt); update O;} }} }
But I am getting an error message stating: Error: Compile Error: Variable does not exist: Update1 at line 41 column 77
Which is this line:
String strA = dT.month() + '/' + dt.day() + '/' + dt.year()+ ' - '+ Update1 ;
I am sure my error is because I put my new If statements in the wrong spot:
/* ****Here is my New Code*** */ If(wu.Status_Update__c == ''){ String Update1 = 'No Report';} Else { String Update1 = wu.Status_Update__c;} If(wu.Risks__c == ''){ String Risk1 = 'No Report';} Else { String Risk1 = wu.Risks__c;} If(wu.Next_Steps__c == ''){ String Next1 = 'No Report';} Else { String Next1 = wu.Next_Steps__c;}
Any thoughts on how to fix this. The multiple IF statements are screwing me up!
- tmbarry
- August 22, 2013
- Like
- 0
Too many DML rows: 10001
I know I am missing something simple here, but I getting a:
Apex script unhandled trigger exception by user/organization: 0055000000118E4/00D50000000784t
Update_NCOA_Address_v01: System.LimitException: Too many DML rows: 10001
Error Message.
1. Can someone spot my error?
2. Is there a way to put into the code or error message which record(s) triggered the error?
trigger Update_NCOA_Address_v01 on printsf__Collateral_Send_History__c(after insert, after update) { // Update the appropriate SD_Member__c record with NCOA address from PrintSF List<SD_Member__c > recordsToUpdate = new List<SD_Member__c >(); For(printsf__Collateral_Send_History__c CSH: Trigger.new) { // Get the SD Member Id from the recipient id field //String strSDId = CSH.printsf__Recipient_ID__c; // Check to see if it is an SD Member Entry If(CSH.printsf__Recipient_ID__c!=null){ If(CSH.printsf__NCOA_Result__c == 'None') { SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c, NCOA_Error_Code__c = CSH.printsf__NCOA_Result__c, NCOA_Error_Description__c = CSH.printsf__NCOA_Result_Description__c); recordsToUpdate.add(SD); } If(CSH.printsf__NCOA_Result__c == 'Fowarded') { SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c); recordsToUpdate.add(SD); } If(CSH.printsf__NCOA_Result__c == 'Failed') { SD_Member__c SD = New SD_Member__c(id = CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c, Address_Bad__c = True); recordsToUpdate.add(SD); } update recordsToUpdate; } }}
Thanks for the help.
- tmbarry
- August 09, 2013
- Like
- 0
Trigger Doing funny things.
I created a simple trigger to increment a numeric value on an object if a certain task is created.
trigger UpdateSentMail_01 on Task (after insert){ // Tasks that meet criteria, and new tasks to create Task[] qualifiedTasks = new Task[0], newTasks = new Task[0]; // Map of SD Members Map<Id,SD_Member__c> members = new Map<Id,SD_Member__c>(); // Find qualifying tasks for(Task record:Trigger.new) if(Record.subject!=null && record.subject.contains('Print Sf Order Submitted') && record.status == 'Completed') qualifiedtasks.add(record); // Obtain member ID values for(Task record:qualifiedtasks) members.put(record.whatid,null); // If there are any membes to query, do so. if(!members.isempty()) members.putall([select id, letter_counter__c from SD_Member__c where id in :members.keyset()]); double i = 0; for(Task record:qualifiedtasks) { // Get the current Letter Counter value i = members.get(record.whatid).letter_counter__c; // Increase the Letter Counter by 1 i=i+1; members.get(record.whatid).Send_Monthly_Letter__c=False; } update members.values(); for(Task record:qualifiedtasks) { members.get(record.whatid).Send_Monthly_Letter__c=True; members.get(record.whatid).Make_1st_Follow_Up_Call__c=False; members.get(record.whatid).Make_2nd_Follow_Up_Call__c=False; members.get(record.whatid).Make_3rd_Follow_Up_Call__c=False; members.get(record.whatid).Letter_Counter__c=i; } update members.values(); }
Before I entered the test tasks using excel connector here is what my test data looked like:
Record ID | First Name | Last Name | Letter Counter |
a02W000000A8SgfIAF | Test | Record_0115 | 17 |
a02W000000A8SggIAF | Test | Record_0155 | 1 |
a02W000000A8SghIAF | Test | Record_0135 | 8 |
a02W000000A8SgiIAF | Test | Record_0175 | 21 |
a02W000000A8SgjIAF | Test | Record_0195 | 14 |
a02W000000A8SglIAF | Test | Record_0116 | 16 |
a02W000000A8SgmIAF | Test | Record_0156 | 0 |
a02W000000A8SgnIAF | Test | Record_0136 | 9 |
a02W000000A8SgoIAF | Test | Record_0176 | 22 |
a02W000000A8SgpIAF | Test | Record_0196 | 15 |
a02W000000A8SgqIAF | Test | Record_0117 | 17 |
a02W000000A8SgrIAF | Test | Record_0157 | 0 |
a02W000000A8SgsIAF | Test | Record_0137 | 10 |
a02W000000A8SgtIAF | Test | Record_0177 | 23 |
a02W000000A8SguIAF | Test | Record_0197 | 16 |
a02W000000A8Sh0IAF | Test | Record_0118 | 18 |
a02W000000A8Sh1IAF | Test | Record_0158 | 0 |
a02W000000A8Sh2IAF | Test | Record_0138 | 11 |
a02W000000A8Sh3IAF | Test | Record_0178 | 24 |
a02W000000A8Sh4IAF | Test | Record_0198 | 17 |
a02W000000A8ShAIAV | Test | Record_0119 | 19 |
a02W000000A8ShBIAV | Test | Record_0159 | 0 |
a02W000000A8ShEIAV | Test | Record_0199 | 18 |
a02W000000A8ShCIAV | Test | Record_0139 | 12 |
a02W000000A8ShDIAV | Test | Record_0179 | 25 |
Now, after entering in my test tasks, each record should have increment by 1. Instead I got this:
Record ID | First Name | Last Name | Letter Counter |
a02W000000A8SgfIAF | Test | Record_0115 | 13 |
a02W000000A8SggIAF | Test | Record_0155 | 13 |
a02W000000A8SghIAF | Test | Record_0135 | 13 |
a02W000000A8SgiIAF | Test | Record_0175 | 13 |
a02W000000A8SgjIAF | Test | Record_0195 | 13 |
a02W000000A8SglIAF | Test | Record_0116 | 13 |
a02W000000A8SgmIAF | Test | Record_0156 | 13 |
a02W000000A8SgnIAF | Test | Record_0136 | 13 |
a02W000000A8SgoIAF | Test | Record_0176 | 13 |
a02W000000A8SgpIAF | Test | Record_0196 | 13 |
a02W000000A8SgqIAF | Test | Record_0117 | 13 |
a02W000000A8SgrIAF | Test | Record_0157 | 13 |
a02W000000A8SgsIAF | Test | Record_0137 | 13 |
a02W000000A8SgtIAF | Test | Record_0177 | 13 |
a02W000000A8SguIAF | Test | Record_0197 | 13 |
a02W000000A8Sh0IAF | Test | Record_0118 | 13 |
a02W000000A8Sh1IAF | Test | Record_0158 | 13 |
a02W000000A8Sh2IAF | Test | Record_0138 | 13 |
a02W000000A8Sh3IAF | Test | Record_0178 | 13 |
a02W000000A8Sh4IAF | Test | Record_0198 | 13 |
a02W000000A8ShAIAV | Test | Record_0119 | 13 |
a02W000000A8ShBIAV | Test | Record_0159 | 13 |
a02W000000A8ShEIAV | Test | Record_0199 | 13 |
a02W000000A8ShCIAV | Test | Record_0139 | 13 |
a02W000000A8ShDIAV | Test | Record_0179 | 13 |
Since I didn't want to include all 700 test records, another block of records had their Letter_counter__c field set to all 3s and another group all 11.
Any ideas what is happening?
- tmbarry
- July 16, 2013
- Like
- 0
Update an Account Record Field from a Child record, Based on an Account Update
I am trying update a field on a on an account record from a value on a child record. Normally I would use a Roll Up summary field, but my Child record criteria field is a formula field and I cannot use a formula field as a roll up summary criteria.
My scenario is this. On the account field I have a field : "number of lives", a simple numeric field. The then have a child object that have pricing values depending on the # of lives from the parent account. Each Child record has a Min # of Lives Field and a Max # of Lives Field and if the Account.number of lives falls between the two, a formula field on the Pricing record returns a value of true.
Whichever record has the true value, I want to return the Pricing__c.Total__c to the Account.Total_Price__c field. Since the Number of lives updates on the Account record, I built the trigger on the account record:
trigger UpdatePricing on Account (before update) { For (Account acct:Trigger.new){ String AcctId = acct.id; List<Account> AccountToUpdate = new List<Account>(); For(Pricing__c pri: [Select id, Total__c from Pricing__c where Account__c =: acctid and Active__c = 'True' ]){ //AccountToUpdate.Total_Price__c = pri.total__c; Update AccountToUpdate; } } }
But I can not for the life of me figure out how to make this work. This is one of the error messages I am getting:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UpdatePricing caused an unexpected exception, contact your administrator: UpdatePricing: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 001i000000Crwx6AAB; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 001i000000Crwx6) is currently in trigger UpdatePricing, therefore it cannot recursively update itself: []: Trigger.UpdatePricing: line 10, column 1
Any help would be greatly appreciate.
- tmbarry
- June 20, 2013
- Like
- 0
Access a field on a Child record
Hello All,
I am trying to write a trigger to update the fields on an object based on the completion of a task.
trigger UpdateSentMail_02 on Task (after Insert, after update){ Integer i = 0; // Tasks that meet criteria, and new tasks to create Task[] qualifiedTasks = new Task[0], newTasks = new Task[0]; // Map of SD Members Map<Id,SD_Member__c> members = new Map<Id,SD_Member__c>(); // Find qualifying tasks for(Task record:Trigger.new) if(Record.subject!=null && record.subject.contains('Print Sf Order Submitted') && record.status == 'Completed') qualifiedtasks.add(record); // Obtain member ID values for(Task record:qualifiedtasks) members.put(record.whatid,null); // If there are any membes to query, do so. if(!members.isempty()) members.putall([select id from SD_Member__c where id in :members.keyset()]); for(Task record:qualifiedtasks) { members.get(record.whatid).Send_Monthly_Letter__c=False; } update members.values(); // Get the current Letter Counter value i == (members.get(record.whatid).letter_counter__c); // Increase the Letter Counter by 1 i=i+1; for(Task record:qualifiedtasks) { members.get(record.whatid).Send_Monthly_Letter__c=True; members.get(record.whatid).Make_1st_Follow_Up_Call__c=False; members.get(record.whatid).Make_2nd_Follow_Up_Call__c=False; members.get(record.whatid).Make_3rd_Follow_Up_Call__c=False; members.get(record.whatid).Letter_Counter__c=i; } update members.values(); }
I issue I am havin is with this line:
// Get the current Letter Counter value i == (members.get(record.whatid).letter_counter__c); // Increase the Letter Counter by 1 i=i+1;
I need to get the orginal SD_Member__c.Letter_Counter__c value so I can increase it by one. I was hoping it was as simple as my code above, but I am getting the following error message:
|
Any ideas how I can get the Letter_counter__c value?
- tmbarry
- June 18, 2013
- Like
- 0
Interesting Error Meeasge
I wrote the following trigger to update a set of fields.
trigger Decide_Which_Address_to_Use on SD_Member__c (before update) { For (SD_Member__c SD : Trigger.new){ // Determine if there is a bad address and which one it is. If(sd.address_bad__c==True){ If(SD.Mailing_Address__c.touppercase()==SD.Address__c.touppercase() && SD.Mailing_City__c.touppercase()==SD.City__c.touppercase()&&SD.Mailing_Zip__c==SD.Zip__c){ sd.Bad_HP_Address__c = SD.Mailing_Address__c; sd.bad_HP_City__c = sd.Mailing_city__c; sd.bad_HP_State__c = sd.mailing_state__c; sd.Bad_HP_Zip__c = SD.Mailing_Zip__c; sd.address_bad__c=False;} If(SD.Mailing_Address__c.touppercase()==SD.Pref_Address__c.touppercase() && SD.Mailing_City__c.touppercase()==SD.Pref_city__c.touppercase()&&SD.Mailing_Zip__c==SD.Pref_Zip__c){ sd.Bad_Pref_Adrs_Address__c = SD.Mailing_Address__c; sd.Bad_Pref_Adrs_City__c = sd.Mailing_city__c; sd.Bad_Pref_Adrs_State__c = sd.mailing_state__c; sd.Bad_Pref_Adrs_Zip__c = SD.Mailing_Zip__c; sd.address_bad__c=False;} If(SD.Mailing_Address__c.touppercase()==SD.NCOA_Address__c.touppercase() && SD.Mailing_City__c.touppercase()==SD.NCOA_city__c.touppercase()&&SD.Mailing_Zip__c==SD.NCOA_Zip__c){ sd.Bad_NCOA_Address__c = SD.Mailing_Address__c; sd.Bad_NCOA_City__c = sd.Mailing_city__c; sd.Bad_NCOA_State__c = sd.mailing_state__c; sd.Bad_NCOA_Zip__c = SD.Mailing_Zip__c; sd.address_bad__c=False; }} } }
And it worked fine in my sandbox.
When I moved it to production, I get the following error.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger Update_NCOA_Address_v01 caused an unexpected exception, contact your administrator: Update_NCOA_Address_v01: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a025000000HuNUiAAN; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Decide_Which_Address_to_Use: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.Decide_Which_Address_to_Use: line 12, column 1: []: Trigger.Update_NCOA_Address_v01: line 41, column 1
So I went back in to my sandbox and change the trigger to (after Update), then I got the error in my sandbox account.
So why does Before Update, give me an error in Production and not Sandbox?
- tmbarry
- June 11, 2013
- Like
- 0
Developer script exception
Hello All,
I am getting a Developer script exception error on one of my triggers. The error states:
Apex script unhandled trigger exception by user/organization: XXXXXXXXXXXXXX/xxxxxxxxxxxxxx
Update_NCOA_Address_v01: System.LimitException: Too many DML statements: 151
trigger Update_NCOA_Address_v01 on printsf__Collateral_Send_History__c (after insert, after update) { // Update the appropriate SD_Member__c record with NCOA address from PrintSF For(printsf__Collateral_Send_History__c CSH : Trigger.new){ // Get the SD Member Id from the recipient id field //String strSDId = CSH.printsf__Recipient_ID__c; If(CSH.printsf__NCOA_Result__c=='None'){ SD_Member__c SD = New SD_Member__c (id=CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c, NCOA_Error_Code__c = CSH.printsf__NCOA_Result__c, NCOA_Error_Description__c = CSH.printsf__NCOA_Result_Description__c); Update SD;} If(CSH.printsf__NCOA_Result__c=='Fowarded'){ SD_Member__c SD = New SD_Member__c (id=CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c); Update SD;} If(CSH.printsf__NCOA_Result__c=='Failed'){ SD_Member__c SD = New SD_Member__c (id=CSH.printsf__Recipient_ID__c, NCOA_Address__c = CSH.printsf__Street__c, NCOA_City__c = CSH.printsf__city__c, NCOA_State__c = CSH.printsf__State__c, NCOA_Zip__c = CSH.printsf__Zip_Code__c, Address_Bad__c = True); Update SD;} }}
What happens is, I send a between 3,000 and 5,000 records to a third party print vendor and they return their validity check results, the "none", "fowarded" or "failed" to their printsf_collateral_send_history__c object. As each record returns, the trigger updates fields on my custom object SD_Member__c.
I thought I had "bulkified" the trigger, but maybe not.
Thanks for the help,
Todd B.
- tmbarry
- June 07, 2013
- Like
- 0
System.NullPointerException: Attempt to de-reference a null object - Not sure Why this Happening.
I wrote a trigger to create a task when a certain field is updated. The trigger works fine and as expected. However, everytime I run the test class I get the following error:
System.DmlException: Update failed. First exception on row 0 with id a0NW0000000ddmlMAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Create_Make_1st_Call: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.Create_Make_1st_Call: line 43, column 1: [] Class.TestClass_SD_Member_Mailing_History.myUnitTest: line 39, column 1
Here is my Test Class:
@isTest class TestClass_SD_Member_Mailing_History { static testMethod void myUnitTest() { // TO DO: implement unit test // Create SD Member Record SD_Member__c sd = New SD_Member__c(First_Name__c = 'John', Last_Name__c = 'Smith', Ins_ID_Member__c = '123456', Ins_ID_Suscriber__c = '456789', address__c = '123 Main Stret', city__c = 'Aster', state__c = 'CT', zip__c = '06001', name = 'John Smith', Lost_Contact_Follow_Up__c = False, Mailing_Cycle__c='Week 2.1'); insert sd; // Create Mailing Order printsf__Collateral_Order_History__c PO = new printsf__Collateral_Order_History__c(Name='Dummy Order 02', printsf__Order_Number__c=2); Insert po; // Create SD Mailing History Item printsf__Collateral_Send_History__c MH = new printsf__Collateral_Send_History__c(Name='Test Mailer Entry XYZ', printsf__Recipient_ID__c = sd.id, printsf__Send_History_ID__c = 123654, printsf__Order__c = po.id); Insert MH; //Test Order Execute logic for send "make first Call" task SD_Member_Mailing_History__c SDMH = New SD_Member_Mailing_History__c(Mailer_History_Item__c =MH.id , SD_Member_Stakeholders__c = sd.id); Insert SDMH; SDMH.Order_Executed__c = True; system.debug(sd.id); Update SDMH; }}
Here is my trigger.
trigger Create_Make_1st_Call on SD_Member_Mailing_History__c (After Update) { //This is the real one!!!!!! // Variables Date CallDate1 = DateTime.now().addDays(-10000).date(); // Create my own Right Text Function public String right(String s, Integer i) { if (s == null || s == '' || i <=0 ) { return ''; } else if (i >= s.length()) { return s; } else { return s.subString(s.length() - i, s.length()); } } //----------------------------------------------------------------------- // Find Entries that meet criteria and new Entries to create SD_Member_Mailing_History__c [] qualifiedEntry = new SD_Member_Mailing_History__c[0]; Task [] newTask = new Task[0]; // Map of SD Member Ids Map<Id,SD_Member__c> members = new Map<Id,SD_Member__c>(); // Find qualifing Entries For (SD_Member_Mailing_History__c record:trigger.new) If(record.Order_executed__c ==True) qualifiedEntry.add(record); //Obtain SD Member Ids For(SD_Member_Mailing_History__c record:qualifiedEntry) members.put(record.SD_Member_Id__c,null); // If there are any members to query, do so. If(!members.isempty()) members.putall([Select id, Mailing_Cycle__c, Ownerid from SD_Member__c where id in :members.keyset()]); // For each qualifing record, create a task. For(SD_Member_Mailing_History__c record:qualifiedEntry){ // Check to see what mailing cycle the SD Member is in to determine when to make the follow up call If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='1') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+3,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='2') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+4,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='3') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+5,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='4') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+6,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='5') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+7,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='6') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+8,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='7') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+9,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='8') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+10,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); } Else If(right(members.get(record.SD_Member_id__c).Mailing_Cycle__c,1)=='9') { newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+11,Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid)); //Old Activity Date Logic //ActivityDate=DateTime.now().addDays(11).date() } } // Insert new task records into database. insert newtask; }
Everything was working fine until I changed one line of code in my trigger.
I change the if statements from
newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=DateTime.now().addDays(11).date(),Status='Not Started', ownerid=members.get(record.SD_Member_id__c).ownerid));
To
newtask.add(new task(whatid=(record.SD_Member_id__c),subject='Make 1st Follow Up Call',ActivityDate=record.Date_Delivered__c+11,Status='Not Started'
Any Ideas
- tmbarry
- May 21, 2013
- Like
- 0
How to Bulkify a Trigger
I recently wrote a trigger that when a Task with a certain subject is closed, create a new follow up task. Everything was working fine until one of my users bulk loaded a few hundred records and I received an error message. Now I need to bulkify this trigger and have no idea how.
trigger Send_Qtrly_Update_02_v02 on Task (after insert, after update) { for (Task t : Trigger.new){ // Today's Date plus 90 days for scheduling next call DateTime dT = System.now()+90; Date myDate = date.newinstance(dT.year(), dT.month(), dT.day()); // Today's Date for updating the Last_Outreach_Call_Made__c field on the Provider_Facility__c record. DateTime dT1 = System.now(); Date TodayDate = date.newinstance(dT1.year(), dT1.month(), dT1.day()); // Step 1 - Get the Outreach_Agent__c id to assign the task too. This logic is used incase the Outreach value on the Provider // Facilty changes in the future. For (Provider_Facility__c prov: [ Select id, Outreach_Agent__c from Provider_Facility__c Where id =: t.whatid]){ // Now Check to see if the Task meets the right citeria if (t.Subject == 'Quarterly Outreach Call' && t.IsClosed==True) { // Insert a recurring task Task t1 = new task(Whatid=t.whatid, Subject='Quarterly Outreach Call', ActivityDate=myDate, Ownerid=prov.Outreach_Agent__c ); insert t1; // Update the Last_Outreach_Call_Made__c field on the Provider_Facility__c record Provider_Facility__c prov01 = New Provider_Facility__c(id=t.WhatId, Last_Outreach_Call_Made__c=TodayDate); Update prov01; }} } }
Can someone point me in the right direction on how to do this?
Any help would be much appreciated. It seems like everytime I learn how to do something, I need to re-learn it to better fit the Apex framework.
- tmbarry
- April 18, 2013
- Like
- 0