-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
12Questions
-
25Replies
Entity 'Owner' not accessible in version 30.0 at line 1 column 24
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;
}
}
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;
}
}
- KR_Force
- February 04, 2015
- Like
- 0
how to get around with Test.isRunningTest() && Limits.getFutureCalls() >= Limits.getLimitFutureCalls() In test class
- trigger MasterTrigger on Master__c (before delete, after insert) {
- if( trigger.isAfter){
- TriggerHandler.SummaryRecords( trigger.new );
- }
- if(trigger.isBefore && trigger.isDelete){
- if(Test.isRunningTest() && Limits.getFutureCalls() >= Limits.getLimitFutureCalls()){
- system.debug(LoggingLevel.Error, 'Future method limit reached. Skipping...');
- }
- else {BUtil.DeleteService(trigger.oldMap.keySet());}
- }
- }
- KR_Force
- August 17, 2014
- Like
- 0
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
Class.TestEvalEndDateHTTPCallOut.testEVAlEndDateCallout: line 28, column 1
- @isTest
- public class TestEvalEndDateHTTPCallOut {
- public static testmethod void testEVAlEndDateCallout() {
- SingleRequestMock fakeResponse = new SingleRequestMock(200,
- 'Complete',
- '[{"Name": "sForceTest1"}]',
- null);
- Test.setMock(HttpCalloutMock.class, fakeResponse);
- set<ID> ast=new Set<ID>();
- Account a = new Account();
- a.Name = 'test account';
- a.Product_Subscriptions__c='test;test:';
- insert a;
- Asset a1 = new Asset(Name='testAsset', RVBD_Product_Family__c= 'test',IB_Status__c='Under Evaluation',Instance_Number__c='77777777XX',AccountID=a.id);
- insert a1;
- ast.add(a1.id);
- Contact foo = new Contact(FirstName = 'Foo', LastName='Bar');
- insert foo;
- Case c = new Case(Subject = 'Test case', ContactId=foo.id,AssetID=a1.id,AccountID=a.id);
- Insert c;
- PageReference pageRef = Page.RefreshEvalEndDate;
- Test.setCurrentPage(pageRef);
- Apexpages.StandardController stdController = new Apexpages.StandardController(a1);
- Apexpages.currentPage().getParameters().put('id',a1.Id);
- EvalEndDateHTTPCallOut controller = new EvalEndDateHTTPCallOut(StdController);
- controller.parseJSONResponse();
- EvalEndDateHTTPCallOut.parseJSONResponseFuture(ast);
- }
- }
- KR_Force
- August 16, 2014
- Like
- 0
Test class help for web services class(Compile Error: Illegal assignment from void to System.HttpResponse)
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"
- @isTest
- private class TestEvalEndDateHTTPCallOut {
- @isTest static void testCallout() {
- set<ID> ast=new Set<ID>();
- Test.setMock(WebServiceMock.class, new MockHttpResponseGenerator());
- Account a = new Account();
- a.Name = 'test account';
- a.Product_Subscriptions__c='test;test:';
- insert a;
- Asset a1 = new Asset(Name='testAsset', RVBD_Product_Family__c= 'test',IB_Status__c='Under Evaluation',Instance_Number__c='77777777XX',AccountID=a.id);
- ast.add(a1.id);
- Contact foo = new Contact(FirstName = 'Foo', LastName='Bar');
- insert foo;
- Case c = new Case(Subject = 'Test case', ContactId=foo.id,AssetID=a1.id,AccountID=a.id);
- Insert c;
- Http h = new Http();
- HttpRequest req1 = new HttpRequest();
- req1.setEndpoint('http://mygreatservice.com/foo/bar');
- req1.setMethod('POST');
- //HttpResponse res1 = h.send(req1);
- HttpResponse res1=EvalEndDateHTTPCallOut.parseJSONResponseFuture(ast);
- String contentType = res1.getHeader('Content-Type');
- System.assert(contentType == 'application/json');
- String actualValue = res1.getBody();
- String expectedValue = '{"foo":"bar"}';
- System.assertEquals(actualValue, expectedValue);
- System.assertEquals(200, res1.getStatusCode());
- }
- }
- ============================================================================================
- Here is the class...
- public class HTTPCallOutClass {
- private ApexPages.StandardController stdCtrl {get; set;}
- public Asset ast { get; set; }
- public String sn { get; set; }
- //constructor to get the Asset record
- public EvalEndDateHTTPCallOut(ApexPages.StandardController controller){
- ast = (Asset) controller.getRecord();
- sn = ast.Name;
- System.debug('The Asset record: ' + sn);
- }
- public PageReference parseJSONResponse() {
- Http httpProtocol = new Http();
- String s=sn;
- Date eDate;
- Asset a = [Select Id, name,EvalEndDate__c from Asset where name=: sn];
- // Create HTTP request to send.
- HttpRequest request = new HttpRequest();
- String ENDPOINT=getUrl('test');
- request.setEndpoint(endpoint+s);
- // Set the HTTP verb to GET.
- request.setMethod('GET');
- request.setTimeout(60000);
- // Send the HTTP request and get the response,The response is in JSON format.
- HttpResponse response = httpProtocol.send(request);
- system.debug(LoggingLevel.INFO,'response:'+response);
- if(response!=null && response.getStatusCode()==200){
- Map<String, Object> data = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());
- system.debug(LoggingLevel.INFO,'response data:'+data);
- system.debug(LoggingLevel.INFO,'ErrorID:'+(String)data.get('error_id'));
- if(!string.IsBlank((String)data.get('evalDate'))){
- eDate = Date.valueOf((String)data.get('evalDate'));
- }
- }
- if (eDate!= null){
- system.debug(LoggingLevel.INFO,'GetResponse:'+response.getBody());
- a.EvalEndDate__c = eDate;
- update a;
- }
- system.debug('updated asset=' + a);
- return new PageReference('/'+a.id);
- }
- @future(callout=true)
- public static void parseJSONResponseFuture(Set<Id> aIds){
- Http httpProtocol = new Http();
- List<Asset>asts=new List<Asset>([Select Id, name,EvalEndDate__c,SerialNumber from Asset where id in : aIds and Status__c='Evaluation']);
- system.debug(LoggingLevel.INFO,'asts:'+asts);
- For( Asset a:asts){
- String s=a.name;
- HttpRequest request = new HttpRequest();
- String ENDPOINT=getUrl('test');
- request.setEndpoint(endpoint+s);
- request.setMethod('GET');
- request.setTimeout(60000);
- try{
- if(!Test.isRunningTest()){
- HttpResponse response = httpProtocol.send(request);
- system.debug(LoggingLevel.INFO,'response:'+response);
- Map<String, Object> data = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());
- system.debug(LoggingLevel.INFO,'response data:'+data);
- Date eDate= Date.valueOf((String)data.get('evalDate'));
- if (eDate!= null){
- system.debug(LoggingLevel.INFO,'GetResponse:'+response.getBody());
- a.EvalEndDate__c = eDate;
- update a;
- }
- system.debug('updated asset****=' + a);
- }
- }
- catch (Exception e) {}
- }
- //update asts;
- system.debug('updated assets=' + asts);
- }
- private static string getUrl(string serviceType){
- Integration_Settings__c iProp=Integration_Settings__c.getValues('IntegrationEndPoints');
- if(iprop != null){
- if(serviceType.equalsIgnoreCase('test')){
- return iProp.url__c;}
- return ' ';
- }
- else {
- return ' ';
- }
- }
- }
- =============================================================================================
- 1.parseJSONResponse() methog being invokde from Button
- 2. parseJSONResponseFuture() method from trigger
- =======================================================
- 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.
- @isTest
- private class TestEvalEndDateHTTPCallOut {
- @isTest static void testCallout() {
- set<ID> ast=new Set<ID>();
- Test.setMock(WebServiceMock.class, new MockHttpResponseGenerator());
- Account a = new Account();
- a.Name = 'test account';
- a.Product_Subscriptions__c='test;test:';
- insert a;
- Asset a1 = new Asset(Name='testAsset', RVBD_Product_Family__c= 'test',IB_Status__c='Under Evaluation',Instance_Number__c='77777777XX',AccountID=a.id);
- ast.add(a1.id);
- Http h = new Http();
- HttpRequest req1 = new HttpRequest();
- req1.setEndpoint('http://mygreatservice.com/foo/bar');
- req1.setMethod('POST');
- HttpResponse res1 = h.send(req1);
- String contentType = res1.getHeader('Content-Type');
- System.assert(contentType == 'application/json');
- String actualValue = res1.getBody();
- String expectedValue = '{"foo":"bar"}';
- System.assertEquals(actualValue, expectedValue);
- System.assertEquals(200, res1.getStatusCode());
- }
- }
- KR_Force
- August 16, 2014
- Like
- 0
test class help for Batch class
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();
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();
- KR_Force
- August 15, 2014
- Like
- 0
Batch Class Help?
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
Note::Product_Subscriptions__c is a multi pick list field
- global class BatchAccountProductSubscriptions implements Database.Batchable<sobject>, Database.Stateful
- {
- public String query;
- global String error;
- global database.queryLocator start(Database.BatchableContext BC)
- { String query = 'select AccountId, Id, Product_Family__c FROM Asset where Product_Family__c!=null limit 200';
- 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>>();
- Map<id,string> accProdFamily = new Map<id,string>();
- Map<id,Asset> aidAssetMap = new Map<id,Asset>();
- List<Account> updateAccountList = new List<Account>();
- boolean isUpdate = false;
- try
- { System.Debug('assetList ****'+assetList);
- for(Asset a :assetList){aidAssetMap.put(a.AccountId,a);}
- list<Account> act =[select Id, Product_Subscriptions__c FROM account where id in:aidAssetMap.keyset()];
- for(Account ac:act){
- string prodstring ='';
- if(!ac.Product_Subscriptions__c.contains(aidAssetMap.get(ac.id).Product_Family__c) && (ac.Product_Subscriptions__c<>''|| ac.Product_Subscriptions__c!=null ))
- { System.Debug('Product_Subscriptions__c Match not Found ');
- prodstring=ac.Product_Subscriptions__c+';'+aidAssetMap.get(ac.id).Product_Family__c;
- }
- else if(!ac.Product_Subscriptions__c.contains(aidAssetMap.get(ac.id).Product_Family__c) && (ac.Product_Subscriptions__c=='' || ac.Product_Subscriptions__c==null))
- { System.Debug('Product_Subscriptions__c Match Found ');
- prodstring=aidAssetMap.get(ac.id).Product_Family__c;
- }
- updateAccountList.add(new Account(Id = ac.id, Product_Subscriptions__c = prodstring));
- }
- System.Debug('updateAccountList ****'+updateAccountList);
- if(updateAccountList.size() != 0){
- Database.SaveResult[] srList = Database.update(updateAccountList, false);
- for(Database.SaveResult sr : srList)
- {
- for(Database.Error e : sr.getErrors())
- error += '\n ' + e.getMessage();
- }
- }
- }
- catch(Exception e)
- {
- error += e.getMessage();
- }
- }
- global void finish(Database.BatchableContext BC)
- {
- AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email from AsyncApexJob where Id =: BC.getJobId()];
- Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
- String[] toEmailAddresses = new String[] {'XXXXXXXXXXXXXXXXXXXXX'};
- mail.setToAddresses(toEmailAddresses);
- mail.setSubject('BatchJob Status' + a.Status);
- mail.setHTMLBody
- ('Total No of Batch Apex job processed ' + a.TotalJobItems +
- ' batches with '+ a.NumberOfErrors + ' failures.');
- Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
- }
- }
- KR_Force
- June 26, 2014
- Like
- 0
How to loop through the map values... Compile Error: Loop must iterate over a collection type: SOBJECT:Asset
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.
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.
- KR_Force
- June 17, 2014
- Like
- 0
System.QueryException: Non-selective query against large object type (more than 100000 rows)
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*******
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*******
- public static void ContactProductSubscription(List<Contact>newcontacts,set<ID>acIds){
- //set<id>acIds=new set<Id>();
- set<id>acIds1=new set<Id>();
- list<Asset>ast=new List<Asset>();
- List<Linked_Account__c>lActs=new List<Linked_Account__c>();
- List<Linked_Account__c>linkedAccounts=new List<Linked_Account__c>();
- Map<Id,Id>actLActMap=new Map<Id,Id>();
- Map<Id,Id>agentctLActMap=new Map<Id,Id>();
- Map<Id,ID>alActs=new Map<Id,ID>();
- Map<Id,Id>conActMap=new Map<Id,Id>();
- Map<ID,String>ActPfamilyMap=new Map<ID,String>();
- Map<ID,ID>lActAgentcontMap=new Map<ID,ID>();
- Map<ID,ID>lActAcontMap=new Map<ID,ID>();
- Map<ID,Asset>actAstMap=new Map<ID,Asset>();
- set<id>aContacts=new set<id>();//Agent Contacts
- set<string>pFamily=new set<string>();//Agent Contacts
- String psubscription;
- for(contact c :newcontacts){conActMap.put(c.id,c.accountID);}
- if(acids.size()>0){
- lActs=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
- Cases__c, Contacts__c, Expiration__c, Linked_Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
- where Agent__c=true and Contacts__c=true and (Expiration__c<>null OR Expiration__c >: date.today()) and Linked_Account__c in:acids ];
- }
- if(lActs.size()>0){
- for(Linked_Account__c l:lActs){
- aContacts.add(l.Agent_Contact__c);
- actLActMap.put(l.Linked_Account__c,l.id);
- agentctLActMap.put(l.Agent_Contact__c,l.id);
- }
- }
- if(aContacts.size()>0){
- linkedAccounts=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
- Cases__c, Contacts__c, Expiration__c, Linked_Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
- where Agent__c=false and isDeleted=false and Agent_Contact__c in:aContacts];
- }
- if(linkedAccounts.size()>0){
- For(Linked_Account__c l1:linkedAccounts){
- acIds1.add(l1.Linked_Account__c);
- lActAgentcontMap.put(l1.Linked_Account__c,l1.Agent_Contact__c);
- lActAcontMap.put(l1.id,l1.Linked_Account__c);
- //agentctLActMap.put(l1.Agent_Contact__c,l1.id);
- }
- }
- acIds1.addAll(acIds);
- if(acIds1.size()>0){ast=[select AccountId, Id, Product_Family__c FROM Asset where AccountId in:acIds1];}
- for(Asset a:ast){ActPfamilyMap.put(a.AccountId,a.Product_Family__c);
- actAstMap.put(a.AccountId,a);}
- for(contact c :newcontacts){
- Id lactID=actLActMap.get(c.AccountID);
- ID aContID=lActAgentcontMap.get(lactID);
- ID lactID1=agentctLActMap.get(aContID);
- ID ActID=lActAcontMap.get(lactID1);
- if(ActPfamilyMap.containsKey(ActID)||ActPfamilyMap.containsKey(c.AccountID)){
- for(Asset a1:[select AccountId, Id, Product_Family__c FROM Asset where AccountId =: c.AccountID OR AccountId=:ActID]){
- psubscription+=a1.Product_Family__c+'; ';
- c.productSubscriptions__c=psubscription;
- }
- }
- }
- }
- KR_Force
- June 16, 2014
- Like
- 0
Can some one please help me with this code??
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.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*******
- public static void ContactProductSubscription(List<Contact>newcontacts,set<ID>acIds){
- //set<id>acIds=new set<Id>();
- set<id>acIds1=new set<Id>();
- list<Asset>ast=new List<Asset>();
- List<Linked_Account__c>lActs=new List<Linked_Account__c>();
- List<Linked_Account__c>linkedAccounts=new List<Linked_Account__c>();
- Map<Id,Linked_Account__c>actLActMap=new Map<Id,Linked_Account__c>();
- Map<Id,ID>alActs=new Map<Id,ID>();
- Map<Id,Id>conActMap=new Map<Id,Id>();
- Map<ID,String>ActPfamilyMap=new Map<ID,String>();
- set<id>aContacts=new set<id>();//Agent Contacts
- for(contact c :newcontacts){conActMap.put(c.id,c.accountID);}
- if(acids.size()>0){
- lActs=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
- Cases__c, Contacts__c, Expiration__c, Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
- where Agent__c=true and Contacts__c=true and (Expiration__c<>null OR Expiration__c >: date.today()) and Linked_Account__c in:acids ];
- }
- if(lActs.size()>0){
- for(Linked_Account__c l:lActs){
- aContacts.add(l.Agent_Contact__c);
- actLActMap.put(l.Linked_Account__c,l);
- }
- }
- if(aContacts.size()>0){
- linkedAccounts=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
- Cases__c, Contacts__c, Expiration__c, Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
- where Agent__c=false and isDeleted=false and Agent_Contact__c in:aContacts];
- }
- if(linkedAccounts.size()>0){
- For(Linked_Account__c l1:linkedAccounts){
- acIds1.add(l1.Account__c);
- //aContact.put(l1.Agent_Contact__c,l1.Account__c);
- }
- }
- acIds1.addAll(acIds);
- String psubscription;
- if(acIds1.size()>0){ast=[select AccountId, Id, Product_Family__c FROM Asset where AccountId in:acIds1];}
- for(Asset a:ast){ActPfamilyMap.put(a.AccountId,a.Product_Family__c);}
- for(contact c :newcontacts){
- list<Linked_Account__c>l1=actLActMap.get(c.AccountId);
- set<id>acts=add(c.accountid);
- for(Linked_Account__c l:l1){acts.add(alActs.get(l.Agent_Contact__c));
- List<Asset>ast=ActPfamilyMap.get(acts);
- }
- for(Asset a1:ast){
- psubscription+=a1.Product_Family__c+'; ';}
- c.productSubscriptions__c=psubscription;
- }
- }
- KR_Force
- June 16, 2014
- Like
- 0
Custome Field is not getting updated
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?
- for(Account a: uChild)
- {
- //Account uParent = uChildMap.get(a.id);
- //System.debug('Parent ID**:'+ a.ParentId);
- if (a.ParentId ==null){
- System.debug('Condition 6**:');
- a.Ultimate_Parent_Vertical__c = a.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = a.AnnualRevenue;
- // uChild1.add(a);
- }
- else if (a.Parent.ParentId ==null){
- System.debug('Condition 7**:'+a.Parent.OS_Industry_Sector__c+a.Parent.AnnualRevenue);
- a.Ultimate_Parent_Vertical__c = a.Parent.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = a.Parent.AnnualRevenue;
- //uChild1.add(a);
- }
- else if (a.Parent.Parent.ParentId ==null){
- System.debug('Condition 8**:');
- a.Ultimate_Parent_Vertical__c = a.Parent.Parent.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = a.Parent.Parent.AnnualRevenue;
- //uChild1.add(a);
- }
- else if (a.Parent.Parent.Parent.ParentId ==null){
- System.debug('Condition 9**:');
- a.Ultimate_Parent_Vertical__c = a.Parent.Parent.Parent.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = a.Parent.Parent.Parent.AnnualRevenue;
- //uChild1.add(a);
- }
- else if (a.Parent.Parent.Parent.Parent.ParentId ==null){
- System.debug('Condition 10**:');
- a.Ultimate_Parent_Vertical__c = a.Parent.Parent.Parent.Parent.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = a.Parent.Parent.Parent.Parent.AnnualRevenue;
- //uChild1.add(a);
- }
- }
- Update uChild;
- }
- KR_Force
- May 06, 2014
- Like
- 0
Account heirarchy traverse...called a method in before update trigger, which is not updating the fields.
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?
- public static void AccountUltimateRevenue(Map<ID,Account> newActMap,Map<ID,Account> oldActMap,List<Account>newActList){
- List<Account>actList=new List<Account>();
- List<Account>aList;
- Set<ID>parentActList=new Set<ID>();
- List<Account>uParents=new List<Account>();
- Map<ID, List<Account>> uActListMap = new Map<ID, List<Account>>();
- for(Account a:newActList)
- {
- Account a1=oldActMap.get(a.id);
- // To check whether Parent Account was updated and not null
- if((newActMap.get(a.Id).parentID!=oldActMap.get(a.Id).parentID && newActMap.get(a.Id).parentID<>null))
- {
- ActList.add(a);
- parentActList.add(newActMap.get(a.Id).parentID);
- System.debug('old+++++++++'+a1.parentID+'new++++++++++++++++'+a.parentID);
- System.debug('ActList+++++++++'+ActList);
- }
- else
- if(newActMap.get(a.Id).parentID==null)
- { System.debug('No Parent**:');
- uParents.add(a);
- }
- }
- // Checking if Parent Account list not null pulling all corresponding Ultimate parent revenue and Ultimate parent vertical values from parent accounts.
- if(parentActList!= null && parentActList.size()>0){
- //system.debug( 'Parent Account list:'+parentActList);
- map<Id, Account> uActMap=new map<Id, Account>([select Id,AnnualRevenue,OS_Industry_Sector__c, Ultimate_Parent_Vertical__c, Ultimate_Parent_Revenue__c,
- ParentId, Parent.OS_Industry_Sector__c, Parent.AnnualRevenue,
- Parent.ParentId, Parent.Parent.OS_Industry_Sector__c, Parent.Parent.AnnualRevenue,
- Parent.Parent.ParentId, Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.AnnualRevenue,
- Parent.Parent.Parent.ParentId, Parent.Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.Parent.AnnualRevenue
- from Account where ID IN :parentActList]);
- for(Account a: newActList)
- {
- Account ParentAccount = uActMap.get(a.ParentId);
- System.debug('Parent ID**:'+ a.ParentId);
- if (ParentAccount.ParentId ==null){
- System.debug('Condition 1**:');
- a.Ultimate_Parent_Vertical__c = ParentAccount.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = ParentAccount.AnnualRevenue;
- }
- else if (ParentAccount.Parent.ParentId ==null){
- System.debug('Condition 2**:');
- a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.AnnualRevenue;
- }
- else if (ParentAccount.Parent.Parent.ParentId ==null){
- System.debug('Condition 3**:');
- a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.Parent.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.Parent.AnnualRevenue;
- }
- else if (ParentAccount.Parent.Parent.Parent.ParentId ==null){
- System.debug('Condition 4**:');
- a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.Parent.Parent.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.Parent.Parent.AnnualRevenue;
- }
- else if (ParentAccount.Parent.Parent.Parent.Parent.ParentId ==null){
- System.debug('Condition 5**:');
- a.Ultimate_Parent_Vertical__c = ParentAccount.Parent.Parent.Parent.Parent.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = ParentAccount.Parent.Parent.Parent.Parent.AnnualRevenue;
- }
- }
- }
- if(uParents.size()>0)
- {
- List<Account> uChild=new List<Account>([select Id,AnnualRevenue,OS_Industry_Sector__c, Ultimate_Parent_Vertical__c, Ultimate_Parent_Revenue__c,
- ParentId, Parent.OS_Industry_Sector__c, Parent.AnnualRevenue,
- Parent.ParentId, Parent.Parent.OS_Industry_Sector__c, Parent.Parent.AnnualRevenue,
- Parent.Parent.ParentId, Parent.Parent.Parent.OS_Industry_Sector__c, Parent.Parent.Parent.AnnualRevenue,
- 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]);
- for(Account a: uChild)
- {
- if (a.ParentId ==null){
- System.debug('Condition 6**:');
- a.Ultimate_Parent_Vertical__c = a.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = a.AnnualRevenue;
- }
- else if (a.Parent.ParentId ==null){
- System.debug('Condition 7**:'+a.Parent.OS_Industry_Sector__c+a.Parent.AnnualRevenue);
- //a.Ultimate_Parent_Vertical__c = a.Parent.OS_Industry_Sector__c;
- a.Ultimate_Parent_Vertical__c = a.Parent.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = a.Parent.AnnualRevenue;
- }
- else if (a.Parent.Parent.ParentId ==null){
- System.debug('Condition 8**:');
- a.Ultimate_Parent_Vertical__c = a.Parent.Parent.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = a.Parent.Parent.AnnualRevenue;
- }
- else if (a.Parent.Parent.Parent.ParentId ==null){
- System.debug('Condition 9**:');
- a.Ultimate_Parent_Vertical__c = a.Parent.Parent.Parent.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = a.Parent.Parent.Parent.AnnualRevenue;
- }
- else if (a.Parent.Parent.Parent.Parent.ParentId ==null){
- System.debug('Condition 10**:');
- a.Ultimate_Parent_Vertical__c = a.Parent.Parent.Parent.Parent.OS_Industry_Sector__c;
- a.Ultimate_Parent_Revenue__c = a.Parent.Parent.Parent.Parent.AnnualRevenue;
- }
- }
- }
- }
- KR_Force
- May 06, 2014
- Like
- 0
|| OR condition is not working in oneClick javascript button.
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.");
}
}
{!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.");
}
}
- KR_Force
- April 22, 2014
- Like
- 0
Entity 'Owner' not accessible in version 30.0 at line 1 column 24
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;
}
}
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;
}
}
- KR_Force
- February 04, 2015
- Like
- 0
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
Class.TestEvalEndDateHTTPCallOut.testEVAlEndDateCallout: line 28, column 1
- @isTest
- public class TestEvalEndDateHTTPCallOut {
- public static testmethod void testEVAlEndDateCallout() {
- SingleRequestMock fakeResponse = new SingleRequestMock(200,
- 'Complete',
- '[{"Name": "sForceTest1"}]',
- null);
- Test.setMock(HttpCalloutMock.class, fakeResponse);
- set<ID> ast=new Set<ID>();
- Account a = new Account();
- a.Name = 'test account';
- a.Product_Subscriptions__c='test;test:';
- insert a;
- Asset a1 = new Asset(Name='testAsset', RVBD_Product_Family__c= 'test',IB_Status__c='Under Evaluation',Instance_Number__c='77777777XX',AccountID=a.id);
- insert a1;
- ast.add(a1.id);
- Contact foo = new Contact(FirstName = 'Foo', LastName='Bar');
- insert foo;
- Case c = new Case(Subject = 'Test case', ContactId=foo.id,AssetID=a1.id,AccountID=a.id);
- Insert c;
- PageReference pageRef = Page.RefreshEvalEndDate;
- Test.setCurrentPage(pageRef);
- Apexpages.StandardController stdController = new Apexpages.StandardController(a1);
- Apexpages.currentPage().getParameters().put('id',a1.Id);
- EvalEndDateHTTPCallOut controller = new EvalEndDateHTTPCallOut(StdController);
- controller.parseJSONResponse();
- EvalEndDateHTTPCallOut.parseJSONResponseFuture(ast);
- }
- }
- KR_Force
- August 16, 2014
- Like
- 0
Test class help for web services class(Compile Error: Illegal assignment from void to System.HttpResponse)
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"
- @isTest
- private class TestEvalEndDateHTTPCallOut {
- @isTest static void testCallout() {
- set<ID> ast=new Set<ID>();
- Test.setMock(WebServiceMock.class, new MockHttpResponseGenerator());
- Account a = new Account();
- a.Name = 'test account';
- a.Product_Subscriptions__c='test;test:';
- insert a;
- Asset a1 = new Asset(Name='testAsset', RVBD_Product_Family__c= 'test',IB_Status__c='Under Evaluation',Instance_Number__c='77777777XX',AccountID=a.id);
- ast.add(a1.id);
- Contact foo = new Contact(FirstName = 'Foo', LastName='Bar');
- insert foo;
- Case c = new Case(Subject = 'Test case', ContactId=foo.id,AssetID=a1.id,AccountID=a.id);
- Insert c;
- Http h = new Http();
- HttpRequest req1 = new HttpRequest();
- req1.setEndpoint('http://mygreatservice.com/foo/bar');
- req1.setMethod('POST');
- //HttpResponse res1 = h.send(req1);
- HttpResponse res1=EvalEndDateHTTPCallOut.parseJSONResponseFuture(ast);
- String contentType = res1.getHeader('Content-Type');
- System.assert(contentType == 'application/json');
- String actualValue = res1.getBody();
- String expectedValue = '{"foo":"bar"}';
- System.assertEquals(actualValue, expectedValue);
- System.assertEquals(200, res1.getStatusCode());
- }
- }
- ============================================================================================
- Here is the class...
- public class HTTPCallOutClass {
- private ApexPages.StandardController stdCtrl {get; set;}
- public Asset ast { get; set; }
- public String sn { get; set; }
- //constructor to get the Asset record
- public EvalEndDateHTTPCallOut(ApexPages.StandardController controller){
- ast = (Asset) controller.getRecord();
- sn = ast.Name;
- System.debug('The Asset record: ' + sn);
- }
- public PageReference parseJSONResponse() {
- Http httpProtocol = new Http();
- String s=sn;
- Date eDate;
- Asset a = [Select Id, name,EvalEndDate__c from Asset where name=: sn];
- // Create HTTP request to send.
- HttpRequest request = new HttpRequest();
- String ENDPOINT=getUrl('test');
- request.setEndpoint(endpoint+s);
- // Set the HTTP verb to GET.
- request.setMethod('GET');
- request.setTimeout(60000);
- // Send the HTTP request and get the response,The response is in JSON format.
- HttpResponse response = httpProtocol.send(request);
- system.debug(LoggingLevel.INFO,'response:'+response);
- if(response!=null && response.getStatusCode()==200){
- Map<String, Object> data = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());
- system.debug(LoggingLevel.INFO,'response data:'+data);
- system.debug(LoggingLevel.INFO,'ErrorID:'+(String)data.get('error_id'));
- if(!string.IsBlank((String)data.get('evalDate'))){
- eDate = Date.valueOf((String)data.get('evalDate'));
- }
- }
- if (eDate!= null){
- system.debug(LoggingLevel.INFO,'GetResponse:'+response.getBody());
- a.EvalEndDate__c = eDate;
- update a;
- }
- system.debug('updated asset=' + a);
- return new PageReference('/'+a.id);
- }
- @future(callout=true)
- public static void parseJSONResponseFuture(Set<Id> aIds){
- Http httpProtocol = new Http();
- List<Asset>asts=new List<Asset>([Select Id, name,EvalEndDate__c,SerialNumber from Asset where id in : aIds and Status__c='Evaluation']);
- system.debug(LoggingLevel.INFO,'asts:'+asts);
- For( Asset a:asts){
- String s=a.name;
- HttpRequest request = new HttpRequest();
- String ENDPOINT=getUrl('test');
- request.setEndpoint(endpoint+s);
- request.setMethod('GET');
- request.setTimeout(60000);
- try{
- if(!Test.isRunningTest()){
- HttpResponse response = httpProtocol.send(request);
- system.debug(LoggingLevel.INFO,'response:'+response);
- Map<String, Object> data = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());
- system.debug(LoggingLevel.INFO,'response data:'+data);
- Date eDate= Date.valueOf((String)data.get('evalDate'));
- if (eDate!= null){
- system.debug(LoggingLevel.INFO,'GetResponse:'+response.getBody());
- a.EvalEndDate__c = eDate;
- update a;
- }
- system.debug('updated asset****=' + a);
- }
- }
- catch (Exception e) {}
- }
- //update asts;
- system.debug('updated assets=' + asts);
- }
- private static string getUrl(string serviceType){
- Integration_Settings__c iProp=Integration_Settings__c.getValues('IntegrationEndPoints');
- if(iprop != null){
- if(serviceType.equalsIgnoreCase('test')){
- return iProp.url__c;}
- return ' ';
- }
- else {
- return ' ';
- }
- }
- }
- =============================================================================================
- 1.parseJSONResponse() methog being invokde from Button
- 2. parseJSONResponseFuture() method from trigger
- =======================================================
- 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.
- @isTest
- private class TestEvalEndDateHTTPCallOut {
- @isTest static void testCallout() {
- set<ID> ast=new Set<ID>();
- Test.setMock(WebServiceMock.class, new MockHttpResponseGenerator());
- Account a = new Account();
- a.Name = 'test account';
- a.Product_Subscriptions__c='test;test:';
- insert a;
- Asset a1 = new Asset(Name='testAsset', RVBD_Product_Family__c= 'test',IB_Status__c='Under Evaluation',Instance_Number__c='77777777XX',AccountID=a.id);
- ast.add(a1.id);
- Http h = new Http();
- HttpRequest req1 = new HttpRequest();
- req1.setEndpoint('http://mygreatservice.com/foo/bar');
- req1.setMethod('POST');
- HttpResponse res1 = h.send(req1);
- String contentType = res1.getHeader('Content-Type');
- System.assert(contentType == 'application/json');
- String actualValue = res1.getBody();
- String expectedValue = '{"foo":"bar"}';
- System.assertEquals(actualValue, expectedValue);
- System.assertEquals(200, res1.getStatusCode());
- }
- }
- KR_Force
- August 16, 2014
- Like
- 0
test class help for Batch class
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();
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();
- KR_Force
- August 15, 2014
- Like
- 0
Batch Class Help?
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
Note::Product_Subscriptions__c is a multi pick list field
- global class BatchAccountProductSubscriptions implements Database.Batchable<sobject>, Database.Stateful
- {
- public String query;
- global String error;
- global database.queryLocator start(Database.BatchableContext BC)
- { String query = 'select AccountId, Id, Product_Family__c FROM Asset where Product_Family__c!=null limit 200';
- 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>>();
- Map<id,string> accProdFamily = new Map<id,string>();
- Map<id,Asset> aidAssetMap = new Map<id,Asset>();
- List<Account> updateAccountList = new List<Account>();
- boolean isUpdate = false;
- try
- { System.Debug('assetList ****'+assetList);
- for(Asset a :assetList){aidAssetMap.put(a.AccountId,a);}
- list<Account> act =[select Id, Product_Subscriptions__c FROM account where id in:aidAssetMap.keyset()];
- for(Account ac:act){
- string prodstring ='';
- if(!ac.Product_Subscriptions__c.contains(aidAssetMap.get(ac.id).Product_Family__c) && (ac.Product_Subscriptions__c<>''|| ac.Product_Subscriptions__c!=null ))
- { System.Debug('Product_Subscriptions__c Match not Found ');
- prodstring=ac.Product_Subscriptions__c+';'+aidAssetMap.get(ac.id).Product_Family__c;
- }
- else if(!ac.Product_Subscriptions__c.contains(aidAssetMap.get(ac.id).Product_Family__c) && (ac.Product_Subscriptions__c=='' || ac.Product_Subscriptions__c==null))
- { System.Debug('Product_Subscriptions__c Match Found ');
- prodstring=aidAssetMap.get(ac.id).Product_Family__c;
- }
- updateAccountList.add(new Account(Id = ac.id, Product_Subscriptions__c = prodstring));
- }
- System.Debug('updateAccountList ****'+updateAccountList);
- if(updateAccountList.size() != 0){
- Database.SaveResult[] srList = Database.update(updateAccountList, false);
- for(Database.SaveResult sr : srList)
- {
- for(Database.Error e : sr.getErrors())
- error += '\n ' + e.getMessage();
- }
- }
- }
- catch(Exception e)
- {
- error += e.getMessage();
- }
- }
- global void finish(Database.BatchableContext BC)
- {
- AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email from AsyncApexJob where Id =: BC.getJobId()];
- Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
- String[] toEmailAddresses = new String[] {'XXXXXXXXXXXXXXXXXXXXX'};
- mail.setToAddresses(toEmailAddresses);
- mail.setSubject('BatchJob Status' + a.Status);
- mail.setHTMLBody
- ('Total No of Batch Apex job processed ' + a.TotalJobItems +
- ' batches with '+ a.NumberOfErrors + ' failures.');
- Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
- }
- }
- KR_Force
- June 26, 2014
- Like
- 0
How to loop through the map values... Compile Error: Loop must iterate over a collection type: SOBJECT:Asset
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.
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.
- KR_Force
- June 17, 2014
- Like
- 0
System.QueryException: Non-selective query against large object type (more than 100000 rows)
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*******
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*******
- public static void ContactProductSubscription(List<Contact>newcontacts,set<ID>acIds){
- //set<id>acIds=new set<Id>();
- set<id>acIds1=new set<Id>();
- list<Asset>ast=new List<Asset>();
- List<Linked_Account__c>lActs=new List<Linked_Account__c>();
- List<Linked_Account__c>linkedAccounts=new List<Linked_Account__c>();
- Map<Id,Id>actLActMap=new Map<Id,Id>();
- Map<Id,Id>agentctLActMap=new Map<Id,Id>();
- Map<Id,ID>alActs=new Map<Id,ID>();
- Map<Id,Id>conActMap=new Map<Id,Id>();
- Map<ID,String>ActPfamilyMap=new Map<ID,String>();
- Map<ID,ID>lActAgentcontMap=new Map<ID,ID>();
- Map<ID,ID>lActAcontMap=new Map<ID,ID>();
- Map<ID,Asset>actAstMap=new Map<ID,Asset>();
- set<id>aContacts=new set<id>();//Agent Contacts
- set<string>pFamily=new set<string>();//Agent Contacts
- String psubscription;
- for(contact c :newcontacts){conActMap.put(c.id,c.accountID);}
- if(acids.size()>0){
- lActs=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
- Cases__c, Contacts__c, Expiration__c, Linked_Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
- where Agent__c=true and Contacts__c=true and (Expiration__c<>null OR Expiration__c >: date.today()) and Linked_Account__c in:acids ];
- }
- if(lActs.size()>0){
- for(Linked_Account__c l:lActs){
- aContacts.add(l.Agent_Contact__c);
- actLActMap.put(l.Linked_Account__c,l.id);
- agentctLActMap.put(l.Agent_Contact__c,l.id);
- }
- }
- if(aContacts.size()>0){
- linkedAccounts=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
- Cases__c, Contacts__c, Expiration__c, Linked_Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
- where Agent__c=false and isDeleted=false and Agent_Contact__c in:aContacts];
- }
- if(linkedAccounts.size()>0){
- For(Linked_Account__c l1:linkedAccounts){
- acIds1.add(l1.Linked_Account__c);
- lActAgentcontMap.put(l1.Linked_Account__c,l1.Agent_Contact__c);
- lActAcontMap.put(l1.id,l1.Linked_Account__c);
- //agentctLActMap.put(l1.Agent_Contact__c,l1.id);
- }
- }
- acIds1.addAll(acIds);
- if(acIds1.size()>0){ast=[select AccountId, Id, Product_Family__c FROM Asset where AccountId in:acIds1];}
- for(Asset a:ast){ActPfamilyMap.put(a.AccountId,a.Product_Family__c);
- actAstMap.put(a.AccountId,a);}
- for(contact c :newcontacts){
- Id lactID=actLActMap.get(c.AccountID);
- ID aContID=lActAgentcontMap.get(lactID);
- ID lactID1=agentctLActMap.get(aContID);
- ID ActID=lActAcontMap.get(lactID1);
- if(ActPfamilyMap.containsKey(ActID)||ActPfamilyMap.containsKey(c.AccountID)){
- for(Asset a1:[select AccountId, Id, Product_Family__c FROM Asset where AccountId =: c.AccountID OR AccountId=:ActID]){
- psubscription+=a1.Product_Family__c+'; ';
- c.productSubscriptions__c=psubscription;
- }
- }
- }
- }
- KR_Force
- June 16, 2014
- Like
- 0
Can some one please help me with this code??
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.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*******
- public static void ContactProductSubscription(List<Contact>newcontacts,set<ID>acIds){
- //set<id>acIds=new set<Id>();
- set<id>acIds1=new set<Id>();
- list<Asset>ast=new List<Asset>();
- List<Linked_Account__c>lActs=new List<Linked_Account__c>();
- List<Linked_Account__c>linkedAccounts=new List<Linked_Account__c>();
- Map<Id,Linked_Account__c>actLActMap=new Map<Id,Linked_Account__c>();
- Map<Id,ID>alActs=new Map<Id,ID>();
- Map<Id,Id>conActMap=new Map<Id,Id>();
- Map<ID,String>ActPfamilyMap=new Map<ID,String>();
- set<id>aContacts=new set<id>();//Agent Contacts
- for(contact c :newcontacts){conActMap.put(c.id,c.accountID);}
- if(acids.size()>0){
- lActs=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
- Cases__c, Contacts__c, Expiration__c, Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
- where Agent__c=true and Contacts__c=true and (Expiration__c<>null OR Expiration__c >: date.today()) and Linked_Account__c in:acids ];
- }
- if(lActs.size()>0){
- for(Linked_Account__c l:lActs){
- aContacts.add(l.Agent_Contact__c);
- actLActMap.put(l.Linked_Account__c,l);
- }
- }
- if(aContacts.size()>0){
- linkedAccounts=[select Active__c, Agent__c, Name, Agent_Contact__c,Agent_Contact__r.account.ID,Agent_Contact_AccountId__c, Assets__c,
- Cases__c, Contacts__c, Expiration__c, Account__c, Id, User_Account__c, User_Contact__c FROM Linked_Account__c
- where Agent__c=false and isDeleted=false and Agent_Contact__c in:aContacts];
- }
- if(linkedAccounts.size()>0){
- For(Linked_Account__c l1:linkedAccounts){
- acIds1.add(l1.Account__c);
- //aContact.put(l1.Agent_Contact__c,l1.Account__c);
- }
- }
- acIds1.addAll(acIds);
- String psubscription;
- if(acIds1.size()>0){ast=[select AccountId, Id, Product_Family__c FROM Asset where AccountId in:acIds1];}
- for(Asset a:ast){ActPfamilyMap.put(a.AccountId,a.Product_Family__c);}
- for(contact c :newcontacts){
- list<Linked_Account__c>l1=actLActMap.get(c.AccountId);
- set<id>acts=add(c.accountid);
- for(Linked_Account__c l:l1){acts.add(alActs.get(l.Agent_Contact__c));
- List<Asset>ast=ActPfamilyMap.get(acts);
- }
- for(Asset a1:ast){
- psubscription+=a1.Product_Family__c+'; ';}
- c.productSubscriptions__c=psubscription;
- }
- }
- KR_Force
- June 16, 2014
- Like
- 0
Error while coding the Test Class when calling the method
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
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
- sailer
- January 27, 2014
- Like
- 0
Geolocation fields not updating on callout from GoogleMaps trigger.
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:
// 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.
I am sure I have just done something stupid but cannot see what I have done wrong!!
Any help would be greatly appreciated.
- David Holland
- October 15, 2012
- Like
- 0