-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
3Questions
-
1Replies
Autonumbering records within batch class
global class LDPurchasedSV implements Database.Batchable<sObject>, Database.AllowsCallouts {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Name,SV_Synced_Hidden__c,Lead_Number_Hidden__c,SV_Priority_Hidden__c,OwnerId,Days_To_SV_Hidden__c, Id FROM Lead WHERE Days_To_SV_Hidden__c <= 3 and SV_Synced_Hidden__c = FALSE';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Lead> scope) {
integer i=1;
for (Lead e : scope) {
if(e.OwnerId == '00Gi0000000iqle')
{
if(e.Days_To_SV_Hidden__c ==0)
{
e.SV_Priority_Hidden__c =1;
}
else{
if(e.Days_To_SV_Hidden__c == 1)
{
e.SV_Priority_Hidden__c =2;
}
else
{
e.SV_Priority_Hidden__c =3;
}
}
e.SV_Synced_Hidden__c = TRUE;
e.OwnerId ='00Gf0000000TIWj';
}
e.Lead_Number_Hidden__c = i;
i++;
Update scope;
}
}
global void finish(Database.BatchableContext BC) { }
}
I am trying to add a number field for all the records that come through this batch. The number should increment with every record.
Lead_Number_Hidden__c should be updated with number.
The above code is giving the same number for all the records.
-
- Vishnu Yadavalli
- November 14, 2013
- Like
- 0
- Continue reading or reply
How to capture fields in XML and store in salesforce.
I have the forrlowing XML code which contain 4 Fields.
Dom.Document doc = new Dom.Document();
doc.load(res.getBody());
List<string> lstValues=new List<String>();
for(DOM.XMLNode rootnode : doc.getRootElement().getChildElements()){
for(DOM.XMLNode CompanyList: rootnode.getChildElements()){
for(DOM.XMLNode Company: CompanyList.getChildElements()){
lstValues.add(company.getText());
}
}
}
Data is comming in the following format.
<User> <CompanyId>4</CompanyId> <FirstName>sample string 2</FirstName> <LastName>sample string 3</LastName> <UserId>1</UserId> </User>
How do capture this data and store in salesforce.
-
- Vishnu Yadavalli
- October 24, 2013
- Like
- 0
- Continue reading or reply
AsyncApexExecutions Limit exceeded error for my batch apex on custom object.
I wrote a batch apex that selects all the records from updated events object. When ever this batch apex is scheduled it throwing the forrlowing error:
AsyncApexExecutions Limit exceeded.
Following is my batch apex code.
global class SyncCalendarsUpdates implements Database.Batchable<sObject>, Database.AllowsCallouts {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id, Event_ID__c, Description__c, Event_Owner__r.Id, Subject__c, Start_Datetime__c, End_Datetime__c, Click_Key__c FROM Updated_Event__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Updated_Event__c> scope) {
Map<String, String> clickKeyMap = new Map<String, String>();
for (Updated_Event__c e : scope) {
Boolean doUpdate = true;
if (e.Subject__c != null) {
if (e.Subject__c.left(2) == 'SV' && e.Click_Key__c != null && e.Click_Key__c != '') {
doUpdate = false;
}
}
if (doUpdate) {
ClickCalendar cal = new ClickCalendar(e.Event_Owner__r.Id, e.Start_Datetime__c, e.End_Datetime__c, e.Subject__c, e.Click_Key__c);
cal.buildUpdateRequest();
if (!Test.isRunningTest()) {
HttpResponse resp = cal.getResponse();
if (e.Click_Key__c == null) {
String key = cal.getKeyFromResponse(resp);
if (e.Event_ID__c != null) {
clickKeyMap.put(e.Event_ID__c, key);
}
}
}
}
e.Is_Synced__c = true;
}
update scope;
List<Event> eventsToUpdate = [SELECT Id, Click_Key__c FROM Event WHERE Id IN :clickKeyMap.keySet()];
for (Event e : eventsToUpdate) {
e.Click_Key__c = clickKeyMap.get(e.Id);
}
update eventsToUpdate;
}
global void finish(Database.BatchableContext BC) { }
}
We have 1,500,000 records in that object.
-
- Vishnu Yadavalli
- October 17, 2013
- Like
- 0
- Continue reading or reply
AsyncApexExecutions Limit exceeded error for my batch apex on custom object.
I wrote a batch apex that selects all the records from updated events object. When ever this batch apex is scheduled it throwing the forrlowing error:
AsyncApexExecutions Limit exceeded.
Following is my batch apex code.
global class SyncCalendarsUpdates implements Database.Batchable<sObject>, Database.AllowsCallouts {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id, Event_ID__c, Description__c, Event_Owner__r.Id, Subject__c, Start_Datetime__c, End_Datetime__c, Click_Key__c FROM Updated_Event__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Updated_Event__c> scope) {
Map<String, String> clickKeyMap = new Map<String, String>();
for (Updated_Event__c e : scope) {
Boolean doUpdate = true;
if (e.Subject__c != null) {
if (e.Subject__c.left(2) == 'SV' && e.Click_Key__c != null && e.Click_Key__c != '') {
doUpdate = false;
}
}
if (doUpdate) {
ClickCalendar cal = new ClickCalendar(e.Event_Owner__r.Id, e.Start_Datetime__c, e.End_Datetime__c, e.Subject__c, e.Click_Key__c);
cal.buildUpdateRequest();
if (!Test.isRunningTest()) {
HttpResponse resp = cal.getResponse();
if (e.Click_Key__c == null) {
String key = cal.getKeyFromResponse(resp);
if (e.Event_ID__c != null) {
clickKeyMap.put(e.Event_ID__c, key);
}
}
}
}
e.Is_Synced__c = true;
}
update scope;
List<Event> eventsToUpdate = [SELECT Id, Click_Key__c FROM Event WHERE Id IN :clickKeyMap.keySet()];
for (Event e : eventsToUpdate) {
e.Click_Key__c = clickKeyMap.get(e.Id);
}
update eventsToUpdate;
}
global void finish(Database.BatchableContext BC) { }
}
We have 1,500,000 records in that object.
- Vishnu Yadavalli
- October 17, 2013
- Like
- 0
- Continue reading or reply