• KR_Force
  • NEWBIE
  • 50 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 25
    Replies
I tried in all API versions getting same error. any suggestion will be greathelfull
public without sharing class LeadXXXXXOwner {

public static List<Lead> leadXXXXXOwnerUpdate(List<Lead> nLst, Map<ID,Lead>oldMap){
        
        List<Lead>updLst= new List<Lead>();
        
        for( Lead l : nLst){
            Lead oldLead = oldMap.get(l.Id);
            if(Owner.profile.name.contains('XXXXX')|| Owner.name.contains('XXXXX')||Owner.profile.name.contains('XXXXX')|| Owner.name.contains('XXXXX')){
                l.Previous_Lead_Owner__c='XXXXXOwner::'+ Owner.Name;
            }
        }
        return updLst;
        
    }
}
 
  1. trigger MasterTrigger on Master__c (before delete, after insert) {
  2.  
  3.     if( trigger.isAfter){
  4.         TriggerHandler.SummaryRecords( trigger.new );
  5.     }
  6.     if(trigger.isBefore && trigger.isDelete){
  7.           if(Test.isRunningTest() && Limits.getFutureCalls() >= Limits.getLimitFutureCalls()){
  8.            system.debug(LoggingLevel.Error, 'Future method limit reached. Skipping...');
  9.          }
  10.        else {BUtil.DeleteService(trigger.oldMap.keySet());}
  11.            
  12.         }
  13. }Trigger
Not able to get around with line number line number and 10 due to that code coverage is not reaching the 75%, Can anyone suggest the trick to pass the through the if condition?
Class.TestEvalEndDateHTTPCallOut.testEVAlEndDateCallout: line 28, column 1
  1. @isTest
  2. public class TestEvalEndDateHTTPCallOut {
  3.     public static testmethod void testEVAlEndDateCallout() {
  4.         SingleRequestMock fakeResponse = new SingleRequestMock(200,
  5.                                                  'Complete',
  6.                                                  '[{"Name": "sForceTest1"}]',
  7.                                                  null);
  8.         Test.setMock(HttpCalloutMock.class, fakeResponse);
  9.         set<ID> ast=new Set<ID>();
  10.         Account a = new Account();
  11.         a.Name = 'test account';
  12.         a.Product_Subscriptions__c='test;test:';
  13.         insert a;
  14.         Asset a1 = new Asset(Name='testAsset', RVBD_Product_Family__c= 'test',IB_Status__c='Under Evaluation',Instance_Number__c='77777777XX',AccountID=a.id);
  15.         insert a1;
  16.         ast.add(a1.id);
  17.        
  18.         Contact foo = new Contact(FirstName = 'Foo', LastName='Bar');
  19.         insert foo;
  20.         Case c = new Case(Subject = 'Test case', ContactId=foo.id,AssetID=a1.id,AccountID=a.id);
  21.         Insert c;
  22.        
  23.         PageReference pageRef = Page.RefreshEvalEndDate;
  24.         Test.setCurrentPage(pageRef);
  25.         Apexpages.StandardController stdController = new Apexpages.StandardController(a1);
  26.         Apexpages.currentPage().getParameters().put('id',a1.Id);
  27.         EvalEndDateHTTPCallOut controller = new EvalEndDateHTTPCallOut(StdController);
  28.         controller.parseJSONResponse();
  29.         EvalEndDateHTTPCallOut.parseJSONResponseFuture(ast);
  30.       
  31.     }
  32. }
at line 25  method is not taking arguments,But my  actual method takes the arugments and throwing the exception on save "Illegal assignment from void to System.HttpResponse"
  1.     
  2.     @isTest
  3.         private class TestEvalEndDateHTTPCallOut {
  4.     
  5.        @isTest static void testCallout() {
  6.             set<ID> ast=new Set<ID>();
  7.             Test.setMock(WebServiceMock.class, new MockHttpResponseGenerator());
  8.             Account a = new Account();
  9.             a.Name = 'test account';
  10.             a.Product_Subscriptions__c='test;test:';
  11.             insert a;
  12.             Asset a1 = new Asset(Name='testAsset', RVBD_Product_Family__c= 'test',IB_Status__c='Under   Evaluation',Instance_Number__c='77777777XX',AccountID=a.id);
  13.             ast.add(a1.id);
  14.           
  15.             Contact foo = new Contact(FirstName = 'Foo', LastName='Bar');
  16.             insert foo;
  17.             Case c = new Case(Subject = 'Test case', ContactId=foo.id,AssetID=a1.id,AccountID=a.id);
  18.             Insert c;
  19.           
  20.             Http h = new Http();      
  21.             HttpRequest req1 = new HttpRequest();
  22.             req1.setEndpoint('http://mygreatservice.com/foo/bar');
  23.             req1.setMethod('POST');
  24.             //HttpResponse res1 = h.send(req1);
  25.             HttpResponse res1=EvalEndDateHTTPCallOut.parseJSONResponseFuture(ast);
  26.             String contentType = res1.getHeader('Content-Type');
  27.             System.assert(contentType == 'application/json');
  28.             String actualValue = res1.getBody();
  29.             String expectedValue = '{"foo":"bar"}';
  30.             System.assertEquals(actualValue, expectedValue);
  31.             System.assertEquals(200, res1.getStatusCode());
  32.         }
  33.     }
  34.  
  35. ============================================================================================
  36. Here is the class...
  37.  
  38. public class HTTPCallOutClass {
  39.  
  40.     private ApexPages.StandardController stdCtrl {get; set;}
  41.     public Asset ast { get; set; }
  42.     public String sn { get; set; }
  43.     //constructor to get the Asset record
  44.     public EvalEndDateHTTPCallOut(ApexPages.StandardController controller){
  45.         ast =  (Asset) controller.getRecord();
  46.         sn = ast.Name;
  47.         System.debug('The Asset record: ' + sn);
  48.     }
  49.     public PageReference parseJSONResponse() {     
  50.         Http httpProtocol = new Http();
  51.         String s=sn;
  52.         Date eDate;
  53.         Asset a = [Select Id, name,EvalEndDate__c from Asset where name=: sn];
  54.         // Create HTTP request to send.
  55.         HttpRequest request = new HttpRequest();
  56.      
  57.         String ENDPOINT=getUrl('test');
  58.         request.setEndpoint(endpoint+s);
  59.         // Set the HTTP verb to GET.
  60.         request.setMethod('GET');
  61.         request.setTimeout(60000);
  62.         // Send the HTTP request and get the response,The response is in JSON format.
  63.         HttpResponse response = httpProtocol.send(request);
  64.         system.debug(LoggingLevel.INFO,'response:'+response);
  65.         if(response!=null && response.getStatusCode()==200){
  66.             Map<String, Object> data = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());
  67.             system.debug(LoggingLevel.INFO,'response data:'+data);
  68.             system.debug(LoggingLevel.INFO,'ErrorID:'+(String)data.get('error_id'));
  69.             if(!string.IsBlank((String)data.get('evalDate'))){
  70.             eDate = Date.valueOf((String)data.get('evalDate'));
  71.             }
  72.         }
  73.         if (eDate!= null){
  74.                 system.debug(LoggingLevel.INFO,'GetResponse:'+response.getBody());
  75.                 a.EvalEndDate__c = eDate;
  76.                 update a;
  77.         }
  78.         system.debug('updated asset=' + a);
  79.         return new PageReference('/'+a.id);
  80.         }
  81.       
  82.     @future(callout=true)
  83.     public static void parseJSONResponseFuture(Set<Id> aIds){     
  84.         Http httpProtocol = new Http();
  85.      
  86.         List<Asset>asts=new List<Asset>([Select Id, name,EvalEndDate__c,SerialNumber from Asset where id in : aIds and Status__c='Evaluation']);
  87.         system.debug(LoggingLevel.INFO,'asts:'+asts);
  88.         For( Asset a:asts){
  89.         String s=a.name;
  90.         HttpRequest request = new HttpRequest();
  91.         String ENDPOINT=getUrl('test');
  92.         request.setEndpoint(endpoint+s);
  93.         request.setMethod('GET');
  94.         request.setTimeout(60000);
  95.         try{
  96.             if(!Test.isRunningTest()){
  97.          
  98.                 HttpResponse response = httpProtocol.send(request);
  99.                 system.debug(LoggingLevel.INFO,'response:'+response);
  100.                 Map<String, Object> data = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());
  101.                 system.debug(LoggingLevel.INFO,'response data:'+data);
  102.                 Date eDate= Date.valueOf((String)data.get('evalDate'));
  103.            
  104.         if (eDate!= null){
  105.                 system.debug(LoggingLevel.INFO,'GetResponse:'+response.getBody());
  106.                 a.EvalEndDate__c = eDate;
  107.                 update a;
  108.             }
  109.              system.debug('updated asset****=' + a);
  110.             }
  111.         }
  112.         catch (Exception e) {}
  113.         }
  114.         //update asts;
  115.         system.debug('updated assets=' + asts);
  116.     }
  117.      private static string getUrl(string serviceType){
  118.        Integration_Settings__c iProp=Integration_Settings__c.getValues('IntegrationEndPoints');
  119.         if(iprop != null){
  120.         if(serviceType.equalsIgnoreCase('test')){
  121.             return iProp.url__c;}
  122.         return ' ';
  123.         }
  124.         else {
  125.             return ' ';
  126.         }
  127.     }
  128. }
  129. =============================================================================================
  130. 1.parseJSONResponse() methog being invokde from Button
  131. 2. parseJSONResponseFuture() method from trigger
  132. =======================================================
  133. i started to buld the test class but im struck not able to proceed further, here is my test class. any help would be much appreciated.
  134.  
  135.  
  136. @isTest
  137. private class TestEvalEndDateHTTPCallOut {
  138.  
  139.    @isTest static void testCallout() {
  140.         set<ID> ast=new Set<ID>();
  141.         Test.setMock(WebServiceMock.class, new MockHttpResponseGenerator());
  142.         Account a = new Account();
  143.         a.Name = 'test account';
  144.         a.Product_Subscriptions__c='test;test:';
  145.         insert a;
  146.         Asset a1 = new Asset(Name='testAsset', RVBD_Product_Family__c= 'test',IB_Status__c='Under Evaluation',Instance_Number__c='77777777XX',AccountID=a.id);
  147.         ast.add(a1.id);
  148.         Http h = new Http();      
  149.         HttpRequest req1 = new HttpRequest();
  150.         req1.setEndpoint('http://mygreatservice.com/foo/bar');
  151.         req1.setMethod('POST');
  152.         HttpResponse res1 = h.send(req1);
  153.         String contentType = res1.getHeader('Content-Type');
  154.         System.assert(contentType == 'application/json');
  155.         String actualValue = res1.getBody();
  156.         String expectedValue = '{"foo":"bar"}';
  157.         System.assertEquals(actualValue, expectedValue);
  158.         System.assertEquals(200, res1.getStatusCode());
  159.     }
  160. }
Can someone please help to buld the test class for below batch class?

global class Batch1234 implements Database.Batchable<sobject>, Database.Stateful
{
    public String query;
    global String error;
    global database.queryLocator start(Database.BatchableContext BC)
    {       String query = 'select AccountId,Account.Product_Subscriptions__c, Id,oracle_product_family__c, Product_Family__c FROM Asset where oracle_product_family__c!= \'\'';
            return database.getQueryLocator(query); 
    } 
   
    global void execute(Database.BatchableContext BC, List<sObject> scope)
    { 
        List<asset> assetList =(List<Asset>)scope;
        set<id>acIDs=new set<Id>();
        Map<Id,Set<String>> actPsubs = new Map<Id,Set<String>>();
        List<Account> updateAccountList = new List<Account>();
        Map<Id,Account> updateAccountMap = new Map<Id,Account>();
        System.Debug('assetList ****'+assetList);
            for(Asset a :assetList){
                String prodstring='';
                set<string>unique=new set<String>(); 
                for(String s:a.oracle_product_family__c.split(':')){
                unique.add(s); 
                }
                if(a.Account.Product_Subscriptions__c!=null && a.Account.Product_Subscriptions__c!=''){
                    System.Debug('at#1 ****');
                    for(String Key:a.Account.Product_Subscriptions__c.split(';')){
                            unique.add(key);
                            System.Debug('at#2 ****');
                        } 
                    }
                if(unique.size()!=0){
                        for(String st : unique ){ 
                            prodstring = prodstring +';'+ st;
                        }
                    }
                System.Debug('prodstring****'+prodstring);
                updateAccountMap.put(a.AccountId,new Account(Id = a.AccountId, Product_Subscriptions__c = prodstring));
                }
                System.Debug('updateAccountMap ****'+updateAccountMap);
                if(updateAccountMap.size() != 0){
                Database.SaveResult[] srList = Database.update(updateAccountMap.values(), false);
                        for(Database.SaveResult sr : srList)
                        {
                            for(Database.Error e : sr.getErrors())
                            error += '\n ' + e.getMessage();
                        }
                    }
         
       }
   
    global void finish(Database.BatchableContext BC){
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { finish.Email(BC)});
   }  
}

===============================================================================================
test class
======================================================================

static testmethod void testBatchClass() {
           /*List <Asset> ast= new List<Asset>();
           Set<String> uniq=new Set<String>();
           Account a = new Account();
           a.Name = 'test account';
           insert a;
           for(integer i = 0; i<200; i++){
           Asset a1 = new Asset(Name='testAsset'+i, RVBD_Product_Family__c= 'test'+i+';',Instance_Number__c='77777777XX'+i,AccountID=a.id);
           ast.add(a1);
           uniq.add(a1.RVBD_Product_Family__c);
           }
           insert ast;
           String prodstring='';
           for(String st : uniq){ 
            prodstring = prodstring +';'+ st;
            }
            a.Product_Subscriptions__c=prodstring;
           
            Test.startTest();
            Batch1123 bc = new Batch123);
            bc.query = 'select AccountId, Id, Product_Family__c FROM Asset where AccountID=a.id limit 200';
            bc.error='TestError';
            ID batchprocessid = Database.executeBatch(bc);
            Test.stopTest();
Below is skipping the if  and else if condition line 25 and 29. and updating the zero records. any help will be much appriciated?

Note::Product_Subscriptions__c is a multi pick list field
  1. global class BatchAccountProductSubscriptions implements Database.Batchable<sobject>, Database.Stateful
  2. {
  3.     public String query;
  4.     global String error;
  5.     global database.queryLocator start(Database.BatchableContext BC)
  6.     {       String query = 'select AccountId, Id, Product_Family__c FROM Asset where Product_Family__c!=null limit 200';
  7.             return database.getQueryLocator(query);
  8.     }
  9.    
  10.     global void execute(Database.BatchableContext BC, List<sObject> scope)
  11.     {
  12.         List<asset> assetList =(List<Asset>)scope; 
  13.         set<id>acIDs=new set<Id>();
  14.         Map<Id,Set<String>> actPsubs = new Map<Id,Set<String>>();
  15.         Map<id,string> accProdFamily = new Map<id,string>();
  16.         Map<id,Asset> aidAssetMap = new Map<id,Asset>();
  17.         List<Account> updateAccountList = new List<Account>();
  18.         boolean isUpdate = false;
  19.         try
  20.         {   System.Debug('assetList ****'+assetList);
  21.             for(Asset a :assetList){aidAssetMap.put(a.AccountId,a);}
  22.             list<Account> act =[select Id, Product_Subscriptions__c FROM account where id in:aidAssetMap.keyset()];
  23.             for(Account ac:act){
  24.             string prodstring ='';
  25.             if(!ac.Product_Subscriptions__c.contains(aidAssetMap.get(ac.id).Product_Family__c) && (ac.Product_Subscriptions__c<>''|| ac.Product_Subscriptions__c!=null ))
  26.            {   System.Debug('Product_Subscriptions__c Match not Found ');
  27.                 prodstring=ac.Product_Subscriptions__c+';'+aidAssetMap.get(ac.id).Product_Family__c;
  28.             }
  29.             else if(!ac.Product_Subscriptions__c.contains(aidAssetMap.get(ac.id).Product_Family__c) && (ac.Product_Subscriptions__c=='' || ac.Product_Subscriptions__c==null))
  30.             {   System.Debug('Product_Subscriptions__c Match Found ');
  31.                 prodstring=aidAssetMap.get(ac.id).Product_Family__c;
  32.             }
  33.             updateAccountList.add(new Account(Id = ac.id, Product_Subscriptions__c = prodstring));
  34.             }
  35.              System.Debug('updateAccountList ****'+updateAccountList);
  36.             if(updateAccountList.size() != 0){
  37.                Database.SaveResult[] srList = Database.update(updateAccountList, false);
  38.                         for(Database.SaveResult sr : srList)
  39.                         {
  40.                             for(Database.Error e : sr.getErrors())
  41.                             error += '\n ' + e.getMessage();
  42.                         }
  43.                     }
  44.             }
  45.         catch(Exception e)
  46.         {
  47.             error += e.getMessage();
  48.         }
  49.     }
  50.     global void finish(Database.BatchableContext BC)
  51.     {
  52.         AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email from AsyncApexJob where Id =: BC.getJobId()];
  53.         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
  54.         String[] toEmailAddresses = new String[] {'XXXXXXXXXXXXXXXXXXXXX'};
  55.         mail.setToAddresses(toEmailAddresses);
  56.         mail.setSubject('BatchJob Status' + a.Status);
  57.         mail.setHTMLBody
  58.         ('Total No of Batch Apex job processed ' + a.TotalJobItems +
  59.         ' batches with '+ a.NumberOfErrors + ' failures.');
  60.         Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
  61.     }
  62. }
I'm actually trying to get the assets from the map based on account ID and loop through the values to get the Product_Family__c.

Map<ID,Asset>actAstMap=new Map<ID,Asset>();
for (Asset a1: actAstMap.get(ActID)){
if(a1.Product_Family__c!=null ||a1.Product_Family__c<>''){
        pFamily.add(a1.Product_Family__c);
}
}

Any help will be much apprecitated.
Can someone please help with this error?
An Error occured at trigger XXXXXXX on contact:System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)

Here is my code, im calling this method from before insert and before update trigger.

*****ANY HELP WILL BE MUCH APPRICITED*******
  1.     public static void ContactProductSubscription(List<Contact>newcontacts,set<ID>acIds){
  2.         //set<id>acIds=new set<Id>();
  3.         set<id>acIds1=new set<Id>();
  4.         list<Asset>ast=new List<Asset>();
  5.         List<Linked_Account__c>lActs=new List<Linked_Account__c>();
  6.         List<Linked_Account__c>linkedAccounts=new List<Linked_Account__c>();
  7.         Map<Id,Id>actLActMap=new Map<Id,Id>();
  8.         Map<Id,Id>agentctLActMap=new Map<Id,Id>();
  9.         Map<Id,ID>alActs=new Map<Id,ID>();
  10.         Map<Id,Id>conActMap=new Map<Id,Id>();
  11.         Map<ID,String>ActPfamilyMap=new Map<ID,String>();
  12.         Map<ID,ID>lActAgentcontMap=new Map<ID,ID>();
  13.         Map<ID,ID>lActAcontMap=new Map<ID,ID>();
  14.         Map<ID,Asset>actAstMap=new Map<ID,Asset>();
  15.         set<id>aContacts=new set<id>();//Agent Contacts
  16.         set<string>pFamily=new set<string>();//Agent Contacts
  17.         String psubscription;
  18.          for(contact c :newcontacts){conActMap.put(c.id,c.accountID);}
  19.             if(acids.size()>0){
  20.                 lActs=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
  21.                 Cases__c, Contacts__c, Expiration__c, Linked_Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
  22.                 where Agent__c=true and  Contacts__c=true and (Expiration__c<>null OR Expiration__c >: date.today()) and Linked_Account__c in:acids ];
  23.             }
  24.             if(lActs.size()>0){
  25.             for(Linked_Account__c l:lActs){
  26.                 aContacts.add(l.Agent_Contact__c);
  27.                 actLActMap.put(l.Linked_Account__c,l.id);
  28.                 agentctLActMap.put(l.Agent_Contact__c,l.id);
  29.               
  30.                 }
  31.             } 
  32.             if(aContacts.size()>0){
  33.                 linkedAccounts=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
  34.                 Cases__c, Contacts__c, Expiration__c, Linked_Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
  35.                 where Agent__c=false and  isDeleted=false and Agent_Contact__c in:aContacts];
  36.             }
  37.             if(linkedAccounts.size()>0){
  38.             For(Linked_Account__c l1:linkedAccounts){
  39.                 acIds1.add(l1.Linked_Account__c);
  40.                 lActAgentcontMap.put(l1.Linked_Account__c,l1.Agent_Contact__c);
  41.                 lActAcontMap.put(l1.id,l1.Linked_Account__c);
  42.                 //agentctLActMap.put(l1.Agent_Contact__c,l1.id);
  43.           }
  44.             }
  45.             acIds1.addAll(acIds);
  46.             if(acIds1.size()>0){ast=[select AccountId, Id, Product_Family__c FROM Asset where AccountId in:acIds1];}
  47.             for(Asset a:ast){ActPfamilyMap.put(a.AccountId,a.Product_Family__c);
  48.             actAstMap.put(a.AccountId,a);}
  49.             for(contact c :newcontacts){
  50.             Id lactID=actLActMap.get(c.AccountID);
  51.             ID aContID=lActAgentcontMap.get(lactID);
  52.             ID lactID1=agentctLActMap.get(aContID);
  53.             ID ActID=lActAcontMap.get(lactID1);
  54.             if(ActPfamilyMap.containsKey(ActID)||ActPfamilyMap.containsKey(c.AccountID)){
  55.             for(Asset a1:[select AccountId, Id, Product_Family__c FROM Asset where AccountId =: c.AccountID OR AccountId=:ActID]){
  56.              psubscription+=a1.Product_Family__c+'; ';
  57.              c.productSubscriptions__c=psubscription;
  58.             }
  59.         
  60.             }
  61.          }
  62.       }
Need to auto populate productionsubscription__c(multi piclist on contact). all i have to do is based on Contact.AccountID i need to pull the Linked accounts and
1.Filter those linked accounts by agent_c == true && cases__c == true && expiration__c > today (or expiration_c empty) 
2. Get the agents of the of the linked accounts filtered in the previous step (i.e. a list of all linkedAccount.agent_Contact__c).
 
3. Get the linked accounts of the agents gotten in the previous step. and
select LINKED_ACCOUNT_FIELDS
from Linked_account__c
where isDeleted = false
and Agent__c = false
and Agent_Contact__c in (STEP_2_AGENTS)
Step 4: for all these linked account.AccountS and Contact.AccountID need to query the asset with product familiy field and get the uniq value and populate contact productSubscription__c field.

I'mcalling this method from before insert trigger.

*****ANY HELP WILL BE MUCH APPRICITED*******
  1. public static void ContactProductSubscription(List<Contact>newcontacts,set<ID>acIds){
  2.     //set<id>acIds=new set<Id>();
  3.     set<id>acIds1=new set<Id>();
  4.     list<Asset>ast=new List<Asset>();
  5.     List<Linked_Account__c>lActs=new List<Linked_Account__c>();
  6.     List<Linked_Account__c>linkedAccounts=new List<Linked_Account__c>();
  7.     Map<Id,Linked_Account__c>actLActMap=new Map<Id,Linked_Account__c>();
  8.     Map<Id,ID>alActs=new Map<Id,ID>();
  9.     Map<Id,Id>conActMap=new Map<Id,Id>();
  10.     Map<ID,String>ActPfamilyMap=new Map<ID,String>();
  11.     set<id>aContacts=new set<id>();//Agent Contacts
  12.    
  13.     for(contact c :newcontacts){conActMap.put(c.id,c.accountID);}
  14.      if(acids.size()>0){
  15.       lActs=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
  16.       Cases__c, Contacts__c, Expiration__c, Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
  17.       where Agent__c=true and  Contacts__c=true and (Expiration__c<>null OR Expiration__c >: date.today()) and Linked_Account__c in:acids ];
  18.      }
  19.      if(lActs.size()>0){
  20.      for(Linked_Account__c l:lActs){
  21.       aContacts.add(l.Agent_Contact__c);
  22.       actLActMap.put(l.Linked_Account__c,l);
  23.      
  24.       }
  25.      }
  26.      if(aContacts.size()>0){
  27.       linkedAccounts=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
  28.       Cases__c, Contacts__c, Expiration__c, Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
  29.       where Agent__c=false and  isDeleted=false and Agent_Contact__c in:aContacts];
  30.      }
  31.      if(linkedAccounts.size()>0){
  32.      For(Linked_Account__c l1:linkedAccounts){
  33.       acIds1.add(l1.Account__c);
  34.       //aContact.put(l1.Agent_Contact__c,l1.Account__c);
  35.      }
  36.      }
  37.      acIds1.addAll(acIds);
  38.      String psubscription;
  39.      if(acIds1.size()>0){ast=[select AccountId, Id, Product_Family__c FROM Asset where AccountId in:acIds1];}
  40.      for(Asset a:ast){ActPfamilyMap.put(a.AccountId,a.Product_Family__c);}
  41.      for(contact c :newcontacts){
  42.       list<Linked_Account__c>l1=actLActMap.get(c.AccountId);
  43.       set<id>acts=add(c.accountid);
  44.      for(Linked_Account__c l:l1){acts.add(alActs.get(l.Agent_Contact__c));
  45.       List<Asset>ast=ActPfamilyMap.get(acts);
  46.       }
  47.      for(Asset a1:ast){
  48.      psubscription+=a1.Product_Family__c+'; ';}
  49.      c.productSubscriptions__c=psubscription;
  50.      }
  51.    }

Hi, in below method  Ultimate_Parent_Revenue__c field is getting updated fine but  the "Ultimate_Parent_Vertical__c" field is not getting updated at all . i see the value coming in for 'Parent.OS_Industry_Sector__c' but its not refelecting on "Ultimate_Parent_Vertical__c". can someone please into it and help to fix the issue?
  1. for(Account a: uChild)
  2.                {
  3.                 //Account uParent = uChildMap.get(a.id);
  4.                 //System.debug('Parent ID**:'+ a.ParentId);
  5.                 if (a.ParentId ==null){
  6.                 System.debug('Condition 6**:');
  7.                     a.Ultimate_Parent_Vertical__c = a.OS_Industry_Sector__c;
  8.                     a.Ultimate_Parent_Revenue__c = a.AnnualRevenue;
  9.                    // uChild1.add(a);
  10.                     }
  11.                 else if (a.Parent.ParentId ==null){
  12.                 System.debug('Condition 7**:'+a.Parent.OS_Industry_Sector__c+a.Parent.AnnualRevenue);
  13.                    a.Ultimate_Parent_Vertical__c = a.Parent.OS_Industry_Sector__c;
  14.                          a.Ultimate_Parent_Revenue__c = a.Parent.AnnualRevenue;
  15.                           //uChild1.add(a);
  16.                          }
  17.                 else if (a.Parent.Parent.ParentId ==null){
  18.                 System.debug('Condition 8**:');
  19.                          a.Ultimate_Parent_Vertical__c = a.Parent.Parent.OS_Industry_Sector__c;
  20.                          a.Ultimate_Parent_Revenue__c = a.Parent.Parent.AnnualRevenue;
  21.                          //uChild1.add(a);
  22.                          }
  23.                 else if (a.Parent.Parent.Parent.ParentId ==null){
  24.                 System.debug('Condition 9**:');
  25.                          a.Ultimate_Parent_Vertical__c = a.Parent.Parent.Parent.OS_Industry_Sector__c;
  26.                          a.Ultimate_Parent_Revenue__c = a.Parent.Parent.Parent.AnnualRevenue;
  27.                           //uChild1.add(a);
  28.                          }
  29.                 else if (a.Parent.Parent.Parent.Parent.ParentId ==null){
  30.                 System.debug('Condition 10**:');
  31.                          a.Ultimate_Parent_Vertical__c = a.Parent.Parent.Parent.Parent.OS_Industry_Sector__c;
  32.                          a.Ultimate_Parent_Revenue__c = a.Parent.Parent.Parent.Parent.AnnualRevenue;
  33.                          //uChild1.add(a);
  34.                          }
  35.                }
  36.                Update uChild;
  37.                }
Here is my method, code works fine till line 65 and its getting executed the conditions 6 to 10(debug staments) but the fields are not getting updated , any clue?
  1.   public static void AccountUltimateRevenue(Map<ID,Account> newActMap,Map<ID,Account> oldActMap,List<Account>newActList){
  2.            List<Account>actList=new List<Account>();
  3.            List<Account>aList;
  4.            Set<ID>parentActList=new Set<ID>();
  5.            List<Account>uParents=new List<Account>();
  6.            Map<ID, List<Account>> uActListMap = new Map<ID, List<Account>>();
  7.             for(Account a:newActList) 
  8.             {
  9.             Account a1=oldActMap.get(a.id);
  10.            // To check whether Parent Account was updated and not null
  11.            if((newActMap.get(a.Id).parentID!=oldActMap.get(a.Id).parentID && newActMap.get(a.Id).parentID<>null))
  12.             {
  13.             ActList.add(a);
  14.             parentActList.add(newActMap.get(a.Id).parentID);
  15.             System.debug('old+++++++++'+a1.parentID+'new++++++++++++++++'+a.parentID);
  16.             System.debug('ActList+++++++++'+ActList);
  17.             }
  18.             else 
  19.             if(newActMap.get(a.Id).parentID==null)
  20.             {   System.debug('No Parent**:');
  21.              uParents.add(a);
  22.                
  23.             }
  24.      }       
  25.    // Checking if Parent Account list not null pulling all corresponding Ultimate parent revenue and Ultimate parent vertical values from parent accounts.
  26.         if(parentActList!= null && parentActList.size()>0){
  27.             //system.debug( 'Parent Account list:'+parentActList);               
  28.             map<Id, Account> uActMap=new map<Id, Account>([select Id,AnnualRevenue,OS_Industry_Sector__c, Ultimate_Parent_Vertical__c, Ultimate_Parent_Revenue__c,
  29.                                                            ParentId, Parent.OS_Industry_Sector__c, Parent.AnnualRevenue,
  30.                                                            Parent.ParentId, Parent.Parent.OS_Industry_Sector__c, Parent.Parent.AnnualRevenue,
  31.                                                            Parent.Parent.ParentId, Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.AnnualRevenue,
  32.                                                            Parent.Parent.Parent.ParentId, Parent.Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.Parent.AnnualRevenue
  33.                                                            from Account where ID IN :parentActList]);     
  34.                for(Account a: newActList)
  35.                {
  36.                 Account ParentAccount = uActMap.get(a.ParentId);
  37.                 System.debug('Parent ID**:'+ a.ParentId);
  38.                 if (ParentAccount.ParentId ==null){
  39.                 System.debug('Condition 1**:');
  40.                     a.Ultimate_Parent_Vertical__c = ParentAccount.OS_Industry_Sector__c;
  41.                     a.Ultimate_Parent_Revenue__c = ParentAccount.AnnualRevenue;
  42.                     }
  43.                 else if (ParentAccount.Parent.ParentId ==null){
  44.                 System.debug('Condition 2**:');
  45.                          a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.OS_Industry_Sector__c;
  46.                          a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.AnnualRevenue;
  47.                          }
  48.                 else if (ParentAccount.Parent.Parent.ParentId ==null){
  49.                 System.debug('Condition 3**:');
  50.                          a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.Parent.OS_Industry_Sector__c;
  51.                          a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.Parent.AnnualRevenue;
  52.                          }
  53.                 else if (ParentAccount.Parent.Parent.Parent.ParentId ==null){
  54.                 System.debug('Condition 4**:');
  55.                          a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.Parent.Parent.OS_Industry_Sector__c;
  56.                          a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.Parent.Parent.AnnualRevenue;
  57.                          }
  58.                 else if (ParentAccount.Parent.Parent.Parent.Parent.ParentId ==null){
  59.                 System.debug('Condition 5**:');
  60.                          a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.Parent.Parent.Parent.OS_Industry_Sector__c;
  61.                          a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.Parent.Parent.Parent.AnnualRevenue;
  62.                          }
  63.                }
  64.         }
  65.                              
  66.                 if(uParents.size()>0)
  67.                 {  
  68.                  List<Account> uChild=new List<Account>([select Id,AnnualRevenue,OS_Industry_Sector__c, Ultimate_Parent_Vertical__c, Ultimate_Parent_Revenue__c,
  69.                                                            ParentId, Parent.OS_Industry_Sector__c, Parent.AnnualRevenue,
  70.                                                            Parent.ParentId, Parent.Parent.OS_Industry_Sector__c, Parent.Parent.AnnualRevenue,
  71.                                                            Parent.Parent.ParentId, Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.AnnualRevenue,
  72.                                                            Parent.Parent.Parent.ParentId, Parent.Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.Parent.AnnualRevenue from Account where ParentId IN :uParents OR Parent.ParentId IN :uParents OR Parent.Parent.ParentId IN :uParents OR Parent.Parent.Parent.ParentId IN :uParents]);
  73.            for(Account a: uChild)
  74.                {
  75.                if (a.ParentId ==null){
  76.                 System.debug('Condition 6**:');
  77.                     a.Ultimate_Parent_Vertical__c = a.OS_Industry_Sector__c;
  78.                     a.Ultimate_Parent_Revenue__c = a.AnnualRevenue;
  79.                     }
  80.                 else if (a.Parent.ParentId ==null){
  81.                 System.debug('Condition 7**:'+a.Parent.OS_Industry_Sector__c+a.Parent.AnnualRevenue);
  82.                   //a.Ultimate_Parent_Vertical__c = a.Parent.OS_Industry_Sector__c;
  83.                          a.Ultimate_Parent_Vertical__c = a.Parent.OS_Industry_Sector__c;
  84.                          a.Ultimate_Parent_Revenue__c = a.Parent.AnnualRevenue;
  85.                          }
  86.                 else if (a.Parent.Parent.ParentId ==null){
  87.                 System.debug('Condition 8**:');
  88.                          a.Ultimate_Parent_Vertical__c = a.Parent.Parent.OS_Industry_Sector__c;
  89.                          a.Ultimate_Parent_Revenue__c = a.Parent.Parent.AnnualRevenue;
  90.                          }
  91.                 else if (a.Parent.Parent.Parent.ParentId ==null){
  92.                 System.debug('Condition 9**:');
  93.                          a.Ultimate_Parent_Vertical__c = a.Parent.Parent.Parent.OS_Industry_Sector__c;
  94.                          a.Ultimate_Parent_Revenue__c = a.Parent.Parent.Parent.AnnualRevenue;
  95.                          }
  96.                 else if (a.Parent.Parent.Parent.Parent.ParentId ==null){
  97.                 System.debug('Condition 10**:');
  98.                          a.Ultimate_Parent_Vertical__c = a.Parent.Parent.Parent.Parent.OS_Industry_Sector__c;
  99.                          a.Ultimate_Parent_Revenue__c = a.Parent.Parent.Parent.Parent.AnnualRevenue;
  100.                          }
  101.                }
  102.                }
  103.                
  104.            
  105.         }
Can anyone please look into this and help to find the error?  code works perfectly fine when i validate only one profile ID in the 'IF' condition when add other 2 profile ID's its not respecting the conditions and leting all actions entering to into the IF.


{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')}

var sr = new sforce.SObject("Contract");

sr.Status = "{!Contract.Status}";
var initial = sr.Status;
if ( '{!$User.ProfileId}'!='00e30000000bqt9'|| '{!$User.ProfileId}' !='00e80000001BvTe'||'{!$User.ProfileId}' != '00eA0000000MKTH')
{
alert('{!$User.ProfileId}');
alert('You are not authorized to cancel the agreement ...........');
window.parent.location.href=window.parent.location.href;
}
else
{
if(initial=='Draft'||initial=='Executed')
{
var sr = new sforce.SObject("Contract");
sr.id = "{!Contract.Id}";
sr.Status = 'Cancelled';
result = sforce.connection.update([sr]);
window.location.reload();
}
else
{
alert("You cannot cancel expired agreements.");
}
}
I tried in all API versions getting same error. any suggestion will be greathelfull
public without sharing class LeadXXXXXOwner {

public static List<Lead> leadXXXXXOwnerUpdate(List<Lead> nLst, Map<ID,Lead>oldMap){
        
        List<Lead>updLst= new List<Lead>();
        
        for( Lead l : nLst){
            Lead oldLead = oldMap.get(l.Id);
            if(Owner.profile.name.contains('XXXXX')|| Owner.name.contains('XXXXX')||Owner.profile.name.contains('XXXXX')|| Owner.name.contains('XXXXX')){
                l.Previous_Lead_Owner__c='XXXXXOwner::'+ Owner.Name;
            }
        }
        return updLst;
        
    }
}
 
Class.TestEvalEndDateHTTPCallOut.testEVAlEndDateCallout: line 28, column 1
  1. @isTest
  2. public class TestEvalEndDateHTTPCallOut {
  3.     public static testmethod void testEVAlEndDateCallout() {
  4.         SingleRequestMock fakeResponse = new SingleRequestMock(200,
  5.                                                  'Complete',
  6.                                                  '[{"Name": "sForceTest1"}]',
  7.                                                  null);
  8.         Test.setMock(HttpCalloutMock.class, fakeResponse);
  9.         set<ID> ast=new Set<ID>();
  10.         Account a = new Account();
  11.         a.Name = 'test account';
  12.         a.Product_Subscriptions__c='test;test:';
  13.         insert a;
  14.         Asset a1 = new Asset(Name='testAsset', RVBD_Product_Family__c= 'test',IB_Status__c='Under Evaluation',Instance_Number__c='77777777XX',AccountID=a.id);
  15.         insert a1;
  16.         ast.add(a1.id);
  17.        
  18.         Contact foo = new Contact(FirstName = 'Foo', LastName='Bar');
  19.         insert foo;
  20.         Case c = new Case(Subject = 'Test case', ContactId=foo.id,AssetID=a1.id,AccountID=a.id);
  21.         Insert c;
  22.        
  23.         PageReference pageRef = Page.RefreshEvalEndDate;
  24.         Test.setCurrentPage(pageRef);
  25.         Apexpages.StandardController stdController = new Apexpages.StandardController(a1);
  26.         Apexpages.currentPage().getParameters().put('id',a1.Id);
  27.         EvalEndDateHTTPCallOut controller = new EvalEndDateHTTPCallOut(StdController);
  28.         controller.parseJSONResponse();
  29.         EvalEndDateHTTPCallOut.parseJSONResponseFuture(ast);
  30.       
  31.     }
  32. }
at line 25  method is not taking arguments,But my  actual method takes the arugments and throwing the exception on save "Illegal assignment from void to System.HttpResponse"
  1.     
  2.     @isTest
  3.         private class TestEvalEndDateHTTPCallOut {
  4.     
  5.        @isTest static void testCallout() {
  6.             set<ID> ast=new Set<ID>();
  7.             Test.setMock(WebServiceMock.class, new MockHttpResponseGenerator());
  8.             Account a = new Account();
  9.             a.Name = 'test account';
  10.             a.Product_Subscriptions__c='test;test:';
  11.             insert a;
  12.             Asset a1 = new Asset(Name='testAsset', RVBD_Product_Family__c= 'test',IB_Status__c='Under   Evaluation',Instance_Number__c='77777777XX',AccountID=a.id);
  13.             ast.add(a1.id);
  14.           
  15.             Contact foo = new Contact(FirstName = 'Foo', LastName='Bar');
  16.             insert foo;
  17.             Case c = new Case(Subject = 'Test case', ContactId=foo.id,AssetID=a1.id,AccountID=a.id);
  18.             Insert c;
  19.           
  20.             Http h = new Http();      
  21.             HttpRequest req1 = new HttpRequest();
  22.             req1.setEndpoint('http://mygreatservice.com/foo/bar');
  23.             req1.setMethod('POST');
  24.             //HttpResponse res1 = h.send(req1);
  25.             HttpResponse res1=EvalEndDateHTTPCallOut.parseJSONResponseFuture(ast);
  26.             String contentType = res1.getHeader('Content-Type');
  27.             System.assert(contentType == 'application/json');
  28.             String actualValue = res1.getBody();
  29.             String expectedValue = '{"foo":"bar"}';
  30.             System.assertEquals(actualValue, expectedValue);
  31.             System.assertEquals(200, res1.getStatusCode());
  32.         }
  33.     }
  34.  
  35. ============================================================================================
  36. Here is the class...
  37.  
  38. public class HTTPCallOutClass {
  39.  
  40.     private ApexPages.StandardController stdCtrl {get; set;}
  41.     public Asset ast { get; set; }
  42.     public String sn { get; set; }
  43.     //constructor to get the Asset record
  44.     public EvalEndDateHTTPCallOut(ApexPages.StandardController controller){
  45.         ast =  (Asset) controller.getRecord();
  46.         sn = ast.Name;
  47.         System.debug('The Asset record: ' + sn);
  48.     }
  49.     public PageReference parseJSONResponse() {     
  50.         Http httpProtocol = new Http();
  51.         String s=sn;
  52.         Date eDate;
  53.         Asset a = [Select Id, name,EvalEndDate__c from Asset where name=: sn];
  54.         // Create HTTP request to send.
  55.         HttpRequest request = new HttpRequest();
  56.      
  57.         String ENDPOINT=getUrl('test');
  58.         request.setEndpoint(endpoint+s);
  59.         // Set the HTTP verb to GET.
  60.         request.setMethod('GET');
  61.         request.setTimeout(60000);
  62.         // Send the HTTP request and get the response,The response is in JSON format.
  63.         HttpResponse response = httpProtocol.send(request);
  64.         system.debug(LoggingLevel.INFO,'response:'+response);
  65.         if(response!=null && response.getStatusCode()==200){
  66.             Map<String, Object> data = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());
  67.             system.debug(LoggingLevel.INFO,'response data:'+data);
  68.             system.debug(LoggingLevel.INFO,'ErrorID:'+(String)data.get('error_id'));
  69.             if(!string.IsBlank((String)data.get('evalDate'))){
  70.             eDate = Date.valueOf((String)data.get('evalDate'));
  71.             }
  72.         }
  73.         if (eDate!= null){
  74.                 system.debug(LoggingLevel.INFO,'GetResponse:'+response.getBody());
  75.                 a.EvalEndDate__c = eDate;
  76.                 update a;
  77.         }
  78.         system.debug('updated asset=' + a);
  79.         return new PageReference('/'+a.id);
  80.         }
  81.       
  82.     @future(callout=true)
  83.     public static void parseJSONResponseFuture(Set<Id> aIds){     
  84.         Http httpProtocol = new Http();
  85.      
  86.         List<Asset>asts=new List<Asset>([Select Id, name,EvalEndDate__c,SerialNumber from Asset where id in : aIds and Status__c='Evaluation']);
  87.         system.debug(LoggingLevel.INFO,'asts:'+asts);
  88.         For( Asset a:asts){
  89.         String s=a.name;
  90.         HttpRequest request = new HttpRequest();
  91.         String ENDPOINT=getUrl('test');
  92.         request.setEndpoint(endpoint+s);
  93.         request.setMethod('GET');
  94.         request.setTimeout(60000);
  95.         try{
  96.             if(!Test.isRunningTest()){
  97.          
  98.                 HttpResponse response = httpProtocol.send(request);
  99.                 system.debug(LoggingLevel.INFO,'response:'+response);
  100.                 Map<String, Object> data = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());
  101.                 system.debug(LoggingLevel.INFO,'response data:'+data);
  102.                 Date eDate= Date.valueOf((String)data.get('evalDate'));
  103.            
  104.         if (eDate!= null){
  105.                 system.debug(LoggingLevel.INFO,'GetResponse:'+response.getBody());
  106.                 a.EvalEndDate__c = eDate;
  107.                 update a;
  108.             }
  109.              system.debug('updated asset****=' + a);
  110.             }
  111.         }
  112.         catch (Exception e) {}
  113.         }
  114.         //update asts;
  115.         system.debug('updated assets=' + asts);
  116.     }
  117.      private static string getUrl(string serviceType){
  118.        Integration_Settings__c iProp=Integration_Settings__c.getValues('IntegrationEndPoints');
  119.         if(iprop != null){
  120.         if(serviceType.equalsIgnoreCase('test')){
  121.             return iProp.url__c;}
  122.         return ' ';
  123.         }
  124.         else {
  125.             return ' ';
  126.         }
  127.     }
  128. }
  129. =============================================================================================
  130. 1.parseJSONResponse() methog being invokde from Button
  131. 2. parseJSONResponseFuture() method from trigger
  132. =======================================================
  133. i started to buld the test class but im struck not able to proceed further, here is my test class. any help would be much appreciated.
  134.  
  135.  
  136. @isTest
  137. private class TestEvalEndDateHTTPCallOut {
  138.  
  139.    @isTest static void testCallout() {
  140.         set<ID> ast=new Set<ID>();
  141.         Test.setMock(WebServiceMock.class, new MockHttpResponseGenerator());
  142.         Account a = new Account();
  143.         a.Name = 'test account';
  144.         a.Product_Subscriptions__c='test;test:';
  145.         insert a;
  146.         Asset a1 = new Asset(Name='testAsset', RVBD_Product_Family__c= 'test',IB_Status__c='Under Evaluation',Instance_Number__c='77777777XX',AccountID=a.id);
  147.         ast.add(a1.id);
  148.         Http h = new Http();      
  149.         HttpRequest req1 = new HttpRequest();
  150.         req1.setEndpoint('http://mygreatservice.com/foo/bar');
  151.         req1.setMethod('POST');
  152.         HttpResponse res1 = h.send(req1);
  153.         String contentType = res1.getHeader('Content-Type');
  154.         System.assert(contentType == 'application/json');
  155.         String actualValue = res1.getBody();
  156.         String expectedValue = '{"foo":"bar"}';
  157.         System.assertEquals(actualValue, expectedValue);
  158.         System.assertEquals(200, res1.getStatusCode());
  159.     }
  160. }
Can someone please help to buld the test class for below batch class?

global class Batch1234 implements Database.Batchable<sobject>, Database.Stateful
{
    public String query;
    global String error;
    global database.queryLocator start(Database.BatchableContext BC)
    {       String query = 'select AccountId,Account.Product_Subscriptions__c, Id,oracle_product_family__c, Product_Family__c FROM Asset where oracle_product_family__c!= \'\'';
            return database.getQueryLocator(query); 
    } 
   
    global void execute(Database.BatchableContext BC, List<sObject> scope)
    { 
        List<asset> assetList =(List<Asset>)scope;
        set<id>acIDs=new set<Id>();
        Map<Id,Set<String>> actPsubs = new Map<Id,Set<String>>();
        List<Account> updateAccountList = new List<Account>();
        Map<Id,Account> updateAccountMap = new Map<Id,Account>();
        System.Debug('assetList ****'+assetList);
            for(Asset a :assetList){
                String prodstring='';
                set<string>unique=new set<String>(); 
                for(String s:a.oracle_product_family__c.split(':')){
                unique.add(s); 
                }
                if(a.Account.Product_Subscriptions__c!=null && a.Account.Product_Subscriptions__c!=''){
                    System.Debug('at#1 ****');
                    for(String Key:a.Account.Product_Subscriptions__c.split(';')){
                            unique.add(key);
                            System.Debug('at#2 ****');
                        } 
                    }
                if(unique.size()!=0){
                        for(String st : unique ){ 
                            prodstring = prodstring +';'+ st;
                        }
                    }
                System.Debug('prodstring****'+prodstring);
                updateAccountMap.put(a.AccountId,new Account(Id = a.AccountId, Product_Subscriptions__c = prodstring));
                }
                System.Debug('updateAccountMap ****'+updateAccountMap);
                if(updateAccountMap.size() != 0){
                Database.SaveResult[] srList = Database.update(updateAccountMap.values(), false);
                        for(Database.SaveResult sr : srList)
                        {
                            for(Database.Error e : sr.getErrors())
                            error += '\n ' + e.getMessage();
                        }
                    }
         
       }
   
    global void finish(Database.BatchableContext BC){
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { finish.Email(BC)});
   }  
}

===============================================================================================
test class
======================================================================

static testmethod void testBatchClass() {
           /*List <Asset> ast= new List<Asset>();
           Set<String> uniq=new Set<String>();
           Account a = new Account();
           a.Name = 'test account';
           insert a;
           for(integer i = 0; i<200; i++){
           Asset a1 = new Asset(Name='testAsset'+i, RVBD_Product_Family__c= 'test'+i+';',Instance_Number__c='77777777XX'+i,AccountID=a.id);
           ast.add(a1);
           uniq.add(a1.RVBD_Product_Family__c);
           }
           insert ast;
           String prodstring='';
           for(String st : uniq){ 
            prodstring = prodstring +';'+ st;
            }
            a.Product_Subscriptions__c=prodstring;
           
            Test.startTest();
            Batch1123 bc = new Batch123);
            bc.query = 'select AccountId, Id, Product_Family__c FROM Asset where AccountID=a.id limit 200';
            bc.error='TestError';
            ID batchprocessid = Database.executeBatch(bc);
            Test.stopTest();
Below is skipping the if  and else if condition line 25 and 29. and updating the zero records. any help will be much appriciated?

Note::Product_Subscriptions__c is a multi pick list field
  1. global class BatchAccountProductSubscriptions implements Database.Batchable<sobject>, Database.Stateful
  2. {
  3.     public String query;
  4.     global String error;
  5.     global database.queryLocator start(Database.BatchableContext BC)
  6.     {       String query = 'select AccountId, Id, Product_Family__c FROM Asset where Product_Family__c!=null limit 200';
  7.             return database.getQueryLocator(query);
  8.     }
  9.    
  10.     global void execute(Database.BatchableContext BC, List<sObject> scope)
  11.     {
  12.         List<asset> assetList =(List<Asset>)scope; 
  13.         set<id>acIDs=new set<Id>();
  14.         Map<Id,Set<String>> actPsubs = new Map<Id,Set<String>>();
  15.         Map<id,string> accProdFamily = new Map<id,string>();
  16.         Map<id,Asset> aidAssetMap = new Map<id,Asset>();
  17.         List<Account> updateAccountList = new List<Account>();
  18.         boolean isUpdate = false;
  19.         try
  20.         {   System.Debug('assetList ****'+assetList);
  21.             for(Asset a :assetList){aidAssetMap.put(a.AccountId,a);}
  22.             list<Account> act =[select Id, Product_Subscriptions__c FROM account where id in:aidAssetMap.keyset()];
  23.             for(Account ac:act){
  24.             string prodstring ='';
  25.             if(!ac.Product_Subscriptions__c.contains(aidAssetMap.get(ac.id).Product_Family__c) && (ac.Product_Subscriptions__c<>''|| ac.Product_Subscriptions__c!=null ))
  26.            {   System.Debug('Product_Subscriptions__c Match not Found ');
  27.                 prodstring=ac.Product_Subscriptions__c+';'+aidAssetMap.get(ac.id).Product_Family__c;
  28.             }
  29.             else if(!ac.Product_Subscriptions__c.contains(aidAssetMap.get(ac.id).Product_Family__c) && (ac.Product_Subscriptions__c=='' || ac.Product_Subscriptions__c==null))
  30.             {   System.Debug('Product_Subscriptions__c Match Found ');
  31.                 prodstring=aidAssetMap.get(ac.id).Product_Family__c;
  32.             }
  33.             updateAccountList.add(new Account(Id = ac.id, Product_Subscriptions__c = prodstring));
  34.             }
  35.              System.Debug('updateAccountList ****'+updateAccountList);
  36.             if(updateAccountList.size() != 0){
  37.                Database.SaveResult[] srList = Database.update(updateAccountList, false);
  38.                         for(Database.SaveResult sr : srList)
  39.                         {
  40.                             for(Database.Error e : sr.getErrors())
  41.                             error += '\n ' + e.getMessage();
  42.                         }
  43.                     }
  44.             }
  45.         catch(Exception e)
  46.         {
  47.             error += e.getMessage();
  48.         }
  49.     }
  50.     global void finish(Database.BatchableContext BC)
  51.     {
  52.         AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email from AsyncApexJob where Id =: BC.getJobId()];
  53.         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
  54.         String[] toEmailAddresses = new String[] {'XXXXXXXXXXXXXXXXXXXXX'};
  55.         mail.setToAddresses(toEmailAddresses);
  56.         mail.setSubject('BatchJob Status' + a.Status);
  57.         mail.setHTMLBody
  58.         ('Total No of Batch Apex job processed ' + a.TotalJobItems +
  59.         ' batches with '+ a.NumberOfErrors + ' failures.');
  60.         Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
  61.     }
  62. }
I'm actually trying to get the assets from the map based on account ID and loop through the values to get the Product_Family__c.

Map<ID,Asset>actAstMap=new Map<ID,Asset>();
for (Asset a1: actAstMap.get(ActID)){
if(a1.Product_Family__c!=null ||a1.Product_Family__c<>''){
        pFamily.add(a1.Product_Family__c);
}
}

Any help will be much apprecitated.
Can someone please help with this error?
An Error occured at trigger XXXXXXX on contact:System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)

Here is my code, im calling this method from before insert and before update trigger.

*****ANY HELP WILL BE MUCH APPRICITED*******
  1.     public static void ContactProductSubscription(List<Contact>newcontacts,set<ID>acIds){
  2.         //set<id>acIds=new set<Id>();
  3.         set<id>acIds1=new set<Id>();
  4.         list<Asset>ast=new List<Asset>();
  5.         List<Linked_Account__c>lActs=new List<Linked_Account__c>();
  6.         List<Linked_Account__c>linkedAccounts=new List<Linked_Account__c>();
  7.         Map<Id,Id>actLActMap=new Map<Id,Id>();
  8.         Map<Id,Id>agentctLActMap=new Map<Id,Id>();
  9.         Map<Id,ID>alActs=new Map<Id,ID>();
  10.         Map<Id,Id>conActMap=new Map<Id,Id>();
  11.         Map<ID,String>ActPfamilyMap=new Map<ID,String>();
  12.         Map<ID,ID>lActAgentcontMap=new Map<ID,ID>();
  13.         Map<ID,ID>lActAcontMap=new Map<ID,ID>();
  14.         Map<ID,Asset>actAstMap=new Map<ID,Asset>();
  15.         set<id>aContacts=new set<id>();//Agent Contacts
  16.         set<string>pFamily=new set<string>();//Agent Contacts
  17.         String psubscription;
  18.          for(contact c :newcontacts){conActMap.put(c.id,c.accountID);}
  19.             if(acids.size()>0){
  20.                 lActs=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
  21.                 Cases__c, Contacts__c, Expiration__c, Linked_Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
  22.                 where Agent__c=true and  Contacts__c=true and (Expiration__c<>null OR Expiration__c >: date.today()) and Linked_Account__c in:acids ];
  23.             }
  24.             if(lActs.size()>0){
  25.             for(Linked_Account__c l:lActs){
  26.                 aContacts.add(l.Agent_Contact__c);
  27.                 actLActMap.put(l.Linked_Account__c,l.id);
  28.                 agentctLActMap.put(l.Agent_Contact__c,l.id);
  29.               
  30.                 }
  31.             } 
  32.             if(aContacts.size()>0){
  33.                 linkedAccounts=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
  34.                 Cases__c, Contacts__c, Expiration__c, Linked_Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
  35.                 where Agent__c=false and  isDeleted=false and Agent_Contact__c in:aContacts];
  36.             }
  37.             if(linkedAccounts.size()>0){
  38.             For(Linked_Account__c l1:linkedAccounts){
  39.                 acIds1.add(l1.Linked_Account__c);
  40.                 lActAgentcontMap.put(l1.Linked_Account__c,l1.Agent_Contact__c);
  41.                 lActAcontMap.put(l1.id,l1.Linked_Account__c);
  42.                 //agentctLActMap.put(l1.Agent_Contact__c,l1.id);
  43.           }
  44.             }
  45.             acIds1.addAll(acIds);
  46.             if(acIds1.size()>0){ast=[select AccountId, Id, Product_Family__c FROM Asset where AccountId in:acIds1];}
  47.             for(Asset a:ast){ActPfamilyMap.put(a.AccountId,a.Product_Family__c);
  48.             actAstMap.put(a.AccountId,a);}
  49.             for(contact c :newcontacts){
  50.             Id lactID=actLActMap.get(c.AccountID);
  51.             ID aContID=lActAgentcontMap.get(lactID);
  52.             ID lactID1=agentctLActMap.get(aContID);
  53.             ID ActID=lActAcontMap.get(lactID1);
  54.             if(ActPfamilyMap.containsKey(ActID)||ActPfamilyMap.containsKey(c.AccountID)){
  55.             for(Asset a1:[select AccountId, Id, Product_Family__c FROM Asset where AccountId =: c.AccountID OR AccountId=:ActID]){
  56.              psubscription+=a1.Product_Family__c+'; ';
  57.              c.productSubscriptions__c=psubscription;
  58.             }
  59.         
  60.             }
  61.          }
  62.       }
Need to auto populate productionsubscription__c(multi piclist on contact). all i have to do is based on Contact.AccountID i need to pull the Linked accounts and
1.Filter those linked accounts by agent_c == true && cases__c == true && expiration__c > today (or expiration_c empty) 
2. Get the agents of the of the linked accounts filtered in the previous step (i.e. a list of all linkedAccount.agent_Contact__c).
 
3. Get the linked accounts of the agents gotten in the previous step. and
select LINKED_ACCOUNT_FIELDS
from Linked_account__c
where isDeleted = false
and Agent__c = false
and Agent_Contact__c in (STEP_2_AGENTS)
Step 4: for all these linked account.AccountS and Contact.AccountID need to query the asset with product familiy field and get the uniq value and populate contact productSubscription__c field.

I'mcalling this method from before insert trigger.

*****ANY HELP WILL BE MUCH APPRICITED*******
  1. public static void ContactProductSubscription(List<Contact>newcontacts,set<ID>acIds){
  2.     //set<id>acIds=new set<Id>();
  3.     set<id>acIds1=new set<Id>();
  4.     list<Asset>ast=new List<Asset>();
  5.     List<Linked_Account__c>lActs=new List<Linked_Account__c>();
  6.     List<Linked_Account__c>linkedAccounts=new List<Linked_Account__c>();
  7.     Map<Id,Linked_Account__c>actLActMap=new Map<Id,Linked_Account__c>();
  8.     Map<Id,ID>alActs=new Map<Id,ID>();
  9.     Map<Id,Id>conActMap=new Map<Id,Id>();
  10.     Map<ID,String>ActPfamilyMap=new Map<ID,String>();
  11.     set<id>aContacts=new set<id>();//Agent Contacts
  12.    
  13.     for(contact c :newcontacts){conActMap.put(c.id,c.accountID);}
  14.      if(acids.size()>0){
  15.       lActs=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
  16.       Cases__c, Contacts__c, Expiration__c, Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
  17.       where Agent__c=true and  Contacts__c=true and (Expiration__c<>null OR Expiration__c >: date.today()) and Linked_Account__c in:acids ];
  18.      }
  19.      if(lActs.size()>0){
  20.      for(Linked_Account__c l:lActs){
  21.       aContacts.add(l.Agent_Contact__c);
  22.       actLActMap.put(l.Linked_Account__c,l);
  23.      
  24.       }
  25.      }
  26.      if(aContacts.size()>0){
  27.       linkedAccounts=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
  28.       Cases__c, Contacts__c, Expiration__c, Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
  29.       where Agent__c=false and  isDeleted=false and Agent_Contact__c in:aContacts];
  30.      }
  31.      if(linkedAccounts.size()>0){
  32.      For(Linked_Account__c l1:linkedAccounts){
  33.       acIds1.add(l1.Account__c);
  34.       //aContact.put(l1.Agent_Contact__c,l1.Account__c);
  35.      }
  36.      }
  37.      acIds1.addAll(acIds);
  38.      String psubscription;
  39.      if(acIds1.size()>0){ast=[select AccountId, Id, Product_Family__c FROM Asset where AccountId in:acIds1];}
  40.      for(Asset a:ast){ActPfamilyMap.put(a.AccountId,a.Product_Family__c);}
  41.      for(contact c :newcontacts){
  42.       list<Linked_Account__c>l1=actLActMap.get(c.AccountId);
  43.       set<id>acts=add(c.accountid);
  44.      for(Linked_Account__c l:l1){acts.add(alActs.get(l.Agent_Contact__c));
  45.       List<Asset>ast=ActPfamilyMap.get(acts);
  46.       }
  47.      for(Asset a1:ast){
  48.      psubscription+=a1.Product_Family__c+'; ';}
  49.      c.productSubscriptions__c=psubscription;
  50.      }
  51.    }
Hello Everyone
i am not able to call one method in the test class can you please help me out

public class JSONParserUtil {

    @future(callout=true)
   
   public static void parseJSONResponse(String Acctname,String Ids)
   // public static void parseJSONResponse()
     {      
        String AcctNameJson;
        system.debug('AccountName______________________________'+AcctName);
        String JSONContent = '{"folionum":'+AcctName+'}';
        Http httpProtocol = new Http();
        // Create HTTP request to send.
        HttpRequest request = new HttpRequest();
        // Set the endpoint URL.
        String endpoint = 'http://.cloudapp.net/api/values';
        request.setEndPoint(endpoint);
        request.setHeader('content-type', 'application/json; charset=utf-8');
        request.setMethod('POST');
       // String strbody = '{"folionum":48430721840}';
        request.setBody(JSONContent);
        HttpResponse response = httpProtocol.send(request);
       // String jsonInput = response.getBody(); UCOMMENETED TO READ TEH JSON
        JSONParser parser = JSON.createParser(response.getBody());
        system.debug('JSON PARESER___________________'+parser );
        system.debug('Respone'+Response.getBody());
        String grandTotal ;
         while (parser.nextToken() != null)
         {
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&(parser.getText() == '12monthspavg'))
             {
               parser.nextToken();
                grandTotal += parser.getDoubleValue();
     
             }
          }
                    system.debug('Grand total=' + grandTotal);
                   
         if (response.getStatusCode() == 200) {

      //update account
      Account acc = new Account(Id=Ids);
      acc.Description =grandTotal ;
      update acc;
    } else {
      System.debug('Callout failed: ' + response);
    }  
         
                   
}
}

###################Test Class####################################
@isTest(SeeAlldata=true)
private class E2PPTestClass {

    @isTest static  void myUnitTest()
     {
     
        // TO DO: implement unit test
        String Acctname;
        String Ids;
        List<Account > Acctquery;
        Account acct = new Account();
         acct.Name='Test';
        insert acct;
        Acctquery=[Select Id,Name from Account limit 1];
       acct.Id =Acct.Id;
       acct.Name='Test';
      Test.startTest();
     Test.setMock(HttpCalloutMock.class, new ExampleCalloutMock());
     HttpResponse res = JSONParserUtil.parseJSONResponse(Acctname, Ids);//I am getting the Error here ave error: Illegal assignment from void to System.HttpResponse
    
     Test.stopTest();
     
    
    }
}

Please help me out

Regards,
Sailer
  • January 27, 2014
  • Like
  • 0

Hi everyone.

I have created a new 'Geolocation' field on a custom object and am trying to get a trigger to fire which will populate the latitude and longitude via a callout to Google Maps.

I have added Google Maps to the remote site settings. This is in a Sandbox environment.

CLASS:

public class LocationCallouts {
 
     @future (callout=true)  // future method needed to run callouts from Triggers
      static public void getLocation(id Id){
        // gather account info
        Transaction__c t = [SELECT Street__c, City__c, County__c, Country__c, Postcode__c FROM Transaction__c WHERE id =: Id];
 
        // create an address string
        String address = '';
        if (t.Street__c!= null)
            address += t.Street__c+', ';
        if (t.City__c!= null)
            address += t.City__c+', ';
        if (t.County__c!= null)
            address += t.County__c+', ';
        if (t.Postcode__c != null)
            address += t.Postcode__c +', ';
        if (t.Country__c!= null)
            address += t.Country__c;
 
        address = EncodingUtil.urlEncode(address, 'UTF-8');
 
        // build callout
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setMethod('GET');
        req.setTimeout(60000);
 
        try{
            // callout
            HttpResponse res = h.send(req);
 
            // parse coordinates from response
            JSONParser parser = JSON.createParser(res.getBody());
            double lat = null;
            double lon = null;
            while (parser.nextToken() != null) {
                if (parser.getText() == 'coordinates'){
                       parser.nextToken(); // object start
                           String txt = parser.getText();
                           parser.nextToken();
                           if (txt == 'lat')
                               lat = parser.getDoubleValue();
                           else if (txt == 'lng')
                               lon = parser.getDoubleValue();
                }
            }
 
            // update coordinates if we get back
            if (lat!= null){
                t.Location__Latitude__s = lat;
                t.Location__Longitude__s = lon;
                update t;
            }
 
        } catch (Exception e) {
        }
    }
}

TRIGGER:


// Trigger runs getLocation() on Transaction
trigger SetGeolocation on Transaction__c (after insert, after update) {
    for (Transaction__c t : trigger.new){
        if (t.Location__Latitude__s == null){
            LocationCallouts.getLocation(t.id);
        }
    }
}

I am sure I have just done something stupid but cannot see what I have done wrong!!

Any help would be greatly appreciated.