-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
21Questions
-
25Replies
Invalid Field Error for Custom Fields but Not Standard Fields on User object?
Here is the code that generated that error:
if(contactEval.Owner.District__c == '') { approvalReasons.add(BUDGET_LIMIT_EXCEEDED_REASON); itemApprovalReasons.add(BUDGET_LIMIT_EXCEEDED_REASON); requiresProductApproval = true; }
But, if I use a Standard Field, I get no error message. For example:
if(contactEval.Owner.IsActive) { approvalReasons.add(BUDGET_LIMIT_EXCEEDED_REASON); itemApprovalReasons.add(BUDGET_LIMIT_EXCEEDED_REASON); requiresProductApproval = true; }
I have tried this for a few different Standard and Custom fields to confirm that it's not these specific fields.
Any ideas why I can reference a custom field on the User object?
- akallioWiley
- February 23, 2015
- Like
- 0
- Continue reading or reply
Can't log into Workbench from Custom Domain
I choose the 'Log into a custom domain' option, and enter the domain. The result upon clicking the Continue buttion is red border appears around the domain. No error message.
has anybody else ran into this?
Thanks!
- akallioWiley
- January 28, 2015
- Like
- 0
- Continue reading or reply
Admin looking for help. Why is this trigger firing?
So, here is the trigger:
trigger opptyTrigger_EvalSyncController on Opportunity (after update) {
if(trigger.isUpdate) {
Map<Id,Opportunity> courseToOppty = new Map<Id,Opportunity>();
for(Opportunity oppty : trigger.new) {
if((oppty.StageName == 'Active' || oppty.StageName == 'Short Stack' || oppty.StageName == 'Probable' ||
oppty.StageName == 'Won' || oppty.StageName == 'Won Format TBD')
&&
(trigger.oldMap.get(oppty.Id).StageName != 'Active' || trigger.oldMap.get(oppty.Id).StageName != 'Short Stack' ||
trigger.oldMap.get(oppty.Id).StageName != 'Probable' || trigger.oldMap.get(oppty.Id).StageName != 'Won' ||
trigger.oldMap.get(oppty.Id).StageName != 'Won Format TBD') ) {
courseToOppty.put(oppty.Course__c,oppty);
}
}
if(!courseToOppty.isEmpty()) {
coreSynchronizer.sendEvalsToCore(courseToOppty);
}
}
}
======================================================================================================================
And here is the script with the error message that follows:
List<Opportunity> upOppties = new List<Opportunity>();
for(Opportunity oppty : [select Id, Name, OwnerId, Owner.Name, TerritoryId, Territory.Name from Opportunity where Owner.Name = 'Andy Kallio' Limit 100]) {
system.debug('Results: '+oppty.Id+' '+oppty.Name+' '+oppty.Territory.name+' '+oppty.Owner.Name);
oppty.OwnerId = '005G0000004NdWEIA0';
oppty.territoryId = '04TA00000004GGfMAM';
upOppties.add(oppty);
}
update upOppties;
==============================================================================================================
Apex script unhandled trigger exception by user/organization: 005G0000002DZlD/00DA0000000YFEv
opptyTrigger_EvalSyncController: execution of AfterUpdate
caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null)
2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)
Class.coreSynchronizer.sendEvalsToCore: line 13, column 1
Trigger.opptyTrigger_EvalSyncController: line 42, column 1
- akallioWiley
- May 29, 2014
- Like
- 0
- Continue reading or reply
Debugging In IE?
The page is basically just a form for entering addresses. In IE when the Save button is clicked the picklist field for State is updated to Null. The controller will not allow the information to be saved without that data...so an error message is displayed on the page.
I am just looking for some basic advice on where to start with debugging this because I'm an admin that has taught himself to write some apex and visualforce. The is the first time I've had a browser based issue and I'm not sure where to start. I've started to play around witih IE's developer tool...a little overwhelming.
- akallioWiley
- January 29, 2014
- Like
- 0
- Continue reading or reply
Getting Custom Chatter Action to work with Case Assignment Rules?
My 2 options for assigning the case were to use workflow rules or write a trigger. I went with the trigger because I have 5 and counting assignment rules and I don't want to create a workflow rule for each.
The trigger works fine too. The issue is that when the trigger is used the resulting ChatterFeedItem is not created....once the user hits 'Submit' the case is created, but the Chatter post is not created. So, I'm looking for ideas on how to get that chatter post created.
Here is the trigger's logic:
if(trigger.isInsert && trigger.isAfter) {
//This will ensure that Case assignments are run even Cases are created through Chatter Actions or through some other service.
//Fetching the assignment rules on case
AssignmentRule AR = new AssignmentRule();
AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];
//Creating the DMLOptions for "Assign using active assignment rules" checkbox
Database.DMLOptions dmlOpts = new Database.DMLOptions();
dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;
Set<Id> newCaseIds = new Set<Id>();
List<Case> newCases = new List<Case>();
for(Case newCaseId : trigger.new) {
newCaseIds.add(newCaseId.Id) ;
}
for(Case newCase : [select Id from Case where Id IN :newCaseIds]) {
newCase.setOptions(dmlOpts);
newCases.add(newCase);
}
update newCases;
- akallioWiley
- January 15, 2014
- Like
- 0
- Continue reading or reply
soql optimization question
Can anybody help me figure out why the following 2 soql queries seem to take forever...they timeout in the workbench. Do you see anything I could to imporve their performance? Thanks!
Select Contact__c,ISBN_13__c,Order_Date__c,Id,Ship_Date__c,Ship_Method_Description__c,Contact__r.Email,Product__r.Name From Comp_Item__c where (LastModifiedDate >=2013-04-07T20:50:40.9793994Z or CreatedDate <=2013-04-07T20:50:40.9793994Z) and Contact__r.Email like '%@%' and Contact__c != Null And (NOT Contact__r.Email like '%@wiley.com') and Contact__r.Inactive__c = FALSE
Select ContactId,Id,OpportunityId,Contact.Email,Opportunity.BRV__c,Opportunity.CA_Tier__c,Opportunity.Custom__c,Opportunity.CloseDate,Opportunity.Enrolment__c,Opportunity.MarketConsultant__c,Opportunity.Type,Opportunity.OwnerId,Opportunity.Primary_Long_Title__c,Opportunity.Primary_Title_Author__c,Opportunity.PrimaryTitleCourseCodeNum__c,Opportunity.Primary_Title_ISBN_13__c,Opportunity.Priority_Target__c,Opportunity.Renew__c,Opportunity.Semester__c,Opportunity.StageName,Opportunity.Est_Revenue__c,Opportunity.Tier__c,Opportunity.WileyPLUS__c,Opportunity.Year__c From OpportunityContactRole where ((OpportunityContactRole.LastModifiedDate >=2013-04-07T20:51:55.6877994Z or CreatedDate <=2013-04-07T20:51:55.6877994Z) or (Opportunity.LastModifiedDate >=2013-04-07T20:51:55.6877994Z) or (Contact.LastModifiedDate >=2013-04-07T20:51:55.6877994Z)) and (Contact.Email like '%@%' and (NOT Contact.Email like '%@wiley.com') and Contact.Inactive__c = FALSE)
- akallioWiley
- April 10, 2013
- Like
- 0
- Continue reading or reply
A Simple Chatter Trigger
Hi All. Below is a really simple chatter trigger that I have written to help me with creating cases from chatter posts. It's my first chatter trigger, and I'm getting stumped on the line that is commented out. I can't get that line to compile. It seems that I can't get the FeedItem's Body from the feedcomment. Is my syntax wrong, or is not possible this way?
Thanks!
trigger createCaseFromChatter on FeedComment (after insert) { for(FeedComment f : trigger.new) { if(f.CommentBody.startsWith('!newCase')) { Case newCase = new Case( Subject = f.CommentBody, //Description = f.FeedItem.Body, Origin = 'Chatter', RecordtypeId = '012G0000000yArc', Status = 'Open' ); insert newCase; } } }
- akallioWiley
- March 26, 2013
- Like
- 0
- Continue reading or reply
Map Returns Null in keySet()
Hi All,
I'm having trouble debugging the following line, which is highlighted in code below:
consCourseCodeMapBig.get(Con.Id).keySet()
for some reason the first value in the set is Null, and the second value is the value I'm expecting to receive. I have confirmed this by testing in UI with the system.assert that you see in the red highlighed section. That system assert returns the following:
Error:
courseRoleTrigger: execution of AfterInsert caused by: System.AssertException: Assertion Failed: Youre here {null, a0FZ0000001sjSzMAI} Class.contactToCourseCodeHandler.saveLogic: line 83, column 1 Class.contactToCourseCodeHandler.newCourseRoleHandler: line 10, column 1 Trigger.courseRoleTrigger: line 20, column 1
I didn't even think it was possible to have a null value in a keySet, and not sure where in my code it would be happening. The section highlighted in blue is where the map is being built. I have used system.asserts there,too and do not find null value there.
Thanks for any help!
public with sharing class contactToCourseCodeHandler { public static void newCourseRoleHandler(Set<Id> newCRs) { Map<Id,Map<Id,courseCodeWrapper>> contactToCourseCodeBig = createBigCCWMap(newCRS, 'cRole'); Map<Id,courseCodeWrapper> contactToCourseCodeLittle = createLittleCCWMap(newCRS, 'cRole'); if(!contactToCourseCodeBig.isEmpty()) { String reqType = 'Insert/Update'; String source = 'Course'; saveLogic(contactToCourseCodeBig,contactToCourseCodeLittle, reqType, source); } } public static void deletedCourseRoleHandler(Set<Id> deletedCRs) { map<Id,Map<Id,courseCodeWrapper>> contactToCourseCodeBig = createBigCCWMap(deletedCRs, 'cRole'); map<Id,courseCodeWrapper> contactToCourseCodeLittle = createLittleCCWMap(deletedCRs, 'cRole'); if(!contactToCourseCodeBig.isEmpty()) { String reqType = 'Delete'; String source = 'Course'; saveLogic(contactToCourseCodeBig,contactToCourseCodeLittle, reqType, source); } } public static void updatedCourseRoleHandler() { } public static void evalItemHandler(Set<Id> evalItems) { map<Id,Map<Id,courseCodeWrapper>> contactToCourseCodeBig = createBigCCWMap(evalItems, 'eval'); map<Id,courseCodeWrapper> contactToCourseCodeLittle = createLittleCCWMap(evalItems, 'eval'); if(!contactToCourseCodeBig.isEmpty()) { String reqType = 'Insert/Update'; String source = 'Eval'; saveLogic(contactToCourseCodeBig,contactToCourseCodeLittle, reqType, source); } } public static void deletedEvalItemHandler(Set<Id> deletedEvalItems) { map<Id,Map<Id,courseCodeWrapper>> contactToCourseCodeBig = createBigCCWMap(deletedEvalItems, 'eval'); map<Id,courseCodeWrapper> contactToCourseCodeLittle = createLittleCCWMap(deletedEvalItems, 'eval'); if(!contactToCourseCodeBig.isEmpty()) { String reqType = 'Delete'; String source = 'Eval'; saveLogic(contactToCourseCodeBig,contactToCourseCodeLittle, reqType, source); } } public static void deletedEvalHandler(Set<Id> evals) { Set<Id> evalItems = new Set<Id>(); for(Comp_Item__c ei : [select ID from Comp_Item__c where Comp__c IN :evals]) { evalItems.add(ei.Id); } map<Id,Map<Id,courseCodeWrapper>> contactToCourseCodeBig = createBigCCWMap(evalItems, 'eval'); map<Id,courseCodeWrapper> contactToCourseCodeLittle = createLittleCCWMap(evalItems, 'eval'); if(!contactToCourseCodeBig.isEmpty()) { String reqType = 'Delete'; String source = 'Eval'; saveLogic(contactToCourseCodeBig,contactToCourseCodeLittle, reqType, source); } } public static void saveLogic(Map<Id,Map<Id,courseCodeWrapper>> consCourseCodeMapBig, Map<Id,courseCodeWrapper> consCourseCodeMapLittle, String triggerType, String source) { List<Contact_Course_Code__c> ccdUpsert = new List<Contact_Course_Code__c>(); List<Contact_Course_Code__c> ccdDelete = new List<Contact_Course_Code__c>(); if(triggerType == 'Insert/Update') { for(Contact Con : [Select Id, Course_Code_Count__c, (Select Id, Contact__c, Course_Code__c, CourseRoleCount__c, EvalCount__c from Contact_Course_Code__r) from Contact where Id IN :consCourseCodeMapBig.keySet()]) { if(Con.Course_Code_Count__c == 0) { for(Id cccId : consCourseCodeMapBig.get(Con.Id).keySet()) { system.assert(false,'Youre here '+consCourseCodeMapBig.get(Con.Id).keySet()); Contact_Course_Code__c newCCC = new Contact_Course_Code__c( Contact__c = Con.Id, Course_Code__c = cccId, CourseRoleCount__c = source == 'Course' ? consCourseCodeMapLittle.get(Con.Id).theCount : 0, EvalCount__c = source == 'Eval' ? consCourseCodeMapLittle.get(Con.Id).theCount : 0 ); ccdUpsert.add(newCCC); } }else{ for(Contact_Course_Code__c existingCCC : Con.Contact_Course_Code__r) { if(consCourseCodeMapBig.get(Con.Id).containsKey(existingCCC.Course_Code__c)) { existingCCC.CourseRoleCount__c += source == 'Course' ? consCourseCodeMapBig.get(Con.Id).get(existingCCC.Course_Code__c).theCount : 0; existingCCC.EvalCount__c += source == 'Eval' ? consCourseCodeMapBig.get(Con.Id).get(existingCCC.Course_Code__c).theCount : 0; ccdUpsert.add(existingCCC); } } } } } if(null != ccdUpsert) { upsert ccdUpsert; } /*if(triggerType == 'Delete') { for(Contact con : [Select Id,Name, Course_Code_Count__c, (Select Id, Contact__c, Course_Code__c, CourseRoleCount__c, Current__c, Primary__c,Total_Association_Count__c,EvalCount__c from Contact_Course_Code__r) from Contact where Id IN: consCourseCodeMapBig.keySet()]) { if(con.Course_Code_Count__c > 0) { for(courseCodeWrapper cdWrap : consCourseCodeMap.get(con.Id) ) { for(Contact_Course_Code__c existingCCC1 : Con.Contact_Course_Code__r) { if(conCourseCodeMapBig.get(Con.Id).containsKey(existingCCC1.Course_Code__c)) { if(existingCCC1.Total_Association_Count__c > 1) { existingCCC1.CourseRoleCount__c -= source == 'Course' ? conCourseCodeMapBig.get(Con.Id).get(existingCCC1.Course_Code__c).theCount : 0; existingCCC1.EvalCount__c -= source == 'Eval' ? conCourseCodeMapBig.get(Con.Id).get(existingCCC1.Course_Code__c).the : 0; ccdUpsert.add(existingCCC1); }else{ ccdDelete.add(existingCCC1); } } } } if(ccdUpdate.size() > 0) { update conCourseCodesUpdate.values(); } if(ccdDelete.size() > 0) { delete conCourseCodesDel.values(); } } } } */ } //uses the triggered CourseRoles to map the Contact Id to CourseCodes...course codes in wrapper class. public static Map<Id,Map<Id,courseCodeWrapper>> createBigCCWMap(Set<Id> IDs, String source) { Map<Id,Map<Id,courseCodeWrapper>> bigMap = new Map<Id,Map<Id,courseCodeWrapper>>(); Map<Id,courseCodeWrapper> littleMap = new Map<Id,courseCodeWrapper>(); if(source == 'cRole') { for(aggregateResult cr1 : [select Contact__c, Course__r.ACE_Code_4__c, Count(Id) from Course_Role__c where Id IN: IDs AND Course__r.ACE_Code_4__c != null AND Contact__c != null Group By Rollup (Contact__c,Course__r.ACE_Code_4__c)]) { courseCodeWrapper wrappedCourse = new courseCodeWrapper(String.valueOf(cr1.get('Contact__c')),String.valueOf(cr1.get('ACE_Code_4__c')),Integer.valueOf(cr1.get('expr0')),source); littleMap.put(wrappedCourse.courseCodeId,wrappedCourse); bigMap.put(String.valueOf(cr1.get('Contact__c')),littleMap); } } else { for(aggregateResult ei : [select Contact__c,Product__r.ACE_Code_4__c, Count(Id) from Comp_Item__c where Id IN: Ids AND Product__r.ACE_Code_4__c != null and Contact__c != null Group By Rollup (Contact__c,Product__r.ACE_Code_4__c)]) { courseCodeWrapper wrappedEval = new courseCodeWrapper(String.valueOf(ei.get('Contact__c')), String.valueOf(ei.get('ACE_Code_4__c')), Integer.valueOf(ei.get('expr0')),source); littleMap.put(wrappedEval.courseCodeId,wrappedEval); bigMap.put(String.valueOf(ei.get('Contact__c')),littleMap); } } return bigMap; } public static Map<Id,courseCodeWrapper> createLittleCCWMap(Set<Id> IDs, String source) { Map<Id,courseCodeWrapper> littleMap = new Map<Id,courseCodeWrapper>(); if(source == 'cRole') { for(aggregateResult cr1 : [select Contact__c, Course__r.ACE_Code_4__c, Count(Id) from Course_Role__c where Id IN: IDs AND Course__r.ACE_Code_4__c != null AND Contact__c != null Group By Rollup (Contact__c,Course__r.ACE_Code_4__c)]) { courseCodeWrapper wrappedCourse = new courseCodeWrapper(String.valueOf(cr1.get('Contact__c')),String.valueOf(cr1.get('ACE_Code_4__c')),Integer.valueOf(cr1.get('expr0')),source); littleMap.put(String.valueOf(cr1.get('Contact__c')),wrappedCourse); } } else { for(aggregateResult ei : [select Contact__c,Product__r.ACE_Code_4__c, Count(Id) from Comp_Item__c where Id IN: Ids AND Product__r.ACE_Code_4__c != null and Contact__c != null Group By Rollup (Contact__c,Product__r.ACE_Code_4__c)]) { courseCodeWrapper wrappedEval = new courseCodeWrapper(String.valueOf(ei.get('Contact__c')), String.valueOf(ei.get('ACE_Code_4__c')), Integer.valueOf(ei.get('expr0')),source); littleMap.put(String.valueOf(ei.get('Contact__c')),wrappedEval); } } return littleMap; } public class courseCodeWrapper { public Id contactId {get; set;} public Id courseCodeId {get; set;} public Integer theCount {get; set;} public String source {get; set;} public courseCodeWrapper(Id conId, Id ccId, Integer elCount, String wCDSource ) { contactId = conId; courseCodeId = ccId; theCount = elCount; source = wCDSource; } } }
- akallioWiley
- February 28, 2013
- Like
- 0
- Continue reading or reply
Help with null pointer exception
The method below fails and throws a null pointer exception on the highlighted and only on the highlighted line, which is strange because the highlighted is nearly exactly the same as a line above it that is in a different if/else branch. The other thing that has me scratching my head is that the system.assert(also highlighted) shows me that the variable called 'source' is not null and has the expected value. So, can anyone spot why I might be getting this error?
Thanks!
public static void saveLogic(Map<Id,List<courseCodeWrapper>> consCourseCodeMap, String triggerType, String source) { if(triggerType == 'Insert/Update') { List<Contact_Course_Code__c> conCourseCodes = new List<Contact_Course_Code__c>(); for(Contact con : [Select Id,Name, Course_Code_Count__c, (Select Id, Contact__c, Course_Code__c, CourseRoleCount__c, Current__c, Primary__c, EvalCount__c from Contact_Course_Code__r) from Contact where Id IN: consCourseCodeMap.keySet()]) { if(con.Course_Code_Count__c == 0) { for(courseCodeWrapper cc : consCourseCodeMap.get(con.Id)) { //Integer currentCount = cc.currentCheck ? 1 : 0; //Integer primaryCount = cc.PrimaryCheck ? 1 : 0; Contact_Course_Code__c newCCC = new Contact_Course_Code__c( Contact__c = con.Id, Course_Code__c = cc.courseCodeId, CourseRoleCount__c = source == 'Course' ? 1 : 0, EvalCount__c = source == 'Eval' ? 1 : 0 //Current__c = currentCount, //Primary__c = primaryCount ); conCourseCodes.add(newCCC); } insert conCourseCodes; } else if(con.Course_Code_Count__c > 0) { for(courseCodeWrapper cdWrap : consCourseCodeMap.get(con.Id) ) { //Integer currentCounter = cdWrap.currentCheck ? 1 : 0; //Integer primaryCounter = cdWrap.primaryCheck ? 1 : 0; for(Contact_Course_Code__c conCD : con.Contact_Course_Code__r) { if(conCD.Course_Code__c == cdWrap.CourseCodeId) { conCD.CourseRoleCount__c += source == 'Course' ? 1 : 0; conCD.EvalCount__c += source == 'Eval' ? 1 : 0; //conCD.Current__c += currentCounter; //conCD.Primary__c += primaryCounter; conCourseCodes.add(conCD); } } } update conCourseCodes; } } } if(triggerType == 'Delete') { List<Contact_Course_Code__c> conCourseCodesUpdate = new List<Contact_Course_Code__c>(); List<Contact_Course_Code__c> conCourseCodesDel = new List<Contact_Course_Code__c>(); for(Contact con : [Select Id,Name, Course_Code_Count__c, (Select Id, Contact__c, Course_Code__c, CourseRoleCount__c, Current__c, Primary__c,Total_Association_Count__c from Contact_Course_Code__r) from Contact where Id IN: consCourseCodeMap.keySet()]) { if(con.Course_Code_Count__c > 0) { for(courseCodeWrapper cdWrap : consCourseCodeMap.get(con.Id) ) { //Integer currentCounter = cdWrap.currentCheck ? 1 : 0; //Integer primaryCounter = cdWrap.primaryCheck ? 1 : 0; for(Contact_Course_Code__c conCD : con.Contact_Course_Code__r) { if(conCD.Course_Code__c == cdWrap.CourseCodeId) { if(conCD.Total_Association_Count__c > 1) { conCD.CourseRoleCount__c -= source == 'Course' ? 1 : 0; //system.assert(false, 'This is your SOURCE: '+source); conCD.EvalCount__c -= source == 'Eval' ? 1 : 0; //conCD.Current__c += currentCounter; //conCD.Primary__c += primaryCounter; conCourseCodesUpdate.add(conCD); }else{ conCourseCodesDEL.add(conCD); } } } } if(conCourseCodesUpdate.size() > 0) { update conCourseCodesUpdate; } if(conCourseCodesDel.size() > 0) { delete conCourseCodesDel; } } } } }
- akallioWiley
- February 19, 2013
- Like
- 0
- Continue reading or reply
Use an operator inside a Ternary Opeartor?
I am trying to increment a field based on if/else logic. I'm just starting to get the hang of the ternary operator. So, I wrote the following, but it won't compile. Does anybody know if it's possible to do this, or does it have to go in an if else statement?
conCD.CourseRoleCount__c = source == 'Course' ? +=1 : 0;
- akallioWiley
- February 19, 2013
- Like
- 0
- Continue reading or reply
Help with Null Pointer Exception. SOSL in VF page
I am trying to use a SOSL query where the criteria will be input from a text box on a VF page. I am running into a null pointer exception and struggling to figure out what it is. It is my first time using SOSL. So, I'm hoping the issue will be easy to spot.
public with sharing class mergeMaster { public string searchString {get; set;} public List<resultWrapper> wrappedResults {get; set;} //fired when the Search button is clicked public PageReference search() { List<List<SObject>> searchList = [FIND :searchString IN ALL FIELDS RETURNING CONTACT (Id, Name, Account.Name Order By Name) ]; for(Contact reCon : (List<Contact>) searchList[0]) { resultWrapper wrCon = new resultWrapper(reCon.Id, reCon.Name, reCon.Account.Name); //system.assert(false,'Results: '+wrCon); wrappedResults.add(wrCon); } return null; } public class resultWrapper { public Id contactID {get; set;} public String contactName {get; set;} public String accountName {get; set;} public List<SelectOption> masterORchild {get; set;} public resultWrapper(ID cID, String cName, String aName) { contactID = cID; contactName = cName; accountName = aName; this.masterORchild = new List<SelectOption>{new SelectOption('The Master','The Master'),new SelectOption('Merge','Merge')}; } } }
<apex:page sidebar="false" controller="mergeMaster" standardstylesheets="false"> <apex:sectionheader title="Merge Master" /> <apex:form id="theform"> <apex:pageBlock mode="edit" id="block"> <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:panelGroup > <apex:inputText id="searchString" value="{!searchString}"/> <apex:commandButton value="Search" action="{!search}" rerender="block" status="status"/> </apex:panelGroup> </apex:pageBlockSectionItem> </apex:pageBlockSection><br/> <apex:actionStatus id="status" startText="Searching... please wait..."/> <apex:pageBlockSection > <apex:pageBlockSection title="Search Results" id="resultsBlock" columns="1"> <apex:pageBlockTable value="{!wrappedResults}" var="item" rendered="{!NOT(ISNULL(wrappedResults))}"> <apex:column value="{!item.contactName}" headerValue="Contact" width="100"/> <apex:column: value="{!item.accountName}" headerValue="Account" width="200"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
- akallioWiley
- November 26, 2012
- Like
- 0
- Continue reading or reply
SOQL Query works in after update, but not after delete
The class posted below is fed a set of Contact Ids that comes from a trigger on the Task object. We use particular Task record type to track what we call 'Market Development'. A Market Development task contributes towards a total Market Development score for the contact. Therefore we have this class which will add or subtract MD points for a Contact as MD tasks are added or deleted.
My issue is that Total Points are not being subtracted when an MD task is deleted. As I said the class receives a set of contact ids and processes MD points from there by using SOQL to select the Contacts and their MD Tasks. What I have found is that, in after delete trigger context only, the SOQL query that is supposed to get the Contact fails to find the contact. And this where I get stuck. I have put comments in the code below to hopefully help you understand how I am trying to debug this.
Any thoughts on why this is happening or a different debugging technique would be great.
public class MarketDevelopmentScorecard { public static void updateMarketDevelopmentScorecard(Set<Id> contactIds) { RecordType mdRecordType = RecordTypeUtil.getRecordType('Task', 'Market Development'); if (mdRecordType != null) { Date recentActivityDate = System.today().addDays(-1095); // 3 years ago List<Task> mdTasks = [select Id, ActivityDate, MD_Activity_Type__c, WhoId from Task where WhoId in :contactIds and RecordTypeId = :mdRecordType.Id and ActivityDate >= :recentActivityDate]; Map<Id, Set<String>> contactMarketDevelopmentActivities = new Map<Id, Set<String>>(); for (Task t : mdTasks) { if (t.MD_Activity_Type__c != null && t.MD_Activity_Type__c != '') { Set<String> mdActivities = contactMarketDevelopmentActivities.get(t.WhoId); if (mdActivities == null) { mdActivities = new Set<String>(); contactMarketDevelopmentActivities.put(t.WhoId, mdActivities); } mdActivities.add(t.MD_Activity_Type__c); } } List<Market_Development_Rating__c> marketDevelopmentRatings = Market_Development_Rating__c.getAll().values(); for (Id cId : contactIds) { System.debug('JJB contactId: ' + cId); } List<Contact> contacts = [select Id, MD_Total_Points__c, MD_Activities__c from Contact where Id in :contactIds]; //this system assert shows that I am receiving a contact from the trigger, but that the SOQL query doesn't find it //system.assert(false, 'Contacts from Trigger '+contactIds.size()+'Contacts found in database '+contacts.size()); for (Contact c : contacts) { Decimal totalPoints = 0.0; String activities = ''; //in after delete context this system assert never gets hit because this for loop never starts because there is nothing in the List contacts //system.assert(false, 'hello!! '); Set<String> mdActivities = contactMarketDevelopmentActivities.get(c.Id); if (mdActivities == null) { mdActivities = new Set<String>(); } for (Market_Development_Rating__c mdr : marketDevelopmentRatings) { if (mdActivities.contains(mdr.Name)) { totalPoints += mdr.MD_Points__c; if (mdr.Contact_Field_Name__c != null && mdr.Contact_Field_Name__c != '') { c.put(mdr.Contact_Field_Name__c, mdr.MD_Points__c); //system.assert(false, 'the total points are: '+mdr.MD_Points__c); } } else { if (mdr.Contact_Field_Name__c != null && mdr.Contact_Field_Name__c != '') { c.put(mdr.Contact_Field_Name__c, 0.00); } } }
- akallioWiley
- October 26, 2012
- Like
- 0
- Continue reading or reply
Change a Trigger's Name in Production
Hello,
I would like to change the name of one of my triggers. Is there any way to do this in a Production org?
- akallioWiley
- September 28, 2012
- Like
- 0
- Continue reading or reply
Avoid Validation Rules within a Trigger?
Is it possible to make a trigger run so that it bypasses validation rules?
- akallioWiley
- June 20, 2012
- Like
- 0
- Continue reading or reply
Help with Error Handling
I receive the following error when I try to merge 2 contact records: INVALID_FIELD_FOR_INSERT_UPDATE, Contact: bad field names on insert/update call: Comps__r:
The records the I am trying to merge are generated from the following 2 queries:
This will give me the childs in the merge...the record that will get deleted:
Contact childCon : [select Id, Acc_No_Part_1__c, Acc_No_Part_2__c, MergeMasterID__c, (select Id, Contact__r.MergeMasterId__c, External_ID__c from Comps__r) from Contact where Id IN :childCons)]
This gets me the parents:
(Contact masterCon : [select Id, Acc_No_Part_1__c, Acc_No_Part_2__c, MergeMasterID__c, (select Id, Contact__c, Contact__r.MergeMasterId__c, External_ID__c from Comps__r) from Contact where Id IN :masterConSet])
Before I can merge them I have to manipulate the child records found Camps__r. Once those updates are done I run a merge statement.
I think the error happens only when the Child Contact does not have any values in Comps__r. My code should be handling that scenario...In other words I use if statements to test if there are records in Comps__r, and if there is isn't then I have code to handle it differently.
When the child contact has records in comps__r then everything works ok.
The other posts that I have found related to this message are not helping, and the definition for the message in docs seems to be way off the mark:
INVALID_FIELD_FOR_INSERT_UPDATE
You can't combine a person account record type change with any other field update.
So, I am stumped at this point.
- akallioWiley
- June 06, 2012
- Like
- 0
- Continue reading or reply
Help with Partial Processing of Update
Hi All,
I am trying to figure out how do paratial processing of an update for the first time. I have always used dml methods up to this point, but now playing around with database methods.
So I understand the following example just fine:
Database.SaveResult[] lsr = Database.update(accounts, false); for(Database.SaveResult sr : lsr){ if (!sr.isSuccess()) { myMethodToaddToErrorObjectList(sr); } }
This almost works for what I need to do. However, I want to add criteria to the if statement so that I handle certain exceptions in certain ways. So, I want to test for a specific exception, and my question is, is there a better way to do that than to test for the actual message?
If the message thrown is this: "Database.Error[getFields=();getMessage=duplicate value found: External_ID__c duplicates value on record with id: a0IZ0000000RCgm;getStatusCode=DUPLICATE_VALUE;]"
Then am I supposed to put that in my if stattement if I want to handle those types of exceptions in a different way? Something like this:
Database.SaveResult[] saveResults = Database.update(childEvals, false); //now I parse the results and find the errors for(Database.SaveResult saveResult : saveResults) { if(!saveResult.isSuccess()) { //system.assert(false,'Your problem is '+err); Database.Error err = saveResult.getErrors()[0]; if(err = duplicate value found: External_ID__c duplicates value on record with id') { //more code to handle these types of errrors } }
It seems like there should be a better way.
- akallioWiley
- June 06, 2012
- Like
- 0
- Continue reading or reply
Learning Describe Methods
I am just starting to learn about Describe methods because I think it is what I need in order to do what I need to do. I am posting here to see if there are any more skilled developers that can tell me if I'm on the right path. So, here's the deal...
Our Contacts are synced with an ERP via Informatica. The ERP is capable of merging Contact records, but Informatica does not seem to be capable of passing those changes down to SFDC. So, I need to make those changes with a trigger.
I have it worked out so when a Merge takes place in the ERP, Informatica will pass the SFID of the master Contact record to the Child contact record. Which I can use to trigger a yet to be written merge class in apex.
My first hope was that I could simply use the merge dml statement, but learned that the statement can only do 3 records at atime. In other words, you can't 'bulkify' a merge dml.
So, now I am faced with recreating the merge statement. It seems I could do this by simply querying for all of the existing child objects of a Contact record. The problem there is that I will have to remember to add code whenever I add a new object as a child to the Contact object.
So, it seemed like a good opportunity to learn about the Describe methods.
My question is...Is this possible? Would it be possible to get a list of Contacts from a trigger, and use the Describe methods to dynamically query for all of the child objects of each Contact, and then actually make updates to the records in those child objects?
Thanks,
Andy
- akallioWiley
- May 01, 2012
- Like
- 0
- Continue reading or reply
How does one perform a bulk merge?
According to this post it is not possible to make a trigger to merge records in bulk. So the workaround to that challenge, in my simple mind, is to make a trigger that does the reparenting explicitly. There are 2 drawbacks to this that I can see. One is that I will have write a lot more code...writting code to find and update all child records seems like a lot more than simply using the merge method. The second is that if I ever add a relationship to the Contact obect I will have to add to the trigger.
So, I am curious to know if anybody else has found a way to do this. I have a hunch about using @future, but I have a poor understanding of what that is all about.
- akallioWiley
- April 25, 2012
- Like
- 0
- Continue reading or reply
Is it possible to use Merge method outside of a For Loop?...Bulkify Merge statement?
I have the following requirement:
Our contact records are synced with another database via informatica. We need to be able to reflect merge events that happen in the other database in our SFDC org. So, we have a field on Contact object called MergeMasterID__c. This field is meant to hold the SFID of a contact record, which would be the master contact in a merge process. The idea is that when a merge takes place in the other database, informatica can push the SFID of the master record into the MergeMasterID__c field of the child record.
This allows me to write a trigger that is pulled when the MergemasterID__c field on a Contact is updated. The trigger then finds the the master contact record and merges the two together.
Anyway, what I want to figure out with this post is how to execute a merge statement outside of a for loop. the docs only demonstrate how to do them one at a time
Here is the for loop where I currently do the merge. I'm obviously going to hit governor limits at some point with this approach. So, I need to bulikify this somehow?
//iterate through master records and merge children for(Contact masterCon1 : masterCons.values()) { merge masterCon1 masterChildMap.get(masterCon1.Id); }
- akallioWiley
- April 24, 2012
- Like
- 0
- Continue reading or reply
Trigger Status
I have found a trigger in my production org that is not valid and not active. In other words, the field IsValid = False and the Status field equals 'Inactive'.
I have found in the docs that IsValid = False indicates that some change to MetaData has taken place since the trigger was deployed...like a field name being changed, but it seems that trigger will continue to work. I have yet found anything about the circumstances under which a trigger is deactivated.
Does anybody know why a trigger's Status made to be 'Inactive'. I assume this means that trigger is not working at all.
Thanks
- akallioWiley
- March 10, 2012
- Like
- 0
- Continue reading or reply
Invalid Field Error for Custom Fields but Not Standard Fields on User object?
Here is the code that generated that error:
if(contactEval.Owner.District__c == '') { approvalReasons.add(BUDGET_LIMIT_EXCEEDED_REASON); itemApprovalReasons.add(BUDGET_LIMIT_EXCEEDED_REASON); requiresProductApproval = true; }
But, if I use a Standard Field, I get no error message. For example:
if(contactEval.Owner.IsActive) { approvalReasons.add(BUDGET_LIMIT_EXCEEDED_REASON); itemApprovalReasons.add(BUDGET_LIMIT_EXCEEDED_REASON); requiresProductApproval = true; }
I have tried this for a few different Standard and Custom fields to confirm that it's not these specific fields.
Any ideas why I can reference a custom field on the User object?
- akallioWiley
- February 23, 2015
- Like
- 0
- Continue reading or reply
Admin looking for help. Why is this trigger firing?
So, here is the trigger:
trigger opptyTrigger_EvalSyncController on Opportunity (after update) {
if(trigger.isUpdate) {
Map<Id,Opportunity> courseToOppty = new Map<Id,Opportunity>();
for(Opportunity oppty : trigger.new) {
if((oppty.StageName == 'Active' || oppty.StageName == 'Short Stack' || oppty.StageName == 'Probable' ||
oppty.StageName == 'Won' || oppty.StageName == 'Won Format TBD')
&&
(trigger.oldMap.get(oppty.Id).StageName != 'Active' || trigger.oldMap.get(oppty.Id).StageName != 'Short Stack' ||
trigger.oldMap.get(oppty.Id).StageName != 'Probable' || trigger.oldMap.get(oppty.Id).StageName != 'Won' ||
trigger.oldMap.get(oppty.Id).StageName != 'Won Format TBD') ) {
courseToOppty.put(oppty.Course__c,oppty);
}
}
if(!courseToOppty.isEmpty()) {
coreSynchronizer.sendEvalsToCore(courseToOppty);
}
}
}
======================================================================================================================
And here is the script with the error message that follows:
List<Opportunity> upOppties = new List<Opportunity>();
for(Opportunity oppty : [select Id, Name, OwnerId, Owner.Name, TerritoryId, Territory.Name from Opportunity where Owner.Name = 'Andy Kallio' Limit 100]) {
system.debug('Results: '+oppty.Id+' '+oppty.Name+' '+oppty.Territory.name+' '+oppty.Owner.Name);
oppty.OwnerId = '005G0000004NdWEIA0';
oppty.territoryId = '04TA00000004GGfMAM';
upOppties.add(oppty);
}
update upOppties;
==============================================================================================================
Apex script unhandled trigger exception by user/organization: 005G0000002DZlD/00DA0000000YFEv
opptyTrigger_EvalSyncController: execution of AfterUpdate
caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null)
2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)
Class.coreSynchronizer.sendEvalsToCore: line 13, column 1
Trigger.opptyTrigger_EvalSyncController: line 42, column 1
- akallioWiley
- May 29, 2014
- Like
- 0
- Continue reading or reply
Debugging In IE?
The page is basically just a form for entering addresses. In IE when the Save button is clicked the picklist field for State is updated to Null. The controller will not allow the information to be saved without that data...so an error message is displayed on the page.
I am just looking for some basic advice on where to start with debugging this because I'm an admin that has taught himself to write some apex and visualforce. The is the first time I've had a browser based issue and I'm not sure where to start. I've started to play around witih IE's developer tool...a little overwhelming.
- akallioWiley
- January 29, 2014
- Like
- 0
- Continue reading or reply
Getting Custom Chatter Action to work with Case Assignment Rules?
My 2 options for assigning the case were to use workflow rules or write a trigger. I went with the trigger because I have 5 and counting assignment rules and I don't want to create a workflow rule for each.
The trigger works fine too. The issue is that when the trigger is used the resulting ChatterFeedItem is not created....once the user hits 'Submit' the case is created, but the Chatter post is not created. So, I'm looking for ideas on how to get that chatter post created.
Here is the trigger's logic:
if(trigger.isInsert && trigger.isAfter) {
//This will ensure that Case assignments are run even Cases are created through Chatter Actions or through some other service.
//Fetching the assignment rules on case
AssignmentRule AR = new AssignmentRule();
AR = [select id from AssignmentRule where SobjectType = 'Case' and Active = true limit 1];
//Creating the DMLOptions for "Assign using active assignment rules" checkbox
Database.DMLOptions dmlOpts = new Database.DMLOptions();
dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;
Set<Id> newCaseIds = new Set<Id>();
List<Case> newCases = new List<Case>();
for(Case newCaseId : trigger.new) {
newCaseIds.add(newCaseId.Id) ;
}
for(Case newCase : [select Id from Case where Id IN :newCaseIds]) {
newCase.setOptions(dmlOpts);
newCases.add(newCase);
}
update newCases;
- akallioWiley
- January 15, 2014
- Like
- 0
- Continue reading or reply
A Simple Chatter Trigger
Hi All. Below is a really simple chatter trigger that I have written to help me with creating cases from chatter posts. It's my first chatter trigger, and I'm getting stumped on the line that is commented out. I can't get that line to compile. It seems that I can't get the FeedItem's Body from the feedcomment. Is my syntax wrong, or is not possible this way?
Thanks!
trigger createCaseFromChatter on FeedComment (after insert) { for(FeedComment f : trigger.new) { if(f.CommentBody.startsWith('!newCase')) { Case newCase = new Case( Subject = f.CommentBody, //Description = f.FeedItem.Body, Origin = 'Chatter', RecordtypeId = '012G0000000yArc', Status = 'Open' ); insert newCase; } } }
- akallioWiley
- March 26, 2013
- Like
- 0
- Continue reading or reply
Map Returns Null in keySet()
Hi All,
I'm having trouble debugging the following line, which is highlighted in code below:
consCourseCodeMapBig.get(Con.Id).keySet()
for some reason the first value in the set is Null, and the second value is the value I'm expecting to receive. I have confirmed this by testing in UI with the system.assert that you see in the red highlighed section. That system assert returns the following:
Error:
courseRoleTrigger: execution of AfterInsert caused by: System.AssertException: Assertion Failed: Youre here {null, a0FZ0000001sjSzMAI} Class.contactToCourseCodeHandler.saveLogic: line 83, column 1 Class.contactToCourseCodeHandler.newCourseRoleHandler: line 10, column 1 Trigger.courseRoleTrigger: line 20, column 1
I didn't even think it was possible to have a null value in a keySet, and not sure where in my code it would be happening. The section highlighted in blue is where the map is being built. I have used system.asserts there,too and do not find null value there.
Thanks for any help!
public with sharing class contactToCourseCodeHandler { public static void newCourseRoleHandler(Set<Id> newCRs) { Map<Id,Map<Id,courseCodeWrapper>> contactToCourseCodeBig = createBigCCWMap(newCRS, 'cRole'); Map<Id,courseCodeWrapper> contactToCourseCodeLittle = createLittleCCWMap(newCRS, 'cRole'); if(!contactToCourseCodeBig.isEmpty()) { String reqType = 'Insert/Update'; String source = 'Course'; saveLogic(contactToCourseCodeBig,contactToCourseCodeLittle, reqType, source); } } public static void deletedCourseRoleHandler(Set<Id> deletedCRs) { map<Id,Map<Id,courseCodeWrapper>> contactToCourseCodeBig = createBigCCWMap(deletedCRs, 'cRole'); map<Id,courseCodeWrapper> contactToCourseCodeLittle = createLittleCCWMap(deletedCRs, 'cRole'); if(!contactToCourseCodeBig.isEmpty()) { String reqType = 'Delete'; String source = 'Course'; saveLogic(contactToCourseCodeBig,contactToCourseCodeLittle, reqType, source); } } public static void updatedCourseRoleHandler() { } public static void evalItemHandler(Set<Id> evalItems) { map<Id,Map<Id,courseCodeWrapper>> contactToCourseCodeBig = createBigCCWMap(evalItems, 'eval'); map<Id,courseCodeWrapper> contactToCourseCodeLittle = createLittleCCWMap(evalItems, 'eval'); if(!contactToCourseCodeBig.isEmpty()) { String reqType = 'Insert/Update'; String source = 'Eval'; saveLogic(contactToCourseCodeBig,contactToCourseCodeLittle, reqType, source); } } public static void deletedEvalItemHandler(Set<Id> deletedEvalItems) { map<Id,Map<Id,courseCodeWrapper>> contactToCourseCodeBig = createBigCCWMap(deletedEvalItems, 'eval'); map<Id,courseCodeWrapper> contactToCourseCodeLittle = createLittleCCWMap(deletedEvalItems, 'eval'); if(!contactToCourseCodeBig.isEmpty()) { String reqType = 'Delete'; String source = 'Eval'; saveLogic(contactToCourseCodeBig,contactToCourseCodeLittle, reqType, source); } } public static void deletedEvalHandler(Set<Id> evals) { Set<Id> evalItems = new Set<Id>(); for(Comp_Item__c ei : [select ID from Comp_Item__c where Comp__c IN :evals]) { evalItems.add(ei.Id); } map<Id,Map<Id,courseCodeWrapper>> contactToCourseCodeBig = createBigCCWMap(evalItems, 'eval'); map<Id,courseCodeWrapper> contactToCourseCodeLittle = createLittleCCWMap(evalItems, 'eval'); if(!contactToCourseCodeBig.isEmpty()) { String reqType = 'Delete'; String source = 'Eval'; saveLogic(contactToCourseCodeBig,contactToCourseCodeLittle, reqType, source); } } public static void saveLogic(Map<Id,Map<Id,courseCodeWrapper>> consCourseCodeMapBig, Map<Id,courseCodeWrapper> consCourseCodeMapLittle, String triggerType, String source) { List<Contact_Course_Code__c> ccdUpsert = new List<Contact_Course_Code__c>(); List<Contact_Course_Code__c> ccdDelete = new List<Contact_Course_Code__c>(); if(triggerType == 'Insert/Update') { for(Contact Con : [Select Id, Course_Code_Count__c, (Select Id, Contact__c, Course_Code__c, CourseRoleCount__c, EvalCount__c from Contact_Course_Code__r) from Contact where Id IN :consCourseCodeMapBig.keySet()]) { if(Con.Course_Code_Count__c == 0) { for(Id cccId : consCourseCodeMapBig.get(Con.Id).keySet()) { system.assert(false,'Youre here '+consCourseCodeMapBig.get(Con.Id).keySet()); Contact_Course_Code__c newCCC = new Contact_Course_Code__c( Contact__c = Con.Id, Course_Code__c = cccId, CourseRoleCount__c = source == 'Course' ? consCourseCodeMapLittle.get(Con.Id).theCount : 0, EvalCount__c = source == 'Eval' ? consCourseCodeMapLittle.get(Con.Id).theCount : 0 ); ccdUpsert.add(newCCC); } }else{ for(Contact_Course_Code__c existingCCC : Con.Contact_Course_Code__r) { if(consCourseCodeMapBig.get(Con.Id).containsKey(existingCCC.Course_Code__c)) { existingCCC.CourseRoleCount__c += source == 'Course' ? consCourseCodeMapBig.get(Con.Id).get(existingCCC.Course_Code__c).theCount : 0; existingCCC.EvalCount__c += source == 'Eval' ? consCourseCodeMapBig.get(Con.Id).get(existingCCC.Course_Code__c).theCount : 0; ccdUpsert.add(existingCCC); } } } } } if(null != ccdUpsert) { upsert ccdUpsert; } /*if(triggerType == 'Delete') { for(Contact con : [Select Id,Name, Course_Code_Count__c, (Select Id, Contact__c, Course_Code__c, CourseRoleCount__c, Current__c, Primary__c,Total_Association_Count__c,EvalCount__c from Contact_Course_Code__r) from Contact where Id IN: consCourseCodeMapBig.keySet()]) { if(con.Course_Code_Count__c > 0) { for(courseCodeWrapper cdWrap : consCourseCodeMap.get(con.Id) ) { for(Contact_Course_Code__c existingCCC1 : Con.Contact_Course_Code__r) { if(conCourseCodeMapBig.get(Con.Id).containsKey(existingCCC1.Course_Code__c)) { if(existingCCC1.Total_Association_Count__c > 1) { existingCCC1.CourseRoleCount__c -= source == 'Course' ? conCourseCodeMapBig.get(Con.Id).get(existingCCC1.Course_Code__c).theCount : 0; existingCCC1.EvalCount__c -= source == 'Eval' ? conCourseCodeMapBig.get(Con.Id).get(existingCCC1.Course_Code__c).the : 0; ccdUpsert.add(existingCCC1); }else{ ccdDelete.add(existingCCC1); } } } } if(ccdUpdate.size() > 0) { update conCourseCodesUpdate.values(); } if(ccdDelete.size() > 0) { delete conCourseCodesDel.values(); } } } } */ } //uses the triggered CourseRoles to map the Contact Id to CourseCodes...course codes in wrapper class. public static Map<Id,Map<Id,courseCodeWrapper>> createBigCCWMap(Set<Id> IDs, String source) { Map<Id,Map<Id,courseCodeWrapper>> bigMap = new Map<Id,Map<Id,courseCodeWrapper>>(); Map<Id,courseCodeWrapper> littleMap = new Map<Id,courseCodeWrapper>(); if(source == 'cRole') { for(aggregateResult cr1 : [select Contact__c, Course__r.ACE_Code_4__c, Count(Id) from Course_Role__c where Id IN: IDs AND Course__r.ACE_Code_4__c != null AND Contact__c != null Group By Rollup (Contact__c,Course__r.ACE_Code_4__c)]) { courseCodeWrapper wrappedCourse = new courseCodeWrapper(String.valueOf(cr1.get('Contact__c')),String.valueOf(cr1.get('ACE_Code_4__c')),Integer.valueOf(cr1.get('expr0')),source); littleMap.put(wrappedCourse.courseCodeId,wrappedCourse); bigMap.put(String.valueOf(cr1.get('Contact__c')),littleMap); } } else { for(aggregateResult ei : [select Contact__c,Product__r.ACE_Code_4__c, Count(Id) from Comp_Item__c where Id IN: Ids AND Product__r.ACE_Code_4__c != null and Contact__c != null Group By Rollup (Contact__c,Product__r.ACE_Code_4__c)]) { courseCodeWrapper wrappedEval = new courseCodeWrapper(String.valueOf(ei.get('Contact__c')), String.valueOf(ei.get('ACE_Code_4__c')), Integer.valueOf(ei.get('expr0')),source); littleMap.put(wrappedEval.courseCodeId,wrappedEval); bigMap.put(String.valueOf(ei.get('Contact__c')),littleMap); } } return bigMap; } public static Map<Id,courseCodeWrapper> createLittleCCWMap(Set<Id> IDs, String source) { Map<Id,courseCodeWrapper> littleMap = new Map<Id,courseCodeWrapper>(); if(source == 'cRole') { for(aggregateResult cr1 : [select Contact__c, Course__r.ACE_Code_4__c, Count(Id) from Course_Role__c where Id IN: IDs AND Course__r.ACE_Code_4__c != null AND Contact__c != null Group By Rollup (Contact__c,Course__r.ACE_Code_4__c)]) { courseCodeWrapper wrappedCourse = new courseCodeWrapper(String.valueOf(cr1.get('Contact__c')),String.valueOf(cr1.get('ACE_Code_4__c')),Integer.valueOf(cr1.get('expr0')),source); littleMap.put(String.valueOf(cr1.get('Contact__c')),wrappedCourse); } } else { for(aggregateResult ei : [select Contact__c,Product__r.ACE_Code_4__c, Count(Id) from Comp_Item__c where Id IN: Ids AND Product__r.ACE_Code_4__c != null and Contact__c != null Group By Rollup (Contact__c,Product__r.ACE_Code_4__c)]) { courseCodeWrapper wrappedEval = new courseCodeWrapper(String.valueOf(ei.get('Contact__c')), String.valueOf(ei.get('ACE_Code_4__c')), Integer.valueOf(ei.get('expr0')),source); littleMap.put(String.valueOf(ei.get('Contact__c')),wrappedEval); } } return littleMap; } public class courseCodeWrapper { public Id contactId {get; set;} public Id courseCodeId {get; set;} public Integer theCount {get; set;} public String source {get; set;} public courseCodeWrapper(Id conId, Id ccId, Integer elCount, String wCDSource ) { contactId = conId; courseCodeId = ccId; theCount = elCount; source = wCDSource; } } }
- akallioWiley
- February 28, 2013
- Like
- 0
- Continue reading or reply
Help with null pointer exception
The method below fails and throws a null pointer exception on the highlighted and only on the highlighted line, which is strange because the highlighted is nearly exactly the same as a line above it that is in a different if/else branch. The other thing that has me scratching my head is that the system.assert(also highlighted) shows me that the variable called 'source' is not null and has the expected value. So, can anyone spot why I might be getting this error?
Thanks!
public static void saveLogic(Map<Id,List<courseCodeWrapper>> consCourseCodeMap, String triggerType, String source) { if(triggerType == 'Insert/Update') { List<Contact_Course_Code__c> conCourseCodes = new List<Contact_Course_Code__c>(); for(Contact con : [Select Id,Name, Course_Code_Count__c, (Select Id, Contact__c, Course_Code__c, CourseRoleCount__c, Current__c, Primary__c, EvalCount__c from Contact_Course_Code__r) from Contact where Id IN: consCourseCodeMap.keySet()]) { if(con.Course_Code_Count__c == 0) { for(courseCodeWrapper cc : consCourseCodeMap.get(con.Id)) { //Integer currentCount = cc.currentCheck ? 1 : 0; //Integer primaryCount = cc.PrimaryCheck ? 1 : 0; Contact_Course_Code__c newCCC = new Contact_Course_Code__c( Contact__c = con.Id, Course_Code__c = cc.courseCodeId, CourseRoleCount__c = source == 'Course' ? 1 : 0, EvalCount__c = source == 'Eval' ? 1 : 0 //Current__c = currentCount, //Primary__c = primaryCount ); conCourseCodes.add(newCCC); } insert conCourseCodes; } else if(con.Course_Code_Count__c > 0) { for(courseCodeWrapper cdWrap : consCourseCodeMap.get(con.Id) ) { //Integer currentCounter = cdWrap.currentCheck ? 1 : 0; //Integer primaryCounter = cdWrap.primaryCheck ? 1 : 0; for(Contact_Course_Code__c conCD : con.Contact_Course_Code__r) { if(conCD.Course_Code__c == cdWrap.CourseCodeId) { conCD.CourseRoleCount__c += source == 'Course' ? 1 : 0; conCD.EvalCount__c += source == 'Eval' ? 1 : 0; //conCD.Current__c += currentCounter; //conCD.Primary__c += primaryCounter; conCourseCodes.add(conCD); } } } update conCourseCodes; } } } if(triggerType == 'Delete') { List<Contact_Course_Code__c> conCourseCodesUpdate = new List<Contact_Course_Code__c>(); List<Contact_Course_Code__c> conCourseCodesDel = new List<Contact_Course_Code__c>(); for(Contact con : [Select Id,Name, Course_Code_Count__c, (Select Id, Contact__c, Course_Code__c, CourseRoleCount__c, Current__c, Primary__c,Total_Association_Count__c from Contact_Course_Code__r) from Contact where Id IN: consCourseCodeMap.keySet()]) { if(con.Course_Code_Count__c > 0) { for(courseCodeWrapper cdWrap : consCourseCodeMap.get(con.Id) ) { //Integer currentCounter = cdWrap.currentCheck ? 1 : 0; //Integer primaryCounter = cdWrap.primaryCheck ? 1 : 0; for(Contact_Course_Code__c conCD : con.Contact_Course_Code__r) { if(conCD.Course_Code__c == cdWrap.CourseCodeId) { if(conCD.Total_Association_Count__c > 1) { conCD.CourseRoleCount__c -= source == 'Course' ? 1 : 0; //system.assert(false, 'This is your SOURCE: '+source); conCD.EvalCount__c -= source == 'Eval' ? 1 : 0; //conCD.Current__c += currentCounter; //conCD.Primary__c += primaryCounter; conCourseCodesUpdate.add(conCD); }else{ conCourseCodesDEL.add(conCD); } } } } if(conCourseCodesUpdate.size() > 0) { update conCourseCodesUpdate; } if(conCourseCodesDel.size() > 0) { delete conCourseCodesDel; } } } } }
- akallioWiley
- February 19, 2013
- Like
- 0
- Continue reading or reply
Use an operator inside a Ternary Opeartor?
I am trying to increment a field based on if/else logic. I'm just starting to get the hang of the ternary operator. So, I wrote the following, but it won't compile. Does anybody know if it's possible to do this, or does it have to go in an if else statement?
conCD.CourseRoleCount__c = source == 'Course' ? +=1 : 0;
- akallioWiley
- February 19, 2013
- Like
- 0
- Continue reading or reply
Help with Null Pointer Exception. SOSL in VF page
I am trying to use a SOSL query where the criteria will be input from a text box on a VF page. I am running into a null pointer exception and struggling to figure out what it is. It is my first time using SOSL. So, I'm hoping the issue will be easy to spot.
public with sharing class mergeMaster { public string searchString {get; set;} public List<resultWrapper> wrappedResults {get; set;} //fired when the Search button is clicked public PageReference search() { List<List<SObject>> searchList = [FIND :searchString IN ALL FIELDS RETURNING CONTACT (Id, Name, Account.Name Order By Name) ]; for(Contact reCon : (List<Contact>) searchList[0]) { resultWrapper wrCon = new resultWrapper(reCon.Id, reCon.Name, reCon.Account.Name); //system.assert(false,'Results: '+wrCon); wrappedResults.add(wrCon); } return null; } public class resultWrapper { public Id contactID {get; set;} public String contactName {get; set;} public String accountName {get; set;} public List<SelectOption> masterORchild {get; set;} public resultWrapper(ID cID, String cName, String aName) { contactID = cID; contactName = cName; accountName = aName; this.masterORchild = new List<SelectOption>{new SelectOption('The Master','The Master'),new SelectOption('Merge','Merge')}; } } }
<apex:page sidebar="false" controller="mergeMaster" standardstylesheets="false"> <apex:sectionheader title="Merge Master" /> <apex:form id="theform"> <apex:pageBlock mode="edit" id="block"> <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:panelGroup > <apex:inputText id="searchString" value="{!searchString}"/> <apex:commandButton value="Search" action="{!search}" rerender="block" status="status"/> </apex:panelGroup> </apex:pageBlockSectionItem> </apex:pageBlockSection><br/> <apex:actionStatus id="status" startText="Searching... please wait..."/> <apex:pageBlockSection > <apex:pageBlockSection title="Search Results" id="resultsBlock" columns="1"> <apex:pageBlockTable value="{!wrappedResults}" var="item" rendered="{!NOT(ISNULL(wrappedResults))}"> <apex:column value="{!item.contactName}" headerValue="Contact" width="100"/> <apex:column: value="{!item.accountName}" headerValue="Account" width="200"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
- akallioWiley
- November 26, 2012
- Like
- 0
- Continue reading or reply
SOQL Query works in after update, but not after delete
The class posted below is fed a set of Contact Ids that comes from a trigger on the Task object. We use particular Task record type to track what we call 'Market Development'. A Market Development task contributes towards a total Market Development score for the contact. Therefore we have this class which will add or subtract MD points for a Contact as MD tasks are added or deleted.
My issue is that Total Points are not being subtracted when an MD task is deleted. As I said the class receives a set of contact ids and processes MD points from there by using SOQL to select the Contacts and their MD Tasks. What I have found is that, in after delete trigger context only, the SOQL query that is supposed to get the Contact fails to find the contact. And this where I get stuck. I have put comments in the code below to hopefully help you understand how I am trying to debug this.
Any thoughts on why this is happening or a different debugging technique would be great.
public class MarketDevelopmentScorecard { public static void updateMarketDevelopmentScorecard(Set<Id> contactIds) { RecordType mdRecordType = RecordTypeUtil.getRecordType('Task', 'Market Development'); if (mdRecordType != null) { Date recentActivityDate = System.today().addDays(-1095); // 3 years ago List<Task> mdTasks = [select Id, ActivityDate, MD_Activity_Type__c, WhoId from Task where WhoId in :contactIds and RecordTypeId = :mdRecordType.Id and ActivityDate >= :recentActivityDate]; Map<Id, Set<String>> contactMarketDevelopmentActivities = new Map<Id, Set<String>>(); for (Task t : mdTasks) { if (t.MD_Activity_Type__c != null && t.MD_Activity_Type__c != '') { Set<String> mdActivities = contactMarketDevelopmentActivities.get(t.WhoId); if (mdActivities == null) { mdActivities = new Set<String>(); contactMarketDevelopmentActivities.put(t.WhoId, mdActivities); } mdActivities.add(t.MD_Activity_Type__c); } } List<Market_Development_Rating__c> marketDevelopmentRatings = Market_Development_Rating__c.getAll().values(); for (Id cId : contactIds) { System.debug('JJB contactId: ' + cId); } List<Contact> contacts = [select Id, MD_Total_Points__c, MD_Activities__c from Contact where Id in :contactIds]; //this system assert shows that I am receiving a contact from the trigger, but that the SOQL query doesn't find it //system.assert(false, 'Contacts from Trigger '+contactIds.size()+'Contacts found in database '+contacts.size()); for (Contact c : contacts) { Decimal totalPoints = 0.0; String activities = ''; //in after delete context this system assert never gets hit because this for loop never starts because there is nothing in the List contacts //system.assert(false, 'hello!! '); Set<String> mdActivities = contactMarketDevelopmentActivities.get(c.Id); if (mdActivities == null) { mdActivities = new Set<String>(); } for (Market_Development_Rating__c mdr : marketDevelopmentRatings) { if (mdActivities.contains(mdr.Name)) { totalPoints += mdr.MD_Points__c; if (mdr.Contact_Field_Name__c != null && mdr.Contact_Field_Name__c != '') { c.put(mdr.Contact_Field_Name__c, mdr.MD_Points__c); //system.assert(false, 'the total points are: '+mdr.MD_Points__c); } } else { if (mdr.Contact_Field_Name__c != null && mdr.Contact_Field_Name__c != '') { c.put(mdr.Contact_Field_Name__c, 0.00); } } }
- akallioWiley
- October 26, 2012
- Like
- 0
- Continue reading or reply
Milestone PM Milestone1_Task_Trigger_Utility_Test.chatterSubscriptionLimitExceeded() Issue
Hi,
I'm getting this issue when trying to deploy a trigger for Account and Contact. I'm not sure why this is happening since I'm not touching any of the objects used by Milestone PM. Has anyone encountered this issue before? Any workaround? Thanks!
Failure Message: "System.AssertException: Assertion Failed: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Insert failed. First exception on row 6; first error: LIMIT_EXCEEDED, Maximum per user subscription limit reached.: []: []", Failure Stack Trace: "Class.Milestone1_Task_Trigger_Util...
- Upleaf
- August 22, 2012
- Like
- 0
- Continue reading or reply
Deployment error problem with Premission Set
Hi,
When im deploying one premission set with one custom app premission it is not deploying throwing error as :
# Deploy Results:
File Name: permissionsets/SSR_Holdings_Permission_Set.permissionset
Full Name: SSR_Holdings_Permission_Set
Action: NO ACTION
Result: FAILED
Problem: Unknown user permission: AllowDeleteDandBCompany
Plz Advice
- sadasiva07
- June 07, 2012
- Like
- 0
- Continue reading or reply