-
ChatterFeed
-
1Best Answers
-
0Likes Received
-
0Likes Given
-
9Questions
-
13Replies
Having issue with mapping. Getting duplicate Ids error
I have delete batch that I would like to improve by using the existing mapping(m_finNums) but when I did I would get a duplicate id error on update. I am looking at 3 fields on FInance record and to match them with the ones on teh DCON record.
So to get around it I created 2 for loops which seems ineffecient. Any suggestions why I am getting the error would be appreciated
Thank you,
P
So to get around it I created 2 for loops which seems ineffecient. Any suggestions why I am getting the error would be appreciated
global class BatchFinanceUpdateFromDCON implements Database.Batchable<sObject> { global Database.QueryLocator start(Database.BatchableContext BC) { Date yesterday = System.today() - 2; String query = 'SELECT Id, Requisition_Number__c, PO_Line_Description__c, DCONFinanceKeyField__c, PO_Number__c, PO_Line_Number__c,' + 'Goods_Received_Date__c,Record_Marked_for_Deletion__c FROM DCON_Cube_Data__c WHERE Record_Marked_for_Deletion__c = false AND '+ 'LastModifiedDate > yesterday AND (Requisition_Number__c != null AND PO_Line_Description__c != null) AND ' + '(PO_Number__c != null OR PO_Line_Number__c != Null OR Goods_Received_Date__c != null)'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<SObject> scope) { List<DCON_Cube_Data__c> matchDCONAndFin = (List<DCON_Cube_Data__c>)scope; Set<String> odapIds = new Set<String>(); List<Finance__c> finListToUpdate = new List<Finance__c>(); List<Finance__c> listOfFinance = new List<Finance__c>(); List<Finance__c> listOfFinanceAllValues = new List<Finance__c>(); List<DCON_Cube_Data__c> listOfDCONToDelete = new List<DCON_Cube_Data__c>(); List<DCON_Cube_Data__c> DCONListToUpdate = new List<DCON_Cube_Data__c>(); Date yesterday = System.today() - 2; for (DCON_Cube_Data__c DCONs : matchDCONAndFin){ if(DCONs.PO_Line_Description__c != null && DCONs.Requisition_Number__c != null){ odapIds.add(DCONs.DCONFinanceKeyField__c); } } if (!odapIds.isEmpty()) { listOfFinance = [SELECT Id, finDCONKeyField__c, PO_Number_Custom__c, PO_Line_Number_Custom__c, Goods_Received_Date__c ,Actual_Date__c FROM Finance__c WHERE (PO_Number_Custom__c = null OR PO_Line_Number_Custom__c = Null OR Goods_Received_Date__c = null) AND finDCONKeyField__c in : odapIds]; } Map<String, Finance__c> m_finNums = new Map<String, Finance__c>(); Map<String, DCON_Cube_Data__c> o_DCONNums = new Map<String, DCON_Cube_Data__c>(); for(Finance__c fins : listOfFinance){ m_finNums.put(fins.finDCONKeyField__c, fins); } for(DCON_Cube_Data__c DCON : matchDCONAndFin){ o_DCONNums.put(DCON.DCONFinanceKeyField__c, DCON); } for (DCON_Cube_Data__c DCONs : o_DCONNums.values()){ for(Finance__c finObj : listOfFinance){ if(finObj.finDCONKeyField__c == DCONs.DCONFinanceKeyField__c ){ if(finObj.Actual_Date__c == null){ finObj.Actual_Date__c = System.today(); } if(DCONs.PO_Number__c != null && finObj.PO_Number_Custom__c == null){ finObj.PO_Number_Custom__c = DCONs.PO_Number__c; } if(DCONs.PO_Line_Number__c != null && finObj.PO_Line_Number_Custom__c == null){ finObj.PO_Line_Number_Custom__c = DCONs.PO_Line_Number__c; } if(DCONs.Goods_Received_Date__c != null && finObj.Goods_Received_Date__c == null){ finObj.Goods_Received_Date__c = DCONs.Goods_Received_Date__c; } finListToUpdate.add(finObj); } } } if(!finListToUpdate.isEmpty()){ Database.update(finListToUpdate, false); } } global void finish(Database.BatchableContext BC){ BatchUpdateDCONForDeletion bd = new BatchUpdateDCONForDeletion(); Database.executeBatch(bd, 200); } }
Thank you,
P
-
- Phuc Nguyen 18
- April 11, 2021
- Like
- 0
- Continue reading or reply
Callouts and Integration
Hi All, Below given code is part of the code which I have used to create and update contact records in another salesforce Org.It between salesforce to salesforce and I am able to create and update records in another org.However,After I made a callout I debug the response and tried to pull out External Id field from it...I wanted to update External ID field in Org1 with the id of the contact created in Org2 So when I used system.debug to see what's in the response. I could see External Id field with a value in it but after I looped through the returned contacts I only saw null in the External Id....Not sure what's going on.....How do I pull out external Id field from the response and update the contact field with the Id of the contact from org 2 as as External Id field in org 1?....I know I can use map to map external id with the Id of contact in map from Org1 and then update the contact field with the Id of the contact from org2...If somebody can help me in telling why I am not able to see External id field in reponse
System.debug('The response is********************'+response.getbody());
The above line has external Id value
The below line give me null
system.debug('The contact variable Conrec has the following values'+conReturned.Contact_Id_As_ExternalId__c);
if(accessTokenWrapperObj != null)
{
String endpoint = 'https://min72-dev-ed.my.salesforce.com/services/apexrest/createContacts/';
String requestBody = JSON.serialize(ContactList);
HTTP http = new HTTP();
HttpRequest request = new HttpRequest();
request.setBody(requestBody);
request.setMethod('POST');
request.setHeader('Authorization', 'Bearer '+accessTokenWrapperObj);
request.setHeader('Content-type','application/json');
request.setHeader('Accept','application/json');
request.setEndpoint(endpoint);
HttpResponse response = http.send(request);
System.debug('The response is********************'+response.getbody());
list<contact>updatecontactlist=new list<contact>();
list<contact> con=(List<contact>) System.JSON.deserialize(response.getbody(),List<contact>.class);
for(contact conReturned:con)
{
system.debug('The contact variable Conrec has the following values'+conReturned.Contact_Id_As_ExternalId__c);
system.debug('The contact variable Conrec has the following values'+conReturned.id);
contact c=new contact();
//c=MapofContact.get(conReturned.Contact_Id_As_ExternalId__c);
c.Contact_Id_As_ExternalId__c=conReturned.Id;
//updatecontactlist.add(c);
}
//update updatecontactlist;
//System.debug('The updated record is'+updatecontactlist);
//System.debug('Status code:'+response.getStatusCode()+'==>'+response.getBody());
}
}
}
System.debug('The response is********************'+response.getbody());
The above line has external Id value
The below line give me null
system.debug('The contact variable Conrec has the following values'+conReturned.Contact_Id_As_ExternalId__c);
if(accessTokenWrapperObj != null)
{
String endpoint = 'https://min72-dev-ed.my.salesforce.com/services/apexrest/createContacts/';
String requestBody = JSON.serialize(ContactList);
HTTP http = new HTTP();
HttpRequest request = new HttpRequest();
request.setBody(requestBody);
request.setMethod('POST');
request.setHeader('Authorization', 'Bearer '+accessTokenWrapperObj);
request.setHeader('Content-type','application/json');
request.setHeader('Accept','application/json');
request.setEndpoint(endpoint);
HttpResponse response = http.send(request);
System.debug('The response is********************'+response.getbody());
list<contact>updatecontactlist=new list<contact>();
list<contact> con=(List<contact>) System.JSON.deserialize(response.getbody(),List<contact>.class);
for(contact conReturned:con)
{
system.debug('The contact variable Conrec has the following values'+conReturned.Contact_Id_As_ExternalId__c);
system.debug('The contact variable Conrec has the following values'+conReturned.id);
contact c=new contact();
//c=MapofContact.get(conReturned.Contact_Id_As_ExternalId__c);
c.Contact_Id_As_ExternalId__c=conReturned.Id;
//updatecontactlist.add(c);
}
//update updatecontactlist;
//System.debug('The updated record is'+updatecontactlist);
//System.debug('Status code:'+response.getStatusCode()+'==>'+response.getBody());
}
}
}
-
- Nitin sharma 425
- April 27, 2021
- Like
- 0
- Continue reading or reply
Apex callouts and Integration Between SF to SF
Hi All,
Below given code is part of the code which I have used to create and update contact records in another salesforce Org.It between salesforce to salesforce and I am able to create and update records in another org.However,After I made a callout I debug the response and tried to pull out External Id field from it...I wanted to update External ID field in Org1 with the id of the contact created in Org2 So when I used system.debug to see what's in the response. I could see External Id field with a value in it but after I looped through the returned contacts I only saw null in the External Id....Not sure what's going on.....How do I pull out external Id field from the response and update the contact field with the Id of the contact from org 2 as as External Id field in org 1?....I know I can use map to map external id with the Id of contact in map from Org1 and then update the contact field with the Id of the contact from org2...If somebody can help me in telling why I am not able to see External id field in reponse
System.debug('The response is********************'+response.getbody());
The above line has external Id value
The below line give me null
system.debug('The contact variable Conrec has the following values'+conReturned.Contact_Id_As_ExternalId__c);
if(accessTokenWrapperObj != null) { String endpoint = 'https://min72-dev-ed.my.salesforce.com/services/apexrest/createContacts/'; String requestBody = JSON.serialize(ContactList); HTTP http = new HTTP(); HttpRequest request = new HttpRequest(); request.setBody(requestBody); request.setMethod('POST'); request.setHeader('Authorization', 'Bearer '+accessTokenWrapperObj); request.setHeader('Content-type','application/json'); request.setHeader('Accept','application/json'); request.setEndpoint(endpoint); HttpResponse response = http.send(request); System.debug('The response is********************'+response.getbody()); list<contact>updatecontactlist=new list<contact>(); list<contact> con=(List<contact>) System.JSON.deserialize(response.getbody(),List<contact>.class); for(contact conReturned:con) { system.debug('The contact variable Conrec has the following values'+conReturned.Contact_Id_As_ExternalId__c); system.debug('The contact variable Conrec has the following values'+conReturned.id); contact c=new contact(); //c=MapofContact.get(conReturned.Contact_Id_As_ExternalId__c); c.Contact_Id_As_ExternalId__c=conReturned.Id; //updatecontactlist.add(c); } //update updatecontactlist; //System.debug('The updated record is'+updatecontactlist); //System.debug('Status code:'+response.getStatusCode()+'==>'+response.getBody()); } }
}
Below given code is part of the code which I have used to create and update contact records in another salesforce Org.It between salesforce to salesforce and I am able to create and update records in another org.However,After I made a callout I debug the response and tried to pull out External Id field from it...I wanted to update External ID field in Org1 with the id of the contact created in Org2 So when I used system.debug to see what's in the response. I could see External Id field with a value in it but after I looped through the returned contacts I only saw null in the External Id....Not sure what's going on.....How do I pull out external Id field from the response and update the contact field with the Id of the contact from org 2 as as External Id field in org 1?....I know I can use map to map external id with the Id of contact in map from Org1 and then update the contact field with the Id of the contact from org2...If somebody can help me in telling why I am not able to see External id field in reponse
System.debug('The response is********************'+response.getbody());
The above line has external Id value
The below line give me null
system.debug('The contact variable Conrec has the following values'+conReturned.Contact_Id_As_ExternalId__c);
if(accessTokenWrapperObj != null) { String endpoint = 'https://min72-dev-ed.my.salesforce.com/services/apexrest/createContacts/'; String requestBody = JSON.serialize(ContactList); HTTP http = new HTTP(); HttpRequest request = new HttpRequest(); request.setBody(requestBody); request.setMethod('POST'); request.setHeader('Authorization', 'Bearer '+accessTokenWrapperObj); request.setHeader('Content-type','application/json'); request.setHeader('Accept','application/json'); request.setEndpoint(endpoint); HttpResponse response = http.send(request); System.debug('The response is********************'+response.getbody()); list<contact>updatecontactlist=new list<contact>(); list<contact> con=(List<contact>) System.JSON.deserialize(response.getbody(),List<contact>.class); for(contact conReturned:con) { system.debug('The contact variable Conrec has the following values'+conReturned.Contact_Id_As_ExternalId__c); system.debug('The contact variable Conrec has the following values'+conReturned.id); contact c=new contact(); //c=MapofContact.get(conReturned.Contact_Id_As_ExternalId__c); c.Contact_Id_As_ExternalId__c=conReturned.Id; //updatecontactlist.add(c); } //update updatecontactlist; //System.debug('The updated record is'+updatecontactlist); //System.debug('Status code:'+response.getStatusCode()+'==>'+response.getBody()); } }
}
-
- Nitin sharma 425
- April 27, 2021
- Like
- 0
- Continue reading or reply
Platform events and Trigger to log errors
Hi All,
Firstly,I am not sure if the Raise Paltform event has been released for all or not.Does anyone knows about it?
Another question:-
I wrote a batch class and deliberately generated an exception while updating an Account record.I did not provide an Account Id while updating an Account record...I was hoping it will fire a trigger on the BatchApexErrorEvent and then update the accoun object with the type of Exception..But triggetr is not getting Fired.Am sure I am missing something here.Please advice.
Simple Batch Apex:-
global class AccountBatchApex implements Database.Batchable<sObject>,Database.RaisesPlatformEvents{
//Database.RaisesPlatformEvents
//global integer numberofDirectCustomers = 0;
//integer counter=0;
global Database.QueryLocator start(Database.BatchableContext bc){
String soqlQuery = 'SELECT Name, AccountNumber, Type From Account limit 10';
return Database.getQueryLocator(soqlQuery);
}
global void execute(Database.BatchableContext bc, List<Account> scope){
List<Account>acc12=new list<Account>();
for (Account acc : scope){
Account a=new account(Name='NYTimes',AccountNumber='1234567890');
acc12.add(a);
}
Update Acc12;
}
global void finish(Database.BatchableContext bc){
}
}
Trigger Code which is from the guide.
global class AccountBatchApex implements Database.Batchable<sObject>,Database.RaisesPlatformEvents{
//Database.RaisesPlatformEvents
//global integer numberofDirectCustomers = 0;
//integer counter=0;
global Database.QueryLocator start(Database.BatchableContext bc){
String soqlQuery = 'SELECT Name, AccountNumber, Type From Account limit 10';
return Database.getQueryLocator(soqlQuery);
}
global void execute(Database.BatchableContext bc, List<Account> scope){
List<Account>acc12=new list<Account>();
for (Account acc : scope){
Account a=new account(Name='NYTimes',AccountNumber='1234567890');
acc12.add(a);
//if(acc.Type.equals('Customer - Direct'))
//{
// numberofDirectCustomers++;
//System.debug('The number of new cutomer are as follows'+numberofDirectCustomers);
//}
}
Update Acc12;
}
global void finish(Database.BatchableContext bc){
}
}
Once again:-Is BatchApexErrorEvent is still Beta or available to all users.?
Is it possible to query this object?
Firstly,I am not sure if the Raise Paltform event has been released for all or not.Does anyone knows about it?
Another question:-
I wrote a batch class and deliberately generated an exception while updating an Account record.I did not provide an Account Id while updating an Account record...I was hoping it will fire a trigger on the BatchApexErrorEvent and then update the accoun object with the type of Exception..But triggetr is not getting Fired.Am sure I am missing something here.Please advice.
Simple Batch Apex:-
global class AccountBatchApex implements Database.Batchable<sObject>,Database.RaisesPlatformEvents{
//Database.RaisesPlatformEvents
//global integer numberofDirectCustomers = 0;
//integer counter=0;
global Database.QueryLocator start(Database.BatchableContext bc){
String soqlQuery = 'SELECT Name, AccountNumber, Type From Account limit 10';
return Database.getQueryLocator(soqlQuery);
}
global void execute(Database.BatchableContext bc, List<Account> scope){
List<Account>acc12=new list<Account>();
for (Account acc : scope){
Account a=new account(Name='NYTimes',AccountNumber='1234567890');
acc12.add(a);
}
Update Acc12;
}
global void finish(Database.BatchableContext bc){
}
}
Trigger Code which is from the guide.
global class AccountBatchApex implements Database.Batchable<sObject>,Database.RaisesPlatformEvents{
//Database.RaisesPlatformEvents
//global integer numberofDirectCustomers = 0;
//integer counter=0;
global Database.QueryLocator start(Database.BatchableContext bc){
String soqlQuery = 'SELECT Name, AccountNumber, Type From Account limit 10';
return Database.getQueryLocator(soqlQuery);
}
global void execute(Database.BatchableContext bc, List<Account> scope){
List<Account>acc12=new list<Account>();
for (Account acc : scope){
Account a=new account(Name='NYTimes',AccountNumber='1234567890');
acc12.add(a);
//if(acc.Type.equals('Customer - Direct'))
//{
// numberofDirectCustomers++;
//System.debug('The number of new cutomer are as follows'+numberofDirectCustomers);
//}
}
Update Acc12;
}
global void finish(Database.BatchableContext bc){
}
}
Once again:-Is BatchApexErrorEvent is still Beta or available to all users.?
Is it possible to query this object?
-
- Nitin sharma 425
- April 21, 2021
- Like
- 0
- Continue reading or reply
URL and Json Issue
HI All.
I am making a webservice call out and I am getting the following reponse which I am not able to fix.
The body has the following reponse{"error": "Invalid Parameters supplied."}
If I direclty type URL with Parameters in the Browser then it gets me data
https://api.weatherbit.io/v2.0/current?city=hudson&key=b3dbd1fd17094d04adab62cb4e9b8d23
{"data":[{"rh":65,"pod":"d","lon":-82.69343,"pres":1008.5,"timezone":"America\/New_York","ob_time":"2021-04-17 21:16","country_code":"US","clouds":75,"ts":1618694160,"solar_rad":425.4,"state_code":"FL","city_name":"Hudson","wind_spd":0.89,"wind_cdir_full":"west-southwest","wind_cdir":"WSW","slp":1009.2,"vis":5,"h_angle":60,"sunset":"23:57","dni":831.43,"dewpt":21.7,"snow":0,"uv":3.24984,"precip":0,"wind_dir":254,"sunrise":"11:01","ghi":608.39,"dhi":103.24,"aqi":52,"lat":28.36445,"weather":{"icon":"c02d","code":802,"description":"Scattered clouds"},"datetime":"2021-04-17:21","temp":28.9,"station":"C9863","elev_angle":37.99,"app_temp":31.7}],"count":1}
However,After constructing the same URL in the code I get the following error
The body has the following reponse{"error": "Invalid Parameters supplied."}
So basically it looks like an issue with my URL.How do I fix it?
Here the rest link from the service supplier
Base URL.
HTTP: http://api.weatherbit.io/v2.0/current
HTTPS: https://api.weatherbit.io/v2.0/current
Followwing is the Api Key
b3dbd1fd17094d04adab62cb4e9b8d23
and I am passing Hudson as the city.
City=Hudson
Here is my URL which I constructed in the code:-
String k='b3dbd1fd17094d04adab62cb4e9b8d23';
city=EncodingUtil.urlEncode(city,'UTF-8');
String MapUrl='https://api.weatherbit.io/v2.0/currentweather?q='+city+'& Key'=+k;
However,it gives me an error when I run code.
Can somebody help me in fixing this URL.
I am making a webservice call out and I am getting the following reponse which I am not able to fix.
The body has the following reponse{"error": "Invalid Parameters supplied."}
If I direclty type URL with Parameters in the Browser then it gets me data
https://api.weatherbit.io/v2.0/current?city=hudson&key=b3dbd1fd17094d04adab62cb4e9b8d23
{"data":[{"rh":65,"pod":"d","lon":-82.69343,"pres":1008.5,"timezone":"America\/New_York","ob_time":"2021-04-17 21:16","country_code":"US","clouds":75,"ts":1618694160,"solar_rad":425.4,"state_code":"FL","city_name":"Hudson","wind_spd":0.89,"wind_cdir_full":"west-southwest","wind_cdir":"WSW","slp":1009.2,"vis":5,"h_angle":60,"sunset":"23:57","dni":831.43,"dewpt":21.7,"snow":0,"uv":3.24984,"precip":0,"wind_dir":254,"sunrise":"11:01","ghi":608.39,"dhi":103.24,"aqi":52,"lat":28.36445,"weather":{"icon":"c02d","code":802,"description":"Scattered clouds"},"datetime":"2021-04-17:21","temp":28.9,"station":"C9863","elev_angle":37.99,"app_temp":31.7}],"count":1}
However,After constructing the same URL in the code I get the following error
The body has the following reponse{"error": "Invalid Parameters supplied."}
So basically it looks like an issue with my URL.How do I fix it?
Here the rest link from the service supplier
Base URL.
HTTP: http://api.weatherbit.io/v2.0/current
HTTPS: https://api.weatherbit.io/v2.0/current
Followwing is the Api Key
b3dbd1fd17094d04adab62cb4e9b8d23
and I am passing Hudson as the city.
City=Hudson
Here is my URL which I constructed in the code:-
String k='b3dbd1fd17094d04adab62cb4e9b8d23';
city=EncodingUtil.urlEncode(city,'UTF-8');
String MapUrl='https://api.weatherbit.io/v2.0/currentweather?q='+city+'& Key'=+k;
However,it gives me an error when I run code.
Can somebody help me in fixing this URL.
-
- Nitin sharma 425
- April 17, 2021
- Like
- 0
- Continue reading or reply
URL issue with Json
Hi All,
String Api='6e8e6478bc45d53ef7e693299ed86f13';
//https://maps.googleapis.com/maps/api/geocode/json?address='+address+'&key='+googleApiKey+'&
city=EncodingUtil.urlEncode(city,'UTF-8');
String MapUrl='https://api.openweathermap.org/data/2.5/weather?q='+city+'&appid='+Api+'';
I am having diffuclty in constructing proprer URL for the callout ..I have listed Api Key but I am getting an error Unauthorised End Point URL.
Can somebody help?
String Api='6e8e6478bc45d53ef7e693299ed86f13';
//https://maps.googleapis.com/maps/api/geocode/json?address='+address+'&key='+googleApiKey+'&
city=EncodingUtil.urlEncode(city,'UTF-8');
String MapUrl='https://api.openweathermap.org/data/2.5/weather?q='+city+'&appid='+Api+'';
I am having diffuclty in constructing proprer URL for the callout ..I have listed Api Key but I am getting an error Unauthorised End Point URL.
Can somebody help?
-
- Nitin sharma 425
- April 17, 2021
- Like
- 0
- Continue reading or reply
An exception while Updating Accounts through batch Apex
Hi All,
Exception:-
First error: Row with null Id at index: 0
I am getting an exception while showing the total number of contacts on the account using batch Apex.Not able to resolve, can somebody help?
public class UpdateAccountwithBatchApex implements Database.Batchable<sObject>,Database.Stateful
{
Public Integer RecordsProcessed=0;
public Database.QueryLocator Start(DataBase.BatchableContext context)
{
return Database.getQueryLocator([Select id from account]);
}
Public void Execute(Database.batchableContext context,list<Account>scope)
{
Map<Id, AggregateResult> results = new Map<Id, AggregateResult>([SELECT Accountid Ids, COUNT(Id) amt FROM contact WHERE Accountid = :scope GROUP BY Accountid]);
list<Account>accrec=new list<account>();
Account acc=new Account();
for(Account record: scope)
{
System.debug('I am in for loop');
AggregateResult amount = results.get(record.Id);
if(amount != null)
{
System.debug('I am in the if statement');
accrec.add(new Account(Id=(Id)amount.get('ids'),Total_no_of_Contacts__c=(Decimal)amount.get('amt')));
}
else
{
accrec.add(new Account(Id=(Id)amount.get('ids'),Total_no_of_Contacts__c=null));
}
}
update accrec ;
}
public void Finish(Database.BatchableContext de)
{
System.debug('Records processed were'+RecordsProcessed);
}
}
Thanks,
Exception:-
First error: Row with null Id at index: 0
I am getting an exception while showing the total number of contacts on the account using batch Apex.Not able to resolve, can somebody help?
public class UpdateAccountwithBatchApex implements Database.Batchable<sObject>,Database.Stateful
{
Public Integer RecordsProcessed=0;
public Database.QueryLocator Start(DataBase.BatchableContext context)
{
return Database.getQueryLocator([Select id from account]);
}
Public void Execute(Database.batchableContext context,list<Account>scope)
{
Map<Id, AggregateResult> results = new Map<Id, AggregateResult>([SELECT Accountid Ids, COUNT(Id) amt FROM contact WHERE Accountid = :scope GROUP BY Accountid]);
list<Account>accrec=new list<account>();
Account acc=new Account();
for(Account record: scope)
{
System.debug('I am in for loop');
AggregateResult amount = results.get(record.Id);
if(amount != null)
{
System.debug('I am in the if statement');
accrec.add(new Account(Id=(Id)amount.get('ids'),Total_no_of_Contacts__c=(Decimal)amount.get('amt')));
}
else
{
accrec.add(new Account(Id=(Id)amount.get('ids'),Total_no_of_Contacts__c=null));
}
}
update accrec ;
}
public void Finish(Database.BatchableContext de)
{
System.debug('Records processed were'+RecordsProcessed);
}
}
Thanks,
-
- Nitin sharma 425
- April 11, 2021
- Like
- 0
- Continue reading or reply
Governor limit for simple query in a regular class versus Batch class
Hi All,
Firstly,Governor limits for a single query such as [Select id,name from Account] wiill fetch 50,000 thousand records as per salesforce Governor limits.
and now same Query in the Start() method of the batch class can fetch 50 million account records,Is that correct?.please correct me if I am wrong.
Thirdly,am not sure how these 50 millions records are processed.
My guess is salesforce will keep on passing 50 million records in chunks of 200 each to the Execute() which will process those records and then next set of 200 records will be passed to the execute methis.Will keep doing it unless all 50 million records are processed.
Am I thinking right?...Though I am going through the documentation,.However would like to hear from people out there in the community.
Thanks
Firstly,Governor limits for a single query such as [Select id,name from Account] wiill fetch 50,000 thousand records as per salesforce Governor limits.
and now same Query in the Start() method of the batch class can fetch 50 million account records,Is that correct?.please correct me if I am wrong.
Thirdly,am not sure how these 50 millions records are processed.
My guess is salesforce will keep on passing 50 million records in chunks of 200 each to the Execute() which will process those records and then next set of 200 records will be passed to the execute methis.Will keep doing it unless all 50 million records are processed.
Am I thinking right?...Though I am going through the documentation,.However would like to hear from people out there in the community.
Thanks
-
- Nitin sharma 425
- April 10, 2021
- Like
- 0
- Continue reading or reply
After Update trigger issue,Having an issuse with the if statement.
Hi All,
After update trigger on the opportunity Object.
If the Title__c field on the Opportunity object have CEO as the title then I should be able to update countofCEO field on the Account object
So when a user update the title__ field from CEO to Blank then counter on the Account object should decrease by 1 and vice versa
When I Update from CEO to Blank ,code run's fine but when I update same record and change Title field from blank to CEO then I get null pointer Exception and am not sure how to remove it.
Exception as per Salesforce.
CountOfOppwithCEOTitle: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.CountOfOppwithCEOTitle: line 77, column 1
Below given line is the culprit.
As per the debug logs ,Below given line is an issue
if(Trigger.oldmap.get(opp.id).title__c.contains('CEO')
if(Trigger.oldmap.get(opp.id).title__c.contains('CEO')&& opp.title__c==null)
if(trigger.isUpdate&& trigger.IsAfter)
{
Set<id>Accids=new set<id>();
Map<id,opportunity>mapofOppIdtoOppRecords=new map<id,opportunity>();
for(opportunity opp:trigger.new)
{
if(Trigger.oldmap.get(opp.id).title__c.contains('CEO')&& opp.title__c==null)
//if(trigger.newmap.get(opp.id).title__c!=trigger.oldmap.get(opp.Id).title__c && (Trigger.oldmap.get(opp.id).title__c.contains('CEO')&& opp.title__c==null))
{
system.debug('I am in the initial for loop');
mapofOppIdtoOppRecords.put(opp.id,opp);
Accids.add(opp.accountid);
}
else
if(opp.title__c!=trigger.oldmap.get(opp.Id).title__c && (String.isBlank(Trigger.oldmap.get(opp.id).title__c)&& opp.title__c.contains('CEO')))
{
mapofOppIdtoOppRecords.put(opp.id,opp);
Accids.add(opp.accountid);
}
}
Map<id,Account>MapofAccountIdToAccount=new map<id,account>([select id,countofCEO__c from account where id in:Accids]);
List<opportunity>Opp=[Select id,title__c,Accountid from Opportunity where id in:mapofOppIdtoOppRecords.keyset()];
list<account>acclist=new list<account>();
for(Opportunity Opprecords:opp)
{
system.debug('I am in for loop');
if(MapofAccountIdToAccount.containskey(opprecords.accountid)&& Opprecords.title__c==null)
{
system.debug('The debug value is');
Account Acc=MapofAccountIdToAccount.get(Opprecords.Accountid);
Acc.countofCEO__c=acc.countofCEO__c-1;
acclist.add(acc);
}
else
if(MapofAccountIdToAccount.containskey(opprecords.accountid)&& Opprecords.title__c.contains('CEO'))
{
Account Acc=MapofAccountIdToAccount.get(Opprecords.Accountid);
Acc.countofCEO__c=acc.countofCEO__c+1;
acclist.add(acc);
}
}
try
{
if(!acclist.isEmpty()&& acclist.size()>0)
{
Map<id,Account>MapofAccountIdToOpp=new map<id,account>();
MapofAccountIdToOpp.putall(acclist);
update MapofAccountIdToOpp.values();
}
}
catch(DmlException de)
{
}
}
Thanks
After update trigger on the opportunity Object.
If the Title__c field on the Opportunity object have CEO as the title then I should be able to update countofCEO field on the Account object
So when a user update the title__ field from CEO to Blank then counter on the Account object should decrease by 1 and vice versa
When I Update from CEO to Blank ,code run's fine but when I update same record and change Title field from blank to CEO then I get null pointer Exception and am not sure how to remove it.
Exception as per Salesforce.
CountOfOppwithCEOTitle: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.CountOfOppwithCEOTitle: line 77, column 1
Below given line is the culprit.
As per the debug logs ,Below given line is an issue
if(Trigger.oldmap.get(opp.id).title__c.contains('CEO')
if(Trigger.oldmap.get(opp.id).title__c.contains('CEO')&& opp.title__c==null)
if(trigger.isUpdate&& trigger.IsAfter)
{
Set<id>Accids=new set<id>();
Map<id,opportunity>mapofOppIdtoOppRecords=new map<id,opportunity>();
for(opportunity opp:trigger.new)
{
if(Trigger.oldmap.get(opp.id).title__c.contains('CEO')&& opp.title__c==null)
//if(trigger.newmap.get(opp.id).title__c!=trigger.oldmap.get(opp.Id).title__c && (Trigger.oldmap.get(opp.id).title__c.contains('CEO')&& opp.title__c==null))
{
system.debug('I am in the initial for loop');
mapofOppIdtoOppRecords.put(opp.id,opp);
Accids.add(opp.accountid);
}
else
if(opp.title__c!=trigger.oldmap.get(opp.Id).title__c && (String.isBlank(Trigger.oldmap.get(opp.id).title__c)&& opp.title__c.contains('CEO')))
{
mapofOppIdtoOppRecords.put(opp.id,opp);
Accids.add(opp.accountid);
}
}
Map<id,Account>MapofAccountIdToAccount=new map<id,account>([select id,countofCEO__c from account where id in:Accids]);
List<opportunity>Opp=[Select id,title__c,Accountid from Opportunity where id in:mapofOppIdtoOppRecords.keyset()];
list<account>acclist=new list<account>();
for(Opportunity Opprecords:opp)
{
system.debug('I am in for loop');
if(MapofAccountIdToAccount.containskey(opprecords.accountid)&& Opprecords.title__c==null)
{
system.debug('The debug value is');
Account Acc=MapofAccountIdToAccount.get(Opprecords.Accountid);
Acc.countofCEO__c=acc.countofCEO__c-1;
acclist.add(acc);
}
else
if(MapofAccountIdToAccount.containskey(opprecords.accountid)&& Opprecords.title__c.contains('CEO'))
{
Account Acc=MapofAccountIdToAccount.get(Opprecords.Accountid);
Acc.countofCEO__c=acc.countofCEO__c+1;
acclist.add(acc);
}
}
try
{
if(!acclist.isEmpty()&& acclist.size()>0)
{
Map<id,Account>MapofAccountIdToOpp=new map<id,account>();
MapofAccountIdToOpp.putall(acclist);
update MapofAccountIdToOpp.values();
}
}
catch(DmlException de)
{
}
}
Thanks
-
- Nitin sharma 425
- April 03, 2021
- Like
- 0
- Continue reading or reply
Updating opp record working from User Interface but same code giving trouble when updating with data loaderr
Hi All,
I have a countofCEO__c field on the Account Object and Account has couple of Opportunties with Title__c field .After an opp is updated and Title__c field which had some value ealier is left blank the the field countofCEO__c field on the account object should subtract 1 from it and update account Object.....The below given code is working fine then I update an opp from the user interface and leave Title__c field blank then 1 is subttracted the field on the Account object .
However,when I try to do same thing from the Data loader the program is not working as desired.
The below given line is the culprit.When I remove Opp.title__c and only keep the line "if(opp.title__c!=trigger.oldmap.get(opp.Id).title__c)
and try to update couple of opp's through the data loader then it works fine.If I add if(opp.title__c==null) in addition to th above line then it does not work....I need to check for the Value in the Title__c field so if its null then then I need to update account object..
So what is wrong with the null value line when trying to update opps through Data Loader.?
if(opp.title__c==null && opp.title__c!=trigger.oldmap.get(opp.Id).title__c)
{
Trigger CountOfOppwithCEOTitle on Opportunity (After Update)
{
Set<id>Accids=new set<id>();
Map<id,opportunity>mapofOppIdtoOppRecords=new map<id,opportunity>();
for(opportunity opp:trigger.new)
{
if(opp.title__c==null && opp.title__c!=trigger.oldmap.get(opp.Id).title__c)
{
system.debug('I am in the initial for loop');
mapofOppIdtoOppRecords.put(opp.id,opp);
Accids.add(opp.accountid);
}
}
Map<id,Account>MapofAccountIdToAccount=new map<id,account>([select id,countofCEO__c from account where id in:Accids]);
List<opportunity>Opp=[Select id,title__c,Accountid from Opportunity where id in:mapofOppIdtoOppRecords.keyset()];
//select id,countofCEO__c,from account
//where id in:mapofAccIdtoOppRecords.keyset()];
list<account>acclist=new list<account>();
for(Opportunity Opprecords:opp)
{
system.debug('I am in for loop');
if(MapofAccountIdToAccount.containskey(opprecords.accountid)&& Opprecords.title__c==null)
{
system.debug('The debug value is');
Account Acc=MapofAccountIdToAccount.get(Opprecords.Accountid);
Acc.countofCEO__c=acc.countofCEO__c-1;
acclist.add(acc);
}
}
try
{
if(!acclist.isEmpty()&& acclist.size()>0)
{
Map<id,Account>MapofAccountIdToOpp=new map<id,account>();
MapofAccountIdToOpp.putall(acclist);
update MapofAccountIdToOpp.values();
}
}
catch(DmlException de)
{
}
}
I have a countofCEO__c field on the Account Object and Account has couple of Opportunties with Title__c field .After an opp is updated and Title__c field which had some value ealier is left blank the the field countofCEO__c field on the account object should subtract 1 from it and update account Object.....The below given code is working fine then I update an opp from the user interface and leave Title__c field blank then 1 is subttracted the field on the Account object .
However,when I try to do same thing from the Data loader the program is not working as desired.
The below given line is the culprit.When I remove Opp.title__c and only keep the line "if(opp.title__c!=trigger.oldmap.get(opp.Id).title__c)
and try to update couple of opp's through the data loader then it works fine.If I add if(opp.title__c==null) in addition to th above line then it does not work....I need to check for the Value in the Title__c field so if its null then then I need to update account object..
So what is wrong with the null value line when trying to update opps through Data Loader.?
if(opp.title__c==null && opp.title__c!=trigger.oldmap.get(opp.Id).title__c)
{
Trigger CountOfOppwithCEOTitle on Opportunity (After Update)
{
Set<id>Accids=new set<id>();
Map<id,opportunity>mapofOppIdtoOppRecords=new map<id,opportunity>();
for(opportunity opp:trigger.new)
{
if(opp.title__c==null && opp.title__c!=trigger.oldmap.get(opp.Id).title__c)
{
system.debug('I am in the initial for loop');
mapofOppIdtoOppRecords.put(opp.id,opp);
Accids.add(opp.accountid);
}
}
Map<id,Account>MapofAccountIdToAccount=new map<id,account>([select id,countofCEO__c from account where id in:Accids]);
List<opportunity>Opp=[Select id,title__c,Accountid from Opportunity where id in:mapofOppIdtoOppRecords.keyset()];
//select id,countofCEO__c,from account
//where id in:mapofAccIdtoOppRecords.keyset()];
list<account>acclist=new list<account>();
for(Opportunity Opprecords:opp)
{
system.debug('I am in for loop');
if(MapofAccountIdToAccount.containskey(opprecords.accountid)&& Opprecords.title__c==null)
{
system.debug('The debug value is');
Account Acc=MapofAccountIdToAccount.get(Opprecords.Accountid);
Acc.countofCEO__c=acc.countofCEO__c-1;
acclist.add(acc);
}
}
try
{
if(!acclist.isEmpty()&& acclist.size()>0)
{
Map<id,Account>MapofAccountIdToOpp=new map<id,account>();
MapofAccountIdToOpp.putall(acclist);
update MapofAccountIdToOpp.values();
}
}
catch(DmlException de)
{
}
}
-
- Nitin sharma 425
- April 01, 2021
- Like
- 0
- Continue reading or reply
If user create opportunity in SF org, then same opp should create in another org
I have two systems Salesforce system and Third party system. It’s a migration process. Component wants a two way synchronization. Any user creates/ edit opportunity in Salesforce system then the same opportunity should create in third party system also. And viceversa. Two way approach require here. How could i accomplish this.
- Abilash.S
- April 22, 2021
- Like
- 0
- Continue reading or reply
Platform events and Trigger to log errors
Hi All,
Firstly,I am not sure if the Raise Paltform event has been released for all or not.Does anyone knows about it?
Another question:-
I wrote a batch class and deliberately generated an exception while updating an Account record.I did not provide an Account Id while updating an Account record...I was hoping it will fire a trigger on the BatchApexErrorEvent and then update the accoun object with the type of Exception..But triggetr is not getting Fired.Am sure I am missing something here.Please advice.
Simple Batch Apex:-
global class AccountBatchApex implements Database.Batchable<sObject>,Database.RaisesPlatformEvents{
//Database.RaisesPlatformEvents
//global integer numberofDirectCustomers = 0;
//integer counter=0;
global Database.QueryLocator start(Database.BatchableContext bc){
String soqlQuery = 'SELECT Name, AccountNumber, Type From Account limit 10';
return Database.getQueryLocator(soqlQuery);
}
global void execute(Database.BatchableContext bc, List<Account> scope){
List<Account>acc12=new list<Account>();
for (Account acc : scope){
Account a=new account(Name='NYTimes',AccountNumber='1234567890');
acc12.add(a);
}
Update Acc12;
}
global void finish(Database.BatchableContext bc){
}
}
Trigger Code which is from the guide.
global class AccountBatchApex implements Database.Batchable<sObject>,Database.RaisesPlatformEvents{
//Database.RaisesPlatformEvents
//global integer numberofDirectCustomers = 0;
//integer counter=0;
global Database.QueryLocator start(Database.BatchableContext bc){
String soqlQuery = 'SELECT Name, AccountNumber, Type From Account limit 10';
return Database.getQueryLocator(soqlQuery);
}
global void execute(Database.BatchableContext bc, List<Account> scope){
List<Account>acc12=new list<Account>();
for (Account acc : scope){
Account a=new account(Name='NYTimes',AccountNumber='1234567890');
acc12.add(a);
//if(acc.Type.equals('Customer - Direct'))
//{
// numberofDirectCustomers++;
//System.debug('The number of new cutomer are as follows'+numberofDirectCustomers);
//}
}
Update Acc12;
}
global void finish(Database.BatchableContext bc){
}
}
Once again:-Is BatchApexErrorEvent is still Beta or available to all users.?
Is it possible to query this object?
Firstly,I am not sure if the Raise Paltform event has been released for all or not.Does anyone knows about it?
Another question:-
I wrote a batch class and deliberately generated an exception while updating an Account record.I did not provide an Account Id while updating an Account record...I was hoping it will fire a trigger on the BatchApexErrorEvent and then update the accoun object with the type of Exception..But triggetr is not getting Fired.Am sure I am missing something here.Please advice.
Simple Batch Apex:-
global class AccountBatchApex implements Database.Batchable<sObject>,Database.RaisesPlatformEvents{
//Database.RaisesPlatformEvents
//global integer numberofDirectCustomers = 0;
//integer counter=0;
global Database.QueryLocator start(Database.BatchableContext bc){
String soqlQuery = 'SELECT Name, AccountNumber, Type From Account limit 10';
return Database.getQueryLocator(soqlQuery);
}
global void execute(Database.BatchableContext bc, List<Account> scope){
List<Account>acc12=new list<Account>();
for (Account acc : scope){
Account a=new account(Name='NYTimes',AccountNumber='1234567890');
acc12.add(a);
}
Update Acc12;
}
global void finish(Database.BatchableContext bc){
}
}
Trigger Code which is from the guide.
global class AccountBatchApex implements Database.Batchable<sObject>,Database.RaisesPlatformEvents{
//Database.RaisesPlatformEvents
//global integer numberofDirectCustomers = 0;
//integer counter=0;
global Database.QueryLocator start(Database.BatchableContext bc){
String soqlQuery = 'SELECT Name, AccountNumber, Type From Account limit 10';
return Database.getQueryLocator(soqlQuery);
}
global void execute(Database.BatchableContext bc, List<Account> scope){
List<Account>acc12=new list<Account>();
for (Account acc : scope){
Account a=new account(Name='NYTimes',AccountNumber='1234567890');
acc12.add(a);
//if(acc.Type.equals('Customer - Direct'))
//{
// numberofDirectCustomers++;
//System.debug('The number of new cutomer are as follows'+numberofDirectCustomers);
//}
}
Update Acc12;
}
global void finish(Database.BatchableContext bc){
}
}
Once again:-Is BatchApexErrorEvent is still Beta or available to all users.?
Is it possible to query this object?
- Nitin sharma 425
- April 21, 2021
- Like
- 0
- Continue reading or reply
URL issue with Json
Hi All,
String Api='6e8e6478bc45d53ef7e693299ed86f13';
//https://maps.googleapis.com/maps/api/geocode/json?address='+address+'&key='+googleApiKey+'&
city=EncodingUtil.urlEncode(city,'UTF-8');
String MapUrl='https://api.openweathermap.org/data/2.5/weather?q='+city+'&appid='+Api+'';
I am having diffuclty in constructing proprer URL for the callout ..I have listed Api Key but I am getting an error Unauthorised End Point URL.
Can somebody help?
String Api='6e8e6478bc45d53ef7e693299ed86f13';
//https://maps.googleapis.com/maps/api/geocode/json?address='+address+'&key='+googleApiKey+'&
city=EncodingUtil.urlEncode(city,'UTF-8');
String MapUrl='https://api.openweathermap.org/data/2.5/weather?q='+city+'&appid='+Api+'';
I am having diffuclty in constructing proprer URL for the callout ..I have listed Api Key but I am getting an error Unauthorised End Point URL.
Can somebody help?
- Nitin sharma 425
- April 17, 2021
- Like
- 0
- Continue reading or reply
An exception while Updating Accounts through batch Apex
Hi All,
Exception:-
First error: Row with null Id at index: 0
I am getting an exception while showing the total number of contacts on the account using batch Apex.Not able to resolve, can somebody help?
public class UpdateAccountwithBatchApex implements Database.Batchable<sObject>,Database.Stateful
{
Public Integer RecordsProcessed=0;
public Database.QueryLocator Start(DataBase.BatchableContext context)
{
return Database.getQueryLocator([Select id from account]);
}
Public void Execute(Database.batchableContext context,list<Account>scope)
{
Map<Id, AggregateResult> results = new Map<Id, AggregateResult>([SELECT Accountid Ids, COUNT(Id) amt FROM contact WHERE Accountid = :scope GROUP BY Accountid]);
list<Account>accrec=new list<account>();
Account acc=new Account();
for(Account record: scope)
{
System.debug('I am in for loop');
AggregateResult amount = results.get(record.Id);
if(amount != null)
{
System.debug('I am in the if statement');
accrec.add(new Account(Id=(Id)amount.get('ids'),Total_no_of_Contacts__c=(Decimal)amount.get('amt')));
}
else
{
accrec.add(new Account(Id=(Id)amount.get('ids'),Total_no_of_Contacts__c=null));
}
}
update accrec ;
}
public void Finish(Database.BatchableContext de)
{
System.debug('Records processed were'+RecordsProcessed);
}
}
Thanks,
Exception:-
First error: Row with null Id at index: 0
I am getting an exception while showing the total number of contacts on the account using batch Apex.Not able to resolve, can somebody help?
public class UpdateAccountwithBatchApex implements Database.Batchable<sObject>,Database.Stateful
{
Public Integer RecordsProcessed=0;
public Database.QueryLocator Start(DataBase.BatchableContext context)
{
return Database.getQueryLocator([Select id from account]);
}
Public void Execute(Database.batchableContext context,list<Account>scope)
{
Map<Id, AggregateResult> results = new Map<Id, AggregateResult>([SELECT Accountid Ids, COUNT(Id) amt FROM contact WHERE Accountid = :scope GROUP BY Accountid]);
list<Account>accrec=new list<account>();
Account acc=new Account();
for(Account record: scope)
{
System.debug('I am in for loop');
AggregateResult amount = results.get(record.Id);
if(amount != null)
{
System.debug('I am in the if statement');
accrec.add(new Account(Id=(Id)amount.get('ids'),Total_no_of_Contacts__c=(Decimal)amount.get('amt')));
}
else
{
accrec.add(new Account(Id=(Id)amount.get('ids'),Total_no_of_Contacts__c=null));
}
}
update accrec ;
}
public void Finish(Database.BatchableContext de)
{
System.debug('Records processed were'+RecordsProcessed);
}
}
Thanks,
- Nitin sharma 425
- April 11, 2021
- Like
- 0
- Continue reading or reply
Having issue with mapping. Getting duplicate Ids error
I have delete batch that I would like to improve by using the existing mapping(m_finNums) but when I did I would get a duplicate id error on update. I am looking at 3 fields on FInance record and to match them with the ones on teh DCON record.
So to get around it I created 2 for loops which seems ineffecient. Any suggestions why I am getting the error would be appreciated
Thank you,
P
So to get around it I created 2 for loops which seems ineffecient. Any suggestions why I am getting the error would be appreciated
global class BatchFinanceUpdateFromDCON implements Database.Batchable<sObject> { global Database.QueryLocator start(Database.BatchableContext BC) { Date yesterday = System.today() - 2; String query = 'SELECT Id, Requisition_Number__c, PO_Line_Description__c, DCONFinanceKeyField__c, PO_Number__c, PO_Line_Number__c,' + 'Goods_Received_Date__c,Record_Marked_for_Deletion__c FROM DCON_Cube_Data__c WHERE Record_Marked_for_Deletion__c = false AND '+ 'LastModifiedDate > yesterday AND (Requisition_Number__c != null AND PO_Line_Description__c != null) AND ' + '(PO_Number__c != null OR PO_Line_Number__c != Null OR Goods_Received_Date__c != null)'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<SObject> scope) { List<DCON_Cube_Data__c> matchDCONAndFin = (List<DCON_Cube_Data__c>)scope; Set<String> odapIds = new Set<String>(); List<Finance__c> finListToUpdate = new List<Finance__c>(); List<Finance__c> listOfFinance = new List<Finance__c>(); List<Finance__c> listOfFinanceAllValues = new List<Finance__c>(); List<DCON_Cube_Data__c> listOfDCONToDelete = new List<DCON_Cube_Data__c>(); List<DCON_Cube_Data__c> DCONListToUpdate = new List<DCON_Cube_Data__c>(); Date yesterday = System.today() - 2; for (DCON_Cube_Data__c DCONs : matchDCONAndFin){ if(DCONs.PO_Line_Description__c != null && DCONs.Requisition_Number__c != null){ odapIds.add(DCONs.DCONFinanceKeyField__c); } } if (!odapIds.isEmpty()) { listOfFinance = [SELECT Id, finDCONKeyField__c, PO_Number_Custom__c, PO_Line_Number_Custom__c, Goods_Received_Date__c ,Actual_Date__c FROM Finance__c WHERE (PO_Number_Custom__c = null OR PO_Line_Number_Custom__c = Null OR Goods_Received_Date__c = null) AND finDCONKeyField__c in : odapIds]; } Map<String, Finance__c> m_finNums = new Map<String, Finance__c>(); Map<String, DCON_Cube_Data__c> o_DCONNums = new Map<String, DCON_Cube_Data__c>(); for(Finance__c fins : listOfFinance){ m_finNums.put(fins.finDCONKeyField__c, fins); } for(DCON_Cube_Data__c DCON : matchDCONAndFin){ o_DCONNums.put(DCON.DCONFinanceKeyField__c, DCON); } for (DCON_Cube_Data__c DCONs : o_DCONNums.values()){ for(Finance__c finObj : listOfFinance){ if(finObj.finDCONKeyField__c == DCONs.DCONFinanceKeyField__c ){ if(finObj.Actual_Date__c == null){ finObj.Actual_Date__c = System.today(); } if(DCONs.PO_Number__c != null && finObj.PO_Number_Custom__c == null){ finObj.PO_Number_Custom__c = DCONs.PO_Number__c; } if(DCONs.PO_Line_Number__c != null && finObj.PO_Line_Number_Custom__c == null){ finObj.PO_Line_Number_Custom__c = DCONs.PO_Line_Number__c; } if(DCONs.Goods_Received_Date__c != null && finObj.Goods_Received_Date__c == null){ finObj.Goods_Received_Date__c = DCONs.Goods_Received_Date__c; } finListToUpdate.add(finObj); } } } if(!finListToUpdate.isEmpty()){ Database.update(finListToUpdate, false); } } global void finish(Database.BatchableContext BC){ BatchUpdateDCONForDeletion bd = new BatchUpdateDCONForDeletion(); Database.executeBatch(bd, 200); } }
Thank you,
P
- Phuc Nguyen 18
- April 11, 2021
- Like
- 0
- Continue reading or reply
Governor limit for simple query in a regular class versus Batch class
Hi All,
Firstly,Governor limits for a single query such as [Select id,name from Account] wiill fetch 50,000 thousand records as per salesforce Governor limits.
and now same Query in the Start() method of the batch class can fetch 50 million account records,Is that correct?.please correct me if I am wrong.
Thirdly,am not sure how these 50 millions records are processed.
My guess is salesforce will keep on passing 50 million records in chunks of 200 each to the Execute() which will process those records and then next set of 200 records will be passed to the execute methis.Will keep doing it unless all 50 million records are processed.
Am I thinking right?...Though I am going through the documentation,.However would like to hear from people out there in the community.
Thanks
Firstly,Governor limits for a single query such as [Select id,name from Account] wiill fetch 50,000 thousand records as per salesforce Governor limits.
and now same Query in the Start() method of the batch class can fetch 50 million account records,Is that correct?.please correct me if I am wrong.
Thirdly,am not sure how these 50 millions records are processed.
My guess is salesforce will keep on passing 50 million records in chunks of 200 each to the Execute() which will process those records and then next set of 200 records will be passed to the execute methis.Will keep doing it unless all 50 million records are processed.
Am I thinking right?...Though I am going through the documentation,.However would like to hear from people out there in the community.
Thanks
- Nitin sharma 425
- April 10, 2021
- Like
- 0
- Continue reading or reply
Updating opp record working from User Interface but same code giving trouble when updating with data loaderr
Hi All,
I have a countofCEO__c field on the Account Object and Account has couple of Opportunties with Title__c field .After an opp is updated and Title__c field which had some value ealier is left blank the the field countofCEO__c field on the account object should subtract 1 from it and update account Object.....The below given code is working fine then I update an opp from the user interface and leave Title__c field blank then 1 is subttracted the field on the Account object .
However,when I try to do same thing from the Data loader the program is not working as desired.
The below given line is the culprit.When I remove Opp.title__c and only keep the line "if(opp.title__c!=trigger.oldmap.get(opp.Id).title__c)
and try to update couple of opp's through the data loader then it works fine.If I add if(opp.title__c==null) in addition to th above line then it does not work....I need to check for the Value in the Title__c field so if its null then then I need to update account object..
So what is wrong with the null value line when trying to update opps through Data Loader.?
if(opp.title__c==null && opp.title__c!=trigger.oldmap.get(opp.Id).title__c)
{
Trigger CountOfOppwithCEOTitle on Opportunity (After Update)
{
Set<id>Accids=new set<id>();
Map<id,opportunity>mapofOppIdtoOppRecords=new map<id,opportunity>();
for(opportunity opp:trigger.new)
{
if(opp.title__c==null && opp.title__c!=trigger.oldmap.get(opp.Id).title__c)
{
system.debug('I am in the initial for loop');
mapofOppIdtoOppRecords.put(opp.id,opp);
Accids.add(opp.accountid);
}
}
Map<id,Account>MapofAccountIdToAccount=new map<id,account>([select id,countofCEO__c from account where id in:Accids]);
List<opportunity>Opp=[Select id,title__c,Accountid from Opportunity where id in:mapofOppIdtoOppRecords.keyset()];
//select id,countofCEO__c,from account
//where id in:mapofAccIdtoOppRecords.keyset()];
list<account>acclist=new list<account>();
for(Opportunity Opprecords:opp)
{
system.debug('I am in for loop');
if(MapofAccountIdToAccount.containskey(opprecords.accountid)&& Opprecords.title__c==null)
{
system.debug('The debug value is');
Account Acc=MapofAccountIdToAccount.get(Opprecords.Accountid);
Acc.countofCEO__c=acc.countofCEO__c-1;
acclist.add(acc);
}
}
try
{
if(!acclist.isEmpty()&& acclist.size()>0)
{
Map<id,Account>MapofAccountIdToOpp=new map<id,account>();
MapofAccountIdToOpp.putall(acclist);
update MapofAccountIdToOpp.values();
}
}
catch(DmlException de)
{
}
}
I have a countofCEO__c field on the Account Object and Account has couple of Opportunties with Title__c field .After an opp is updated and Title__c field which had some value ealier is left blank the the field countofCEO__c field on the account object should subtract 1 from it and update account Object.....The below given code is working fine then I update an opp from the user interface and leave Title__c field blank then 1 is subttracted the field on the Account object .
However,when I try to do same thing from the Data loader the program is not working as desired.
The below given line is the culprit.When I remove Opp.title__c and only keep the line "if(opp.title__c!=trigger.oldmap.get(opp.Id).title__c)
and try to update couple of opp's through the data loader then it works fine.If I add if(opp.title__c==null) in addition to th above line then it does not work....I need to check for the Value in the Title__c field so if its null then then I need to update account object..
So what is wrong with the null value line when trying to update opps through Data Loader.?
if(opp.title__c==null && opp.title__c!=trigger.oldmap.get(opp.Id).title__c)
{
Trigger CountOfOppwithCEOTitle on Opportunity (After Update)
{
Set<id>Accids=new set<id>();
Map<id,opportunity>mapofOppIdtoOppRecords=new map<id,opportunity>();
for(opportunity opp:trigger.new)
{
if(opp.title__c==null && opp.title__c!=trigger.oldmap.get(opp.Id).title__c)
{
system.debug('I am in the initial for loop');
mapofOppIdtoOppRecords.put(opp.id,opp);
Accids.add(opp.accountid);
}
}
Map<id,Account>MapofAccountIdToAccount=new map<id,account>([select id,countofCEO__c from account where id in:Accids]);
List<opportunity>Opp=[Select id,title__c,Accountid from Opportunity where id in:mapofOppIdtoOppRecords.keyset()];
//select id,countofCEO__c,from account
//where id in:mapofAccIdtoOppRecords.keyset()];
list<account>acclist=new list<account>();
for(Opportunity Opprecords:opp)
{
system.debug('I am in for loop');
if(MapofAccountIdToAccount.containskey(opprecords.accountid)&& Opprecords.title__c==null)
{
system.debug('The debug value is');
Account Acc=MapofAccountIdToAccount.get(Opprecords.Accountid);
Acc.countofCEO__c=acc.countofCEO__c-1;
acclist.add(acc);
}
}
try
{
if(!acclist.isEmpty()&& acclist.size()>0)
{
Map<id,Account>MapofAccountIdToOpp=new map<id,account>();
MapofAccountIdToOpp.putall(acclist);
update MapofAccountIdToOpp.values();
}
}
catch(DmlException de)
{
}
}
- Nitin sharma 425
- April 01, 2021
- Like
- 0
- Continue reading or reply
BATCH class to Delete records from an Object which are created 10 Days ago from today.
Can anyone share an example considering Account as an example.
Thanks
Shri
Thanks
Shri
- Shri Raj
- September 15, 2014
- Like
- 1
- Continue reading or reply