• Abhay Rathore
  • NEWBIE
  • 30 Points
  • Member since 2013
  • Salesforce Developer

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hi, 

I wrote a below batch program which is working but bug i noticed is its updating common value to all the accounts which should not happen

example : account_ 1 has two opportunity with amount = 200
                 account_ 2 has one opportunity with amount = 100

When i run below batch it is update 200 as common to account_1 and account_2 which is a bug it should actiually update 200 for account_1  and 100 for account_1

Please suggest me how to get this fixed
global class batchpreamount implements Database.Batchable<sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'Select Id, Name, Previous_Year_Closed_Opportunities__c   from Account';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Account> scope)
    {
        List<Id> accIds = new List<Id>();
        for(Account a : scope)
        {
                accIds.add(a.id);
        }
            // query outside for loop
        List<AggregateResult> groupedResults = [ 
        SELECT sum(amount)preamount from opportunity 
                                     WHERE accountid in:accIds and
                                           isDeleted = false AND forecastcategoryname = 'commit' AND 
                                           closedate = LAST_YEAR];
                                       
                      
                                
      if (groupedResults[0].get('preamount') != NULL)
      {
       Decimal totalSum = Decimal.valueOf ( groupedResults[0].get('preamount') + '');

        for(Account a : Scope)
        {
            a.Previous_Year_Closed_Opportunities__c  = totalSum;
        }
            update scope;
        }
        
      if (groupedResults[0].get('preamount') == NULL)
      {
       
        for(Account a : Scope)
        {
            a.Previous_Year_Closed_Opportunities__c  = NULL;
        }
            update scope;
        }   
        
        
      }  
    
    global void finish(Database.BatchableContext BC)
    {  
    }
}

Thanks
Sudhir
In my production organization I am facing Apex SOQL limit exception (too many soql queries 101). I tried lot of ways but not able to resolve it. Now I want to use Oracle cloud or other PaaS platform to replace SOQL with the data returned by REST or SOAP . Trying to impleatment this logic:-
Step 1)  Use metadata api to send all salesforce data to other platform
Step 2)  Use REST/SOAP to get all the data from third party(Oracle Cloud/Heroku).
Step 3)  Replace SOQL with this data.

I really have no idea how to start this.... any suggestion or help ?? 

 
Hello,

I have created a community and want to use google for login and register users. I have done following :-
 a) Created a google Cilent ID 
 b) Created Salesforce Auth. Provider
 c) Enabled Auth. Provider to my community and got a button on login page.
 
 But when I click on the button I redirect to gmail login page and then "401. That’s an error.Error: invalid_client no support email" error is thrown. 
 Please suggest any way.
 
 Thanks.User-added image
Hi, 

I wrote a below batch program which is working but bug i noticed is its updating common value to all the accounts which should not happen

example : account_ 1 has two opportunity with amount = 200
                 account_ 2 has one opportunity with amount = 100

When i run below batch it is update 200 as common to account_1 and account_2 which is a bug it should actiually update 200 for account_1  and 100 for account_1

Please suggest me how to get this fixed
global class batchpreamount implements Database.Batchable<sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'Select Id, Name, Previous_Year_Closed_Opportunities__c   from Account';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Account> scope)
    {
        List<Id> accIds = new List<Id>();
        for(Account a : scope)
        {
                accIds.add(a.id);
        }
            // query outside for loop
        List<AggregateResult> groupedResults = [ 
        SELECT sum(amount)preamount from opportunity 
                                     WHERE accountid in:accIds and
                                           isDeleted = false AND forecastcategoryname = 'commit' AND 
                                           closedate = LAST_YEAR];
                                       
                      
                                
      if (groupedResults[0].get('preamount') != NULL)
      {
       Decimal totalSum = Decimal.valueOf ( groupedResults[0].get('preamount') + '');

        for(Account a : Scope)
        {
            a.Previous_Year_Closed_Opportunities__c  = totalSum;
        }
            update scope;
        }
        
      if (groupedResults[0].get('preamount') == NULL)
      {
       
        for(Account a : Scope)
        {
            a.Previous_Year_Closed_Opportunities__c  = NULL;
        }
            update scope;
        }   
        
        
      }  
    
    global void finish(Database.BatchableContext BC)
    {  
    }
}

Thanks
Sudhir
Hello,

I have created a community and want to use google for login and register users. I have done following :-
 a) Created a google Cilent ID 
 b) Created Salesforce Auth. Provider
 c) Enabled Auth. Provider to my community and got a button on login page.
 
 But when I click on the button I redirect to gmail login page and then "401. That’s an error.Error: invalid_client no support email" error is thrown. 
 Please suggest any way.
 
 Thanks.User-added image