- BroncoBoy
- NEWBIE
- 290 Points
- Member since 2013
- Salesforce CRM Developer
- Jackson
-
ChatterFeed
-
3Best Answers
-
2Likes Received
-
0Likes Given
-
37Questions
-
45Replies
How to execute Multiple batch apex jobs in sequence
I want to understand a specific concept.
I have created 2 batch apex classes say account and contact and now I need to run contact class only after account class fully completes(without any errors of course).
I schedule account class & then contact class, so when I click setup --> jobs --> scheduled jobs, I can see both these jobs
As per documentation order of execution of jobs is not guaranteed.
so how do I make sure that contact batch job executes only successful execution of account batch job.
please be specific in replies.
sonali
- sonali verma
- October 07, 2015
- Like
- 0
- Continue reading or reply
Link from Visualforce to Salesforce App Events
Bronco
- BroncoBoy
- March 01, 2018
- Like
- 0
- Continue reading or reply
2 Quick Questions RE: Governor Limit Max # of Asynchronous Apex Method Executions
"The maximum number of asynchronous Apex method executions (batch Apex, future methods, Queueable Apex, and scheduled Apex) per a 24-hour period: 250,000 or the number of user licenses in your organization multiplied by 200, whichever is greater"
When we're talking about batch Apex, for example, are we just talking about start(), execute(), finish() methods being applied to that limit or are all methods - even custom methods - also included in that figure as well?
Also is there a way to see how close we are getting to that limit every day? I looked at the Limits class but didn't see any direct methods there. We have a couple of huge batch classes that run once a week and I want to make sure we're not getting too close to that limit.
- BroncoBoy
- December 09, 2016
- Like
- 0
- Continue reading or reply
Possible to Combine 2 Bar Charts
1. It has last 6 months on the X axis, e.g. January - June
2. It has 2 Y Axes: on the left Sales in $$, on the right Applications - both as a decimal
3. For each month you have Product A Applications bar stacked on Product A Sales bar and then Product B Applications bar stacked on Product B Sales bar.
So essentially it's like stacking/superimposing one bar chart on top of another and adding an extra y axis. Is this even possible? Thanks in advance!
Bronco
- BroncoBoy
- July 28, 2016
- Like
- 0
- Continue reading or reply
Batch Process Attempt to de-reference a null object
Code:
public Database.QueryLocator start(Database.BatchableContext BC)
{
String query = 'SELECT Id, (SELECT ContactId, IsPrimary FROM OpportunityContactRoles ORDER BY IsPrimary DESC) FROM Opportunity WHERE LastModifiedDate = LAST_N_DAYS:365';
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC, List < sObject > s)
{
List < Opportunity > oppsToUpdate = new List < Opportunity > ();
for (sObject ssss: s)
{
Opportunity o = (Opportunity) ssss;
List < OpportunityContactRole > opptys = new List < OpportunityContactRole > ();
opptys = (List < OpportunityContactRole > ) o.getsobjects('OpportunityContactRoles'); //o.getsobjects will return a List<SObject>, in the same line we cast those into List<OpportunityContactRole>
for (OpportunityContactRole optt: opptys) // HERE IS WHERE THE ERROR IS. LOOPING THROUGH SUB QUERY LIST
{
String contId = '';
contId = String.ValueOf(optt.ContactId);
if (!String.IsBlank(contId))
{
o.Primary_Contact_Id__c = contId;
oppsToUpdate.add(o);
break;
}
}
}
update oppsToUpdate;
}
- BroncoBoy
- July 20, 2016
- Like
- 0
- Continue reading or reply
SAML For Specific Users
Thanks in advance!
Bronco
- BroncoBoy
- June 30, 2016
- Like
- 0
- Continue reading or reply
Visualforce apex:param not populating
ValidateProduct is a method in my VF page extension that uses the productsToVerify property (with getters/setters) to return a boolean. Using <apex:param I'm trying to set the productsToVerify property each time the <apex:repeat iterates through a record, then execute ValidateProduct which returns boolean - thus deciding whether to render <apex:outputLink
Problem: <apex:param isn't setting the productsToVerify property...it just remains null. Thanks in advance for your help!
VF Code:
<apex:pageBlockTable value="{!JNLCampaigns}" var="junc">
<apex:column>
<apex:facet name="header">View X</apex:facet>
<apex:repeat value="{!junc.CampaignMarketingMaterials__r}" var="campMark">
<apex:outputLink rendered="false">
<apex:param name="prodsParam" value="{!campMark.MarketingMaterial__r.Product_Name__c}" assignTo="{!productsToVerify}"/>
</apex:outputLink>
<apex:outputLink rendered="{!ValidateProduct}" value="{!campMark.MarketingMaterial__r.Form_Number__c}">VIEW PREVIEW</apex:outputLink><br />
</apex:repeat>
</apex:column>
</apex:pageBlockTable>
Extension code for getValidateProduct method:
public String productsToVerify{get;set{productsToVerify=value;}
public boolean getValidateProduct()
{
system.debug(' productsToVerify ' + productsToVerify + ' ss ' + ss);
Boolean result = false;
if(!String.IsBlank(productsToVerify) && productsToVerify.contains(ss))
{
result = true;
system.debug(' result a ');
break;
}
else if(String.IsBlank(productsToVerify))
{
system.debug(' result b ');
result = true;
break;
}
return result;
}
- BroncoBoy
- June 14, 2016
- Like
- 0
- Continue reading or reply
Visualforce Chart apex:barSeries, Currency
Right now the left axis is displaying several #'s, for example: 10000. I would prefer 10,000 or, even better, $10,000.
The source data is coming from a number type field from a custom object. I'm also wondering if I convert the field to type: currency if that would help?
Thanks in advance!
Bronco
- BroncoBoy
- May 18, 2016
- Like
- 0
- Continue reading or reply
Opportunities Aggregate Query Group By RecordType & ContactId
Query: SELECT COUNT(Id) idSum, SUM(Consolidated_Opportunities_Count__c) consolidatedSum FROM Opportunity WHERE CreatedDate = LAST_MONTH AND (RecordType.Name = 'A' OR RecordType.Name = 'B' OR RecordType.Name = 'C') GROUP BY ContactId, RecordTypeId
Thanks fo your help!
Bronco
- BroncoBoy
- April 26, 2016
- Like
- 0
- Continue reading or reply
SOQL: Trying to dynamically change the month filter for a query
SELECT Summary_Id__c, SUM(EA_App_Count__c) appCount FROM CustomObject__c WHERE Full_Date__c = THIS_MONTH GROUP BY Summary_Id__c';
Here's what I'm trying to do:
Trying to run this SOQL 6 separate times, based on the current month, once per month for the previous 6 months date range. So, in essence, after each run, the filter date range would dynamically change look something like:
- WHERE Full_Date__c = THIS_MONTH -1 //Previous month
- WHERE Full_Date__c = THIS_MONTH - 2 //2 months ago
- WHERE Full_Date__c = THIS_MONTH - 3 //3 months ago
- WHERE Full_Date__c = THIS_MONTH - 4 //4 months ago
- WHERE Full_Date__c = THIS_MONTH - 5 //5 months ago
- WHERE Full_Date__c = THIS_MONTH - 6 //6 months ago
Thanks in advance for any help you can offer!
-Bronco
- BroncoBoy
- April 20, 2016
- Like
- 0
- Continue reading or reply
Error: Cannot modify a collection while it is being iterated.
Not sure why I'm getting this error as I'm out of the for loop when I'm trying to re-order the collection. Any help is appreciated!
-Bronco
CODE:
for (sObject s : scope)
{
User evtOwner = (User)s;
Id evtOwnerId = evtOwner.Id;
if(ownrIdsToEvents.containsKey(evtOwnerId))
{
List <Event> evtsToReorder = new Event[ownrIdsToEvents.get(evtOwnerId).size()];
evtsToReorder = ownrIdsToEvents.get(evtOwnerId);
Boolean userHasAllDayEvent = false;
Boolean reOrderList = false;
Event allDayEvent;
Event zoneRotationEvent;
for(Event ee: ownrIdsToEvents.get(evtOwnerId))//loop through each owners events
{
if (ee.IsAllDayEvent && ee.RecordType.Name != 'Zone Rotation')
{
userHasAllDayEvent = true;
allDayEvent = ee;
}
if(ee.RecordType.Name == 'Zone Rotation' && userHasAllDayEvent)
{
reOrderList = true;
zoneRotationEvent = ee;
Event zoneRotationEventToMove = ee;
break;
}
}
if(reOrderList && userHasAllDayEvent && evtsToReorder.size() > 1)
{
evtsToReorder.set(0, zoneRotationEvent);
evtsToReorder.remove(1);
evtsToReorder.add(1, allDayEvent);
}
}
}
- BroncoBoy
- December 07, 2015
- Like
- 0
- Continue reading or reply
Building a map of lists, error accessing subquery field values. Error: Invalid aggregate relationship
Create a map of lists (contactIdsToOpportunities) which maps a contact id to the list of opportunities that contact is associated with within the OpportunityContactRole object - all based on a limited # of contact id's, only opportunities within the last 30 days.
As I'm trying to access the subquery field values to build my map of lists, its generating the following error:
Invalid aggregate relationship OpportunityContactRole for Opportunity
I'm trying to use this approach: http://www.infallibletechie.com/2012/04/how-to-get-subquery-field-value-using.html
I'm grateful for any help, so thanks in advance!
-Bronco
CODE:
set <Id> evtsContactIds = new set <Id>{'0035000000yim1c’,’0035000000cin2f’};//insert contacts id's here
map <Id, List <Opportunity>> contactIdsToOpportunities = new Map <Id, List <Opportunity>>();
for (Opportunity o: [SELECT Id, CloseDate, Description, Name, (SELECT ContactId FROM OpportunityContactRoles WHERE ContactId IN: evtsContactIds) FROM Opportunity WHERE CloseDate >= LAST_N_DAYS: 30 AND Id IN(SELECT OpportunityId FROM OpportunityContactRole WHERE ContactId IN: evtsContactIds) ORDER BY CloseDate DESC])
{
List < OpportunityContactRole > opptys = new List < OpportunityContactRole > ();
opptys = o.getSObjects('OpportunityContactRole'); //very rarely used method, but this gets the records from the subquery,
Id oppContId;
for (OpportunityContactRole opt: opptys)
{
oppContId = opt.ContactId;
if (contactIdsToOpportunities.containsKey(oppContId))
{
List < Opportunity > contactsOpportunities = contactIdsToOpportunities.get(oppContId);
if (contactsOpportunities.size() <= 3) //this is what determines that the code will only return the latest 3 opportunities
{
contactsOpportunities.add(o);
contactIdsToOpportunities.put(oppContId, contactsOpportunities);
}
}
else
{
contactIdsToOpportunities.put(oppContId, new List <Opportunity>{o});
}
}
}
- BroncoBoy
- December 01, 2015
- Like
- 0
- Continue reading or reply
Task Trigger: Reset Checkboxes to Unchecked, Retain Checkbox Values
Code:
trigger EmailTaskDescription on Task(before insert, after insert, before update, after update)
{
Boolean nofityRIW = false;
Boolean nofityREW = false;
Boolean nofityBDC = false;
Boolean nofityGIW = false;
Boolean nofityGEW = false;
if (trigger.isBefore)
{
Task tt = Trigger.new[0];
//capture checkbox selections
nofityRIW = tt.Notify_R_IW__c;
nofityREW = tt.Notify_R_EW__c;
nofityBDC = tt.Notify_BDC__c;
nofityGIW = tt.Notify_G_IW__c;
nofityGEW = tt.Notify_G_EW__c;
//reset checkbox selections to unchecked
tt.Notify_R_IW__c = false;
tt.Notify_R_EW__c = false;
tt.Notify_BDC__c = false;
tt.Notify_G_EW__c = false;
tt.Notify_G_IW__c = false;
}
if (trigger.isAfter)
{
//use initial values to execute logic
if (nofityRIW)
{
}
else if (nofityREW)
{
}
}
}
- BroncoBoy
- October 07, 2015
- Like
- 0
- Continue reading or reply
Executing method within a Visualforce extension using Javascript on a Visualforce page
Because of this, I can't use Javascript remoting nor can I use the AJAX toolkit/sforce.apex.execute method because both require static keywords and the instance variables are not visible to static methods. I'm greatful for any advice.
FYI The JSON string is used to populate a Datatables (https://datatables.net/" target="_blank) table on the VF page.
- BroncoBoy
- September 09, 2015
- Like
- 0
- Continue reading or reply
Repeat function to fill a list collection until collection size reaches 100 records
CODE:
public String TopOneHundred()
{
List < sObject > bd = StdSetControllerBD.getRecords();
List < Contact > contactsListB = retrieveTopOneHundred(bd);
if (contactsListB.size() < 100)
{
StdSetControllerBD.next(); //if we have less than 100 contact records then we will go get more by repeating the process, this time with the next set of bd records in the StdSetControllerBD
List < BD__c > nextRoundOfBdRecords = new List < BD__c > ();
for (sObject sob: StdSetControllerBD.getRecords())
{
BD__c sobd = (BD__c) sob;
nextRoundOfBdRecords.Add(sobd);
}
contactsListB.addAll(retrieveTopOneHundred(nextRoundOfBdRecords));
if (contactsListB.size() < 100)
{
StdSetControllerBD.next(); //if we have less than 100 contact records then we will go get more by repeating the process, this time with the next set of bd records in the StdSetControllerBD
List < BD__c > thirdRoundOfBdRecords = new List < BD__c > ();
for (sObject sob: StdSetControllerBD.getRecords())
{
BD__c sobdd = (BD__c) sob;
thirdRoundOfBdRecords.Add(sobdd);
}
contactsListB.addAll(retrieveTopOneHundred(nextRoundOfBdRecords));
}
}
String contactsJSON = JSON.serializePretty(contactsListB);
return contactsJSON;
}
- BroncoBoy
- September 03, 2015
- Like
- 0
- Continue reading or reply
Returning a List of Contacts based on info from 2 other related objects
Background: The Account object is related to two other objects Contact (lookup, 1 Account can have many Contacts) and I have another object, a custom object, BD__c, with a master detail relationship to the Account object (1 Account can have many BD__c's).
To start with, I return a list of these BD__c and I want to order them by Opportunity_Amount__c (descending):
BD__c record #1 Opportunity_Amount__c = $100,000.
BD__c record #2 Opportunity_Amount__c = $50,000.
BD__c record #3 Opportunity_Amount__c = $20,000.
BD__c record #4 Opportunity_Amount__c = $0.
Problem to solve: Since each BD__c is associated to an Account I want the contacts from the associated account from BD record #1, record #2, record #3 (and so forth) until the total # of contacts reaches 100. In other words I want the first 100 contacts associated with accounts related to the BD__c records who have the highest Opportunity_Amount__c.
So far the code I have is:
Set<Id> setOfBDIds = new Set<Id>();
for (BD__c bbb : [SELECT b.Account__r.Id FROM BD__c WHERE Opportunity_Amount__c > 0 ORDER BY Opportunity_Amount__c DESC])
{
setOfBDIds.add(bbb.Account__r.Id);
}
List<Contacts> contacts = [SELECT AccountId, Name FROM Contact WHERE AccountId IN =: setOfBDIds LIMIT 100];
The problem is that, with this structure, the contacts in the list won't necessarily be from the BD__c/Accounts who have the highest Opportunity_Amount__c - they can be from any account.
I thought about trying this using SOQL but according to this: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_query_limits.htm (https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_query_limits.htm" target="_blank)
"In each specified relationship, only one level of parent-to-child relationship can be specified in a query"
Any thoughts on how this can be acheived?
Thanks in advance!
- BroncoBoy
- June 10, 2015
- Like
- 0
- Continue reading or reply
Best Practices & Efficiency Retrieving Data from Map or Lists
In my view C) works but only if the SOQL returns records, otherwise you get a 'now rows returned' error. A) A works but again will return a "list out of bounds error if the SOQL returns 0 records B) seems the best to me because if there is no key it simply returns null...but I'd like to hear your opinions.
So, which approach is the more efficient - which one is the best practice below, A, B or C (or Other) - is B the best?
A)
list<User> jnldGenericId = [SELECT Id FROM User WHERE Name = '1' LIMIT 1];
list<User> rbdGenericId = [SELECT Id FROM User WHERE Name = '2' LIMIT 1];
list<User> imgGenericId = [SELECT Id FROM User WHERE Name = '3' LIMIT 1];
list<User> cclGenericId = [SELECT Id FROM User WHERE Name = '4' LIMIT 1];
Id Owner1 = rbdGenericId[0].Id;
Id Owner2 = imgGenericId[0].Id;
Id Owner3 = cclGenericId[0].Id;
Id Owner4 = jnldGenericId[0].Id;
OR
B)
map<String, Id> userNameIdMap = new map<String, Id>();
for(user u : [SELECT Id FROM User WHERE Name = '1' OR Name = '2' OR Name = '3' OR Name = '4'])
{
userNameIdMap.put(u.Name, u.Id);
}
Id Owner1 = userNameIdMap.get('1');
Id Owner2= userNameIdMap.get('2');
Id Owner3 = userNameIdMap.get('3');
Id Owner4= userNameIdMap.get('4');
OR
C)
Id Owner1= [SELECT Id FROM User WHERE Name = '1' LIMIT 1].Id;
Id Owner2 = [SELECT Id FROM User WHERE Name = '2' LIMIT 1].Id;
Id Owner3 = [SELECT Id FROM User WHERE Name = '3' LIMIT 1].Id;
Id Owner4 = [SELECT Id FROM User WHERE Name = '4' LIMIT 1].Id;
- BroncoBoy
- April 08, 2015
- Like
- 0
- Continue reading or reply
Need Help Generating a Map Of Lists
Example of desired effect:
public map <String, list <String>> MyMap = new map <String, list <String>>
{
'FSID1234' => new list<String> {'a0yW0000000zC177', 'a0yW0000000zC178', 'a0yW0000000zC179'},
'FSID5678' => new list<String> {'a0yW0000000zC187', 'a0yW0000000zC188', 'a0yW0000000zC189'},,
'FSID5678' => new list<String> {'a0yW0000000zC197', 'a0yW0000000zC198', 'a0yW0000000zC199'},
};
Referernce:
http://www.davehelgerson.com/?p=379
- BroncoBoy
- November 19, 2014
- Like
- 0
- Continue reading or reply
Handling Errors When Inserting/Updating a <List> of Objects/Records
Scenario:
In this example (not a batch process) I have a list of 100 contact records: List <Contact> contactsToUpdate = new List <Contact> ();
// contactsToUpdate.size() = 100
I loop through these using a for loop, I update a few records. Then I upsert them using DML. Result: a few records have been updated and a few are new & are inserted.
if (contactsToUpdate.size() > 0)
{
try
{
upsert contactsToUpdate;
}
catch(DmlException e)
{
system.debug('The following exception has occurred: ' + e.getMessage());
}
}
Here are my questions:
1) If only 1 of those 100 records cannot be inserted do to something like a validation rule failing, will the entire insert fail or just the one record?
2) Is there a way in the Catch that I could email myself only the records that fail and the reason - can I use the database.upsert in a try catch?
Thank you!
Brandon
- BroncoBoy
- November 18, 2014
- Like
- 0
- Continue reading or reply
How to write tests for if statements in my test class
Code"
@RemoteAction
global static list <Marketing_Material__c> retrieveAllMaterialsList(String userDivision)
{
List<String> imgAudience = new List<String> {'AMC', 'WMC'};
List<String> jnldAudience = new List<String> {'AMC', 'WMC'};
List<String> jnlAudience = new List<String> {'AMC', 'WMC'};
List<String> jnldgAudience = new List<String> {'AMC', 'WMC'};
List<String> rbdAudience = new List<String> {'AMC', 'WMC'};
List<String> cclAudience = new List<String> {'CURIAN', 'CURIAN RIA', 'CURIAN SELECT'};
List<String> siiAudience = new List<String> {'NPH'};
List<String> npcAudience = new List<String> {'NPH'};
List<String> icaAudience = new List<String> {'NPH'};
List<String> investAudience = new List<String> {'NPH'};
List<String> wAudience = new List<String> {'NPH'};
Map<String, List<String>> audienceMap = new Map<String, List<String>>();
audienceMap.put('IMG', imgAudience);
audienceMap.put('JNLD', jnldAudience);
audienceMap.put('JNL', jnlAudience);
audienceMap.put('JNLDG', jnldgAudience);
audienceMap.put('RBD', rbdAudience);
audienceMap.put('CCL', cclAudience);
audienceMap.put('SII', siiAudience);
audienceMap.put('NPC', npcAudience);
audienceMap.put('ICA', icaAudience);
audienceMap.put('INVEST', investAudience);
audienceMap.put('W1', wAudience);
List <String> finalAudienceListB = new List <String> (audienceMap.get(userDivision)); //e.g. 'WMC, AMC'
audienceMap.clear();
Map <Id, Marketing_Material__c> materialListC = new Map <Id, Marketing_Material__c> ();
List <Marketing_Material__c> finalMaterialList = new List <Marketing_Material__c> ();
try
{
for (Marketing_Material__c mmmm: [SELECT Name, Marketing_Material_Name__c, Form_Number__c, PieceLink__c, PictureLink__c, Approved_Firms__c, Not_Approved_Firms__c, Approved_States__c, Not_Approved_States__c, Item_Cost__c, Audience__c, Product_Line__c, Audience_Groups_Multi_picklist__c, IsObsoleted__c FROM Marketing_Material__c WHERE IsObsoleted__c = false AND(Viewabillity__c = 'Viewable And Orderable' OR Viewabillity__c = 'Viewable Not Orderable')])
{
String audC = mmmm.Audience_Groups_Multi_picklist__c; //e.g. 'WMC, AMC, SSU'
if (!String.isBlank(audC))
{
Integer audienceMatchesC = 0;
for (String tt: finalAudienceListB)
{
//you're finding a matching in the Audience_Groups_Multi_picklist__c(aud) with each item the user is qualified to see based on the user division in the
//above hard-coded map.
audienceMatchesC = audienceMatchesC + audC.countMatches(tt);
}
if (audienceMatchesC > 0) //if there's a match then we're good to return the record for the user to see
{
materialListC.put(mmmm.Id, mmmm); //we add to a map which, by default, prevents duplicates from being added;
}
}
}
finalMaterialList = materialListC.values();
}
catch (Exception e)
{
ApexPages.addMessages(e);
}
return finalMaterialList;
}
- BroncoBoy
- October 06, 2014
- Like
- 0
- Continue reading or reply
Struggling Writing a Bulk Safe Event Trigger
Here's my code:
trigger UpdateEventDescription on Event (before insert, before update)
{
Map<Id, User> usersMap = new Map<Id, User>([SELECT Cost_Center__c FROM User WHERE IsActive = true]);
private String iwEmailAddress;
private String bdcEmailAddress;
if (trigger.isInsert)
{
for (Event e: Trigger.new)
{
String descrip = e.Description;
String ownCC = usersMap.get(e.OwnerId).Cost_Center__c;
if(e.Email_Description_to_BDC__c || e.Email_Description_to_IW__c)//if either checkbox (Email_Description_to_BDC__c or e.Email_Description_to_IW__c) is are checked, proceed
{
if(e.Email_Description_to_BDC__c && ownCC != '' && ownCC != null)
{
//Retrieve the BDC-users email address based on the event-owner's cost center
bdcEmailAddress = [SELECT Cost_Center__c, Email FROM User WHERE Cost_Center__c =:ownCC AND (ProfileId = '1234' OR ProfileId = '1234') LIMIT 1].Email; //is there a way to removed this from the for loop so that I can avoid the too many queries error?
}
if(e.Email_Description_to_IW__c && ownCC != '' && ownCC != null)
{
//Retrieve the IW-users email address based on the event-owner's cost center
iwEmailAddress = [SELECT Cost_Center__c, Email FROM User WHERE Cost_Center__c =:ownCC AND (ProfileId = '5678' OR ProfileId = '8940') LIMIT 1].Email;
}
//Will add code here to update the description
}
}
}
}
- BroncoBoy
- September 04, 2014
- Like
- 0
- Continue reading or reply
Visualforce Save and Close: Saves But Doesn't Close
- http://raydehler.com/cloud/clod/visualforce-perform-action-then-close-window.html
- https://developer.salesforce.com/forums/ForumsMain?id=906F000000095V9IAI
Code:
<apex:outputPanel id="outBottom">
<apex:commandButton oncomplete="window.close();" action="{!createTask}" value="Save Task" status="closer" rerender="outBottom"/>
<apex:actionStatus startText="(Saving...)" stopText="" onstop="window.close(); return false;" id="closer"/>
</apex:outputPanel>
Has anyone found a solution to this or is there an error in my code? Thank you in advance!
- BroncoBoy
- February 05, 2014
- Like
- 1
- Continue reading or reply
Question Regarding Casting Within Batch Apex
I am new to apex programming and have been asked to look into an issue within a batch apex class created by an senior apex developer (s.a.d.).
The setup:
My understanding of the execute method used with batch apex is that this method takes 2 things:
-A reference to the Database.BatchableContext object.
-A list of sObjects, such as List<sObject>, which is passed to the method for each batch of records
You can see both being passed into the s.a.d.'s code below:
The code:
global void execute(Database.BatchableContext BC, List<sObject> scope)
{
Set<String> branchZips = new Set<String>();
Set<Id> branchPIds = new Set<Id>();
// First, we collect all the unique zips from the branches into a set.
for (sObject s : scope) {
Account a = (Account)s;
if (a.Branch_Office_Zip_Code__c != null && a.Branch_Office_Zip_Code__c.length() == 5) {
branchZips.add(a.Branch_Office_Zip_Code__c);
branchPIds.add(a.ParentId);
}
}
My question:
Regarding list of sObjects (List<sObject> scope) being passed to the method I'm simply trying to understand what the developer is doing within the code. My question: Does it appear to you that the developer was passing list of sObjects in a variable "scope", taking each record from the "scope", storing it in an sObject "s" and then casting that "s" sObject into an account object "a" with this code: Account a = (Account)s? If so, I've been trying to find information regarding this casting "technique" and why it's used and, more importantly, other examples. This whole topic of casting appears to be widly used not just in apex programming but in other programming like java, and I would like to understand it better. I have been unable to find resources that clearly explain what it is and why you would do it and examples. Thanks in advance!
- BroncoBoy
- April 19, 2013
- Like
- 1
- Continue reading or reply
2 Quick Questions RE: Governor Limit Max # of Asynchronous Apex Method Executions
"The maximum number of asynchronous Apex method executions (batch Apex, future methods, Queueable Apex, and scheduled Apex) per a 24-hour period: 250,000 or the number of user licenses in your organization multiplied by 200, whichever is greater"
When we're talking about batch Apex, for example, are we just talking about start(), execute(), finish() methods being applied to that limit or are all methods - even custom methods - also included in that figure as well?
Also is there a way to see how close we are getting to that limit every day? I looked at the Limits class but didn't see any direct methods there. We have a couple of huge batch classes that run once a week and I want to make sure we're not getting too close to that limit.
- BroncoBoy
- December 09, 2016
- Like
- 0
- Continue reading or reply
Wave Analytics Error "Invalid schema: Error, Invalid key name: %!(EXTRA string=WhatId(Account).Name)"
I'm trying to run the Dataflow and getting this error:
Error executing node 133: Invalid schema: Error, Invalid key name: %!(EXTRA string=WhatId(Account).Name) (02K32000000CdmREAS_03C32000000TNDQEA4)
I can't find a knowledge article on this particular error.
Can anybody speak to this?
Thanks in advance.
- Daniel Neufeld 6
- August 30, 2016
- Like
- 0
- Continue reading or reply
Possible to Combine 2 Bar Charts
1. It has last 6 months on the X axis, e.g. January - June
2. It has 2 Y Axes: on the left Sales in $$, on the right Applications - both as a decimal
3. For each month you have Product A Applications bar stacked on Product A Sales bar and then Product B Applications bar stacked on Product B Sales bar.
So essentially it's like stacking/superimposing one bar chart on top of another and adding an extra y axis. Is this even possible? Thanks in advance!
Bronco
- BroncoBoy
- July 28, 2016
- Like
- 0
- Continue reading or reply
Batch Process Attempt to de-reference a null object
Code:
public Database.QueryLocator start(Database.BatchableContext BC)
{
String query = 'SELECT Id, (SELECT ContactId, IsPrimary FROM OpportunityContactRoles ORDER BY IsPrimary DESC) FROM Opportunity WHERE LastModifiedDate = LAST_N_DAYS:365';
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC, List < sObject > s)
{
List < Opportunity > oppsToUpdate = new List < Opportunity > ();
for (sObject ssss: s)
{
Opportunity o = (Opportunity) ssss;
List < OpportunityContactRole > opptys = new List < OpportunityContactRole > ();
opptys = (List < OpportunityContactRole > ) o.getsobjects('OpportunityContactRoles'); //o.getsobjects will return a List<SObject>, in the same line we cast those into List<OpportunityContactRole>
for (OpportunityContactRole optt: opptys) // HERE IS WHERE THE ERROR IS. LOOPING THROUGH SUB QUERY LIST
{
String contId = '';
contId = String.ValueOf(optt.ContactId);
if (!String.IsBlank(contId))
{
o.Primary_Contact_Id__c = contId;
oppsToUpdate.add(o);
break;
}
}
}
update oppsToUpdate;
}
- BroncoBoy
- July 20, 2016
- Like
- 0
- Continue reading or reply
Visualforce Chart apex:barSeries, Currency
Right now the left axis is displaying several #'s, for example: 10000. I would prefer 10,000 or, even better, $10,000.
The source data is coming from a number type field from a custom object. I'm also wondering if I convert the field to type: currency if that would help?
Thanks in advance!
Bronco
- BroncoBoy
- May 18, 2016
- Like
- 0
- Continue reading or reply
SOQL: Trying to dynamically change the month filter for a query
SELECT Summary_Id__c, SUM(EA_App_Count__c) appCount FROM CustomObject__c WHERE Full_Date__c = THIS_MONTH GROUP BY Summary_Id__c';
Here's what I'm trying to do:
Trying to run this SOQL 6 separate times, based on the current month, once per month for the previous 6 months date range. So, in essence, after each run, the filter date range would dynamically change look something like:
- WHERE Full_Date__c = THIS_MONTH -1 //Previous month
- WHERE Full_Date__c = THIS_MONTH - 2 //2 months ago
- WHERE Full_Date__c = THIS_MONTH - 3 //3 months ago
- WHERE Full_Date__c = THIS_MONTH - 4 //4 months ago
- WHERE Full_Date__c = THIS_MONTH - 5 //5 months ago
- WHERE Full_Date__c = THIS_MONTH - 6 //6 months ago
Thanks in advance for any help you can offer!
-Bronco
- BroncoBoy
- April 20, 2016
- Like
- 0
- Continue reading or reply
Edit/Save issue with the salesforce 1 Mobile
My user running his mobile Salesforce1 then showing this Error.
"There's a problem saving this record. You might not have permission to edit, or might have been deleted or archived."
I also checked his profile, he is Salesforce 1 User. How can help this user to edit/ Save via Salesforce1 on the case ?
- Praveen Bonalu
- March 03, 2016
- Like
- 0
- Continue reading or reply
Building a map of lists, error accessing subquery field values. Error: Invalid aggregate relationship
Create a map of lists (contactIdsToOpportunities) which maps a contact id to the list of opportunities that contact is associated with within the OpportunityContactRole object - all based on a limited # of contact id's, only opportunities within the last 30 days.
As I'm trying to access the subquery field values to build my map of lists, its generating the following error:
Invalid aggregate relationship OpportunityContactRole for Opportunity
I'm trying to use this approach: http://www.infallibletechie.com/2012/04/how-to-get-subquery-field-value-using.html
I'm grateful for any help, so thanks in advance!
-Bronco
CODE:
set <Id> evtsContactIds = new set <Id>{'0035000000yim1c’,’0035000000cin2f’};//insert contacts id's here
map <Id, List <Opportunity>> contactIdsToOpportunities = new Map <Id, List <Opportunity>>();
for (Opportunity o: [SELECT Id, CloseDate, Description, Name, (SELECT ContactId FROM OpportunityContactRoles WHERE ContactId IN: evtsContactIds) FROM Opportunity WHERE CloseDate >= LAST_N_DAYS: 30 AND Id IN(SELECT OpportunityId FROM OpportunityContactRole WHERE ContactId IN: evtsContactIds) ORDER BY CloseDate DESC])
{
List < OpportunityContactRole > opptys = new List < OpportunityContactRole > ();
opptys = o.getSObjects('OpportunityContactRole'); //very rarely used method, but this gets the records from the subquery,
Id oppContId;
for (OpportunityContactRole opt: opptys)
{
oppContId = opt.ContactId;
if (contactIdsToOpportunities.containsKey(oppContId))
{
List < Opportunity > contactsOpportunities = contactIdsToOpportunities.get(oppContId);
if (contactsOpportunities.size() <= 3) //this is what determines that the code will only return the latest 3 opportunities
{
contactsOpportunities.add(o);
contactIdsToOpportunities.put(oppContId, contactsOpportunities);
}
}
else
{
contactIdsToOpportunities.put(oppContId, new List <Opportunity>{o});
}
}
}
- BroncoBoy
- December 01, 2015
- Like
- 0
- Continue reading or reply
Task Trigger: Reset Checkboxes to Unchecked, Retain Checkbox Values
Code:
trigger EmailTaskDescription on Task(before insert, after insert, before update, after update)
{
Boolean nofityRIW = false;
Boolean nofityREW = false;
Boolean nofityBDC = false;
Boolean nofityGIW = false;
Boolean nofityGEW = false;
if (trigger.isBefore)
{
Task tt = Trigger.new[0];
//capture checkbox selections
nofityRIW = tt.Notify_R_IW__c;
nofityREW = tt.Notify_R_EW__c;
nofityBDC = tt.Notify_BDC__c;
nofityGIW = tt.Notify_G_IW__c;
nofityGEW = tt.Notify_G_EW__c;
//reset checkbox selections to unchecked
tt.Notify_R_IW__c = false;
tt.Notify_R_EW__c = false;
tt.Notify_BDC__c = false;
tt.Notify_G_EW__c = false;
tt.Notify_G_IW__c = false;
}
if (trigger.isAfter)
{
//use initial values to execute logic
if (nofityRIW)
{
}
else if (nofityREW)
{
}
}
}
- BroncoBoy
- October 07, 2015
- Like
- 0
- Continue reading or reply
How to execute Multiple batch apex jobs in sequence
I want to understand a specific concept.
I have created 2 batch apex classes say account and contact and now I need to run contact class only after account class fully completes(without any errors of course).
I schedule account class & then contact class, so when I click setup --> jobs --> scheduled jobs, I can see both these jobs
As per documentation order of execution of jobs is not guaranteed.
so how do I make sure that contact batch job executes only successful execution of account batch job.
please be specific in replies.
sonali
- sonali verma
- October 07, 2015
- Like
- 0
- Continue reading or reply
Executing method within a Visualforce extension using Javascript on a Visualforce page
Because of this, I can't use Javascript remoting nor can I use the AJAX toolkit/sforce.apex.execute method because both require static keywords and the instance variables are not visible to static methods. I'm greatful for any advice.
FYI The JSON string is used to populate a Datatables (https://datatables.net/" target="_blank) table on the VF page.
- BroncoBoy
- September 09, 2015
- Like
- 0
- Continue reading or reply
Repeat function to fill a list collection until collection size reaches 100 records
CODE:
public String TopOneHundred()
{
List < sObject > bd = StdSetControllerBD.getRecords();
List < Contact > contactsListB = retrieveTopOneHundred(bd);
if (contactsListB.size() < 100)
{
StdSetControllerBD.next(); //if we have less than 100 contact records then we will go get more by repeating the process, this time with the next set of bd records in the StdSetControllerBD
List < BD__c > nextRoundOfBdRecords = new List < BD__c > ();
for (sObject sob: StdSetControllerBD.getRecords())
{
BD__c sobd = (BD__c) sob;
nextRoundOfBdRecords.Add(sobd);
}
contactsListB.addAll(retrieveTopOneHundred(nextRoundOfBdRecords));
if (contactsListB.size() < 100)
{
StdSetControllerBD.next(); //if we have less than 100 contact records then we will go get more by repeating the process, this time with the next set of bd records in the StdSetControllerBD
List < BD__c > thirdRoundOfBdRecords = new List < BD__c > ();
for (sObject sob: StdSetControllerBD.getRecords())
{
BD__c sobdd = (BD__c) sob;
thirdRoundOfBdRecords.Add(sobdd);
}
contactsListB.addAll(retrieveTopOneHundred(nextRoundOfBdRecords));
}
}
String contactsJSON = JSON.serializePretty(contactsListB);
return contactsJSON;
}
- BroncoBoy
- September 03, 2015
- Like
- 0
- Continue reading or reply