- Terminusbot
- NEWBIE
- 130 Points
- Member since 2016
- CEO
- Terminus Consulting
-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
43Questions
-
34Replies
All Apex Callouts Across Production Experiencing Error: System.CalloutException: Read timed out
Did anything change in Salesforce over the weekend? Across all of our Apex Call Outs we are now getting this error:
System.CalloutException: Read timed out
Could this be associated with the new TLS requirements? Anyone else experiencing something like this?
Thanks,
Ricky
System.CalloutException: Read timed out
Could this be associated with the new TLS requirements? Anyone else experiencing something like this?
Thanks,
Ricky
- Terminusbot
- September 19, 2017
- Like
- 0
Lightning SLDS File Selector - Detect Drag and Drop States
I am trying to understand how to modify the state of the Lightning Design System File Selector. Here is the base variant below. See bold and underlined for the dropzone class.
When you want to change it to show the drag over blue highlight that line changes to the following:
My question is how do you know when a file is hovering over the dropzone to trigger the class swap?
Thanks for any guidance.
<lightning:layout horizontalAlign="center"> <div class="slds-form-element"> <span class="slds-form-element__label" id="file-selector-id"></span> <div class="slds-form-element__control"> <div class="slds-file-selector slds-file-selector_files"> <div class="slds-file-selector__dropzone"> <input type="file" class="slds-file-selector__input slds-assistive-text" accept="image/png" id="file-upload-input-01" aria-describedby="file-selector-id"/> <label class="slds-file-selector__body" for="file-upload-input-01"> <span class="slds-file-selector__button slds-button slds-button_neutral"> <lightning:icon iconName="utility:upload" variant="base" size="x-small"/> </span> <span class="slds-file-selector__text slds-medium-show">or Drop Files</span> </label> </div> </div> </div> </div> </lightning:layout>
When you want to change it to show the drag over blue highlight that line changes to the following:
<div class="slds-file-selector__dropzone slds-has-drag-over">
My question is how do you know when a file is hovering over the dropzone to trigger the class swap?
Thanks for any guidance.
- Terminusbot
- August 31, 2017
- Like
- 0
WSDL: There is an error in XML document ---> System.FormatException: The string '' is not a valid Boolean value.
I'm sending a Web Service request by calling an external WSDL I imported to Salesforce and I'm getting the following error:
I have used over methods in the WSDL and they work just fine so the WSDL appears to be ok. I used Postman to initially send over the Soap request to confirm my request will work and it does. When I use the imported WSDL class to send it over I get the above error.
Here is my Apex Class that is calling the WSDL class.
I have hardcoded some values for testing. I read on some of the forums that this could be due to issues with DateTime fields. I tried to elimiate the use of DateTime and still getting the error.
Any suggestions?
Thanks!
There is an error in XML document (1, 860). ---> System.FormatException: The string '' is not a valid Boolean value.
I have used over methods in the WSDL and they work just fine so the WSDL appears to be ok. I used Postman to initially send over the Soap request to confirm my request will work and it does. When I use the imported WSDL class to send it over I get the above error.
Here is my Apex Class that is calling the WSDL class.
public with sharing class UpdateSagittaPolicy { public static Boolean AsyncFlag = false; @Future(callout=true) public static void SendToSagitta(Set<ID> ids) { Map<ID, Policy__c> mapPolicies = getPolicy(ids); System.debug('Map Values: ' + mapPolicies); //Initialize Sagitta Services SagittaServices.Results sResult; SagittaServices.TransporterSoap port = new SagittaServices.TransporterSoap(); SagittaServices.AuthenticationHeader authHeader = new SagittaServices.AuthenticationHeader(); SagittaServices.Post post = new SagittaServices.Post(); // Update Accounts Confirmed with Client Code and Sagitta ID List<OpportunityLineItem> updProdLine = new List<OpportunityLineItem>(); Integer sizeOfMap = mapPolicies.size(); for(Policy__c polLine : mapPolicies.values()) { //Creating instances for complex data types. Postal Code, Producers, Servicers, Categeory Codes SagittaServices.policyUpdateMap policy = new SagittaServices.policyUpdateMap(); //Set Producer Code String prodCode = polLine.Producer_1__c; SagittaServices.ProducerCd prod = new SagittaServices.ProducerCd(); prod.Producer1Cd = prodCode; //Sagitta ID SagittaServices.ClientInfo sagID = new SagittaServices.ClientInfo(); sagID.ClientId = long.valueOf(polLine.SagittaID__c); //Client Info String sagClientId = '60703'; SagittaServices.ClientInfo accountInfo = new SagittaServices.ClientInfo(); accountInfo.ClientId = long.valueOf(sagClientId); //Generate Unique ID for GUID over to Sagitta String genGuid = string.ValueOf(Datetime.now().formatGMT('yyyyMMddHHmmssSSS')); //Date serviceDate = oppLine.ServiceDate; String transDateString = '2017-05-31'; Date transDate = date.valueOf(transDateString); //Transaction Info SagittaServices.TransactionInfo transInfo = new SagittaServices.TransactionInfo(); transInfo.TransactionType = 'XLC'; transInfo.TransactionDescription = 'Testing'; transInfo.TransactionDate = transDate; transInfo.FollowupDays = 30; //Set Login Credentials to AuthHeader authHeader.Account = 'xxxxx'; authHeader.Username = 'xxxxx'; authHeader.Password = 'xxxxx'; authHeader.Serverpool = 'xxxxx'; authHeader.Accesscode = null; authHeader.Onlinecode = null; port.AuthenticationHeader = authHeader; //------------------------Policy Insert Map------------------------------------------- String cancelReasonCode = 'N'; String effDate = '2017-03-15'; String cancDateString = '2017-05-31'; Date cancDate = date.valueOf(cancDateString); String polSagId = '579716'; policy.Guid = genGuid; policy.ClientInfo = accountInfo; policy.TransactionInformation = transInfo; policy.PolicyId = long.valueOf(polSagId); policy.PolicyEffectiveDt = date.valueOf(effDate); policy.CancellationTypeCd = 'P'; policy.CancDt = cancDate; policy.CancReasonCd = 'N'; policy.CancEvidence = 'C'; policy.CancNonrenewRenewDt = cancDate; System.debug('Policy Update' + policy); try { sResult = port.policyUpdate(policy); System.debug('Success:'+sResult.Success+'SagittaId:'+sResult.SagittaId+'SagittaCode:'+sResult.SagittaCode+'Errors:'); //If Succesful, update Account record with Sagitta ID and Client Code if(sResult.SagittaId != null) { System.debug('Sagitta Id Success'); } else { System.debug('Sagitta Id Error'); } } catch (Exception ex) { System.debug('ERROR: '+ ex); } } } private static Map<Id, Policy__c> getPolicy(Set<ID> ids){ Map<Id, Policy__c> oppPolicy; oppPolicy = new Map<ID, Policy__c>([SELECT Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, LastActivityDate, LastViewedDate, LastReferencedDate, Opportunity__c, Account__c, Effective_Date__c, Expiration_Date__c, Written_Premium__c, Policy_Status__c, Written_Agency_Comm__c, Written_Prod_Comm__c, Bill_To_Code__c, Billing_Method__c, Payee__c, Coverage_Name__c, Cov__c, Ins__c, Client_Code__c, State_Risk_is_Located__c, Insuror__c, Insuror_Name__c, Producer_1__c, Producer_2__c, AE__c, Dept__c, Carrier_Code__c, Coverage_Detail__c, Coverages__c, EstComPct__c, EstCommAmt__c, EstPremAmt__c, Policy_Term__c, Transaction_Type__c, SagittaID__c, SendQuery__c, //Policy_Effective_Month__c, //Producer__c, RecordTypeName__c, //Carrier_Code_Payee__c, Accounts__c, Product__c, //Coverage_Code_Product_Code__c, //Policy__c, Cancellation_Date__c, Cancellation_Method__c, Cancellation_Reason__c, Reinstatement_Date__c, Reinstatement_Reason__c, Cancellation_Request_Date__c, //Reinstatement_Entry_Date__c, Cancellation_Amount__c, Account_Sagitta_ID__c //Finance_Company__c, //Last_User__c FROM Policy__c Where ID in :ids ]); System.debug('Product Map Private' + oppPolicy); return oppPolicy; } }
I have hardcoded some values for testing. I read on some of the forums that this could be due to issues with DateTime fields. I tried to elimiate the use of DateTime and still getting the error.
Any suggestions?
Thanks!
- Terminusbot
- June 01, 2017
- Like
- 0
Lightning Component - Data Tables Styling Issue
I am creating a lightning component and I'm trying to style the data table using the example in the Lightning Design System documentation. I'm having trouble getting this to render correctly. Any ideas?
Here is what the example looks like:
Link to example:
https://www.lightningdesignsystem.com/components/data-tables/?variant=base
Here is how mine renders:
Here is what I am doing in the Component:
Thanks!!
Here is what the example looks like:
Link to example:
https://www.lightningdesignsystem.com/components/data-tables/?variant=base
Here is how mine renders:
Here is what I am doing in the Component:
<aura:component controller="AddPoliciesApexController" implements="force:LightningQuickAction,force:hasRecordId"> <aura:attribute name="policies" type="Policy__c[]" /> <aura:attribute name="addToOpp" type="Boolean" /> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <table class="slds-table slds-table_bordered slds-table_cell-buffer slds-table_striped"> <thead> <tr class="slds-text-title_caps"> <th scope="col"> <div class="slds-truncate" title="Policy Number">POLICY NUMBER</div> </th> <th scope="col"> <div class="slds-truncate" title="Effective Date">EFFECTIVE DATE</div> </th> <th scope="col"> <div class="slds-truncate" title="Expiration Date">EXPIRATION DATE</div> </th> <th scope="col"> <div class="slds-truncate" title="Coverage Code">COVERAGE</div> </th> <th scope="col"> <div class="slds-truncate" title="Add to Opp">ADD TO OPP?</div> </th> </tr> </thead> <tbody> </tbody> <aura:iteration items="{!v.policies}" var="pol" > <tr> <th scope="row" data-label="Policy Number"> <div class="slds-truncate" title="Policy Number"> <a href="javascript:void(0);">{!pol.Name}</a> </div> </th> <td data-label="Effective Date"> <div class="slds-truncate" title="Effective Date">{!pol.Effective_Date__c}</div> </td> <td data-label="Expiration Date"> <div class="slds-truncate" title="Expiration Date">{!pol.Expiration_Date__c}</div> </td> <td data-label="Coverage Code"> <div class="slds-truncate" title="Coverage Code">{!pol.Coverage_Code_Product_Code__c }</div> </td> <td data-label="Add to Opp"> <div class="slds-truncate" title="Add to Opp"> <ui:inputCheckbox class="slds-form-element" label="Add to Opp?"/> </div> </td> </tr> </aura:iteration> </table> </aura:component>
Thanks!!
- Terminusbot
- May 28, 2017
- Like
- 0
Has anyone converted a chatter thread to a PDF?
We need to store our corresponence in a 3rd party document management system and need to bring our Chatter posts into that system. Has anyone ever converted chatter to a PDF?
- Terminusbot
- May 03, 2017
- Like
- 0
Convert custom object and child objects to PDF or Lightning Page. Design Ideas
I have created a Flow that walks our users through entering data in a custom object (as well as child custom objects related to the main custom object). All of this is done from the Opportunity record.
The users would either like to see the data presented back to them in a PDF document or potentially a Lightning page. Before I journey down a certian path does anyone have any recommendations? My understanding is that if I want to generate a PDF usually you first create the Lightning page then render the PDF from that. If that is the case then I guess I have to create the Lightning page first either way.
Thanks for any advice or tips.
Ricky
The users would either like to see the data presented back to them in a PDF document or potentially a Lightning page. Before I journey down a certian path does anyone have any recommendations? My understanding is that if I want to generate a PDF usually you first create the Lightning page then render the PDF from that. If that is the case then I guess I have to create the Lightning page first either way.
Thanks for any advice or tips.
Ricky
- Terminusbot
- February 23, 2017
- Like
- 0
Best Practice: Refresh Record via Web Service Call - Moving to Lightning
I have a custom object called 'Policy__c'. I have a Trigger to fire a Web Service call when a Checkbox field is equal to True on the Policy__c object record.
When the checkbox is True the trigger fires the callout.
Before Lightning I would check this box via a JavaScript button called 'Policy Sync'. This worked great but we are now moving to Lightning.
What is the best way to handle this in Lightning?
When the checkbox is True the trigger fires the callout.
Before Lightning I would check this box via a JavaScript button called 'Policy Sync'. This worked great but we are now moving to Lightning.
What is the best way to handle this in Lightning?
- Terminusbot
- November 30, 2016
- Like
- 0
Deploy WSDL to Production: Test Class Best Approach?
I have generated Apex Class from a WSDL and it is large. I have created the integration and tested everything in Sandbox except for the test class that covers the entire WSDL. This look like a huge undertaking. Can someone point me in the right direciton on how to approach this test class?
Here is snippet class generated from my WSDL. Thanks for any help you can provide. ~Ricky
Here is snippet class generated from my WSDL. Thanks for any help you can provide. ~Ricky
public class SagittaServices { public class ArrayOfContainsArray { public SagittaServices.containsArray[] containsArray; private String[] containsArray_type_info = new String[]{'containsArray','http://amsservices.com/',null,'0','-1','true'}; private String[] apex_schema_type_info = new String[]{'http://amsservices.com/','true','false'}; private String[] field_order_type_info = new String[]{'containsArray'}; } public class policyDeleteResponse_element { public SagittaServices.Results policyDeleteResult; private String[] policyDeleteResult_type_info = new String[]{'policyDeleteResult','http://amsservices.com/',null,'0','1','false'}; private String[] apex_schema_type_info = new String[]{'http://amsservices.com/','true','false'}; private String[] field_order_type_info = new String[]{'policyDeleteResult'}; } public class Policies { public String PolicyNumber; private String[] PolicyNumber_type_info = new String[]{'PolicyNumber','http://amsservices.com/',null,'0','1','false'}; private String[] apex_schema_type_info = new String[]{'http://amsservices.com/','true','false'}; private String[] field_order_type_info = new String[]{'PolicyNumber'}; } public class clientUpdateResponse_element { public SagittaServices.Results clientUpdateResult; private String[] clientUpdateResult_type_info = new String[]{'clientUpdateResult','http://amsservices.com/',null,'0','1','false'}; private String[] apex_schema_type_info = new String[]{'http://amsservices.com/','true','false'}; private String[] field_order_type_info = new String[]{'clientUpdateResult'}; } public class InsurerReceivablePostingsInsert { public String InsurerReceivableId; public Decimal PostAmount; public String SplitAdjust; private String[] InsurerReceivableId_type_info = new String[]{'InsurerReceivableId','http://amsservices.com/',null,'0','1','false'}; private String[] PostAmount_type_info = new String[]{'PostAmount','http://amsservices.com/',null,'1','1','true'}; private String[] SplitAdjust_type_info = new String[]{'SplitAdjust','http://amsservices.com/',null,'1','1','true'}; private String[] apex_schema_type_info = new String[]{'http://amsservices.com/','true','false'}; private String[] field_order_type_info = new String[]{'InsurerReceivableId','PostAmount','SplitAdjust'}; } public class containsArray { public Integer ID; public String ClientName; public String ClientCd; public SagittaServices.StreetAddress StreetAddress; public String City; public String StateProvCd; public String PostalCode; public String ContactName; public SagittaServices.ArrayOfPolicies Policy; public SagittaServices.ArrayOfPolSerial PolicySerial; public SagittaServices.TelephoneNum Telephone; public String ClaimantName; public String FaxNumber; public String BillToCode; public SagittaServices.ProducerCd Prod; public SagittaServices.ServicerCd Serv; public SagittaServices.ArrayOfStatus Stat_x; public String Archived; public String ContactMethod; public String SIC1Cd; public String SourceCd; private String[] ID_type_info = new String[]{'ID','http://amsservices.com/',null,'1','1','true'}; private String[] ClientName_type_info = new String[]{'ClientName','http://amsservices.com/',null,'0','1','false'}; private String[] ClientCd_type_info = new String[]{'ClientCd','http://amsservices.com/',null,'0','1','false'}; private String[] StreetAddress_type_info = new String[]{'StreetAddress','http://amsservices.com/',null,'0','1','false'}; private String[] City_type_info = new String[]{'City','http://amsservices.com/',null,'0','1','false'}; private String[] StateProvCd_type_info = new String[]{'StateProvCd','http://amsservices.com/',null,'0','1','false'}; private String[] PostalCode_type_info = new String[]{'PostalCode','http://amsservices.com/',null,'0','1','false'}; private String[] ContactName_type_info = new String[]{'ContactName','http://amsservices.com/',null,'0','1','false'}; private String[] Policy_type_info = new String[]{'Policy','http://amsservices.com/',null,'0','1','false'}; private String[] PolicySerial_type_info = new String[]{'PolicySerial','http://amsservices.com/',null,'0','1','false'}; private String[] Telephone_type_info = new String[]{'Telephone','http://amsservices.com/',null,'0','1','false'}; private String[] ClaimantName_type_info = new String[]{'ClaimantName','http://amsservices.com/',null,'0','1','false'}; private String[] FaxNumber_type_info = new String[]{'FaxNumber','http://amsservices.com/',null,'0','1','false'}; private String[] BillToCode_type_info = new String[]{'BillToCode','http://amsservices.com/',null,'0','1','false'}; private String[] Prod_type_info = new String[]{'Prod','http://amsservices.com/',null,'0','1','false'}; private String[] Serv_type_info = new String[]{'Serv','http://amsservices.com/',null,'0','1','false'}; private String[] Stat_x_type_info = new String[]{'Stat','http://amsservices.com/',null,'0','1','false'}; private String[] Archived_type_info = new String[]{'Archived','http://amsservices.com/',null,'0','1','false'}; private String[] ContactMethod_type_info = new String[]{'ContactMethod','http://amsservices.com/',null,'0','1','false'}; private String[] SIC1Cd_type_info = new String[]{'SIC1Cd','http://amsservices.com/',null,'0','1','false'}; private String[] SourceCd_type_info = new String[]{'SourceCd','http://amsservices.com/',null,'0','1','false'}; private String[] apex_schema_type_info = new String[]{'http://amsservices.com/','true','false'}; private String[] field_order_type_info = new String[]{'ID','ClientName','ClientCd','StreetAddress','City','StateProvCd','PostalCode','ContactName','Policy','PolicySerial','Telephone','ClaimantName','FaxNumber','BillToCode','Prod','Serv','Stat_x','Archived','ContactMethod','SIC1Cd','SourceCd'}; } public class TransporterSoap { public String endpoint_x = 'http://167.206.227.210/sagittaws/transporter.asmx'; public Map<String,String> inputHttpHeaders_x; public Map<String,String> outputHttpHeaders_x; public String clientCertName_x; public String clientCert_x; public String clientCertPasswd_x; public Integer timeout_x; public SagittaServices.AuthenticationHeader AuthenticationHeader; private String AuthenticationHeader_hns = 'AuthenticationHeader=http://amsservices.com/'; private String[] ns_map_type_info = new String[]{'http://amsservices.com/', 'SagittaServices'}; public SagittaServices.Results policyDelete(String Guid,Long PolicyId,String StaffUser) { SagittaServices.policyDelete_element request_x = new SagittaServices.policyDelete_element(); request_x.Guid = Guid; request_x.PolicyId = PolicyId; request_x.StaffUser = StaffUser; SagittaServices.policyDeleteResponse_element response_x; Map<String, SagittaServices.policyDeleteResponse_element> response_map_x = new Map<String, SagittaServices.policyDeleteResponse_element>(); response_map_x.put('response_x', response_x); WebServiceCallout.invoke( this, request_x, response_map_x, new String[]{endpoint_x, 'http://amsservices.com/policyDelete', 'http://amsservices.com/', 'policyDelete', 'http://amsservices.com/', 'policyDeleteResponse', 'SagittaServices.policyDeleteResponse_element'} ); response_x = response_map_x.get('response_x'); return response_x.policyDeleteResult; } public SagittaServices.Results importResults(String Guid) { SagittaServices.importResults_element request_x = new SagittaServices.importResults_element(); request_x.Guid = Guid; SagittaServices.importResultsResponse_element response_x; Map<String, SagittaServices.importResultsResponse_element> response_map_x = new Map<String, SagittaServices.importResultsResponse_element>(); response_map_x.put('response_x', response_x); WebServiceCallout.invoke( this, request_x, response_map_x, new String[]{endpoint_x, 'http://amsservices.com/importResults', 'http://amsservices.com/', 'importResults', 'http://amsservices.com/', 'importResultsResponse', 'SagittaServices.importResultsResponse_element'} ); response_x = response_map_x.get('response_x'); return response_x.importResultsResult; }
- Terminusbot
- November 01, 2016
- Like
- 0
Trigger Deploy Fail: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: List Index out of bounds: 0
I have created a trigger on a custom object and a test class to migrate it. I have over 95% code coverage and when I deploy to Production I get this error.
It can't find an ID I am querying for even though I know it exists in Production as well as Sandbox. Here is my trigger. I have set the line 38 in the trigger to BOLD and Underline so you can see it.
Here is my test class. I have set (seeAllData=true).
10:38:50:047 FATAL_ERROR System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateNewOpp: execution of AfterInsert 10:38:47:000 FATAL_ERROR Trigger.CreateNewOpp: line 38, column 1: []
It can't find an ID I am querying for even though I know it exists in Production as well as Sandbox. Here is my trigger. I have set the line 38 in the trigger to BOLD and Underline so you can see it.
trigger CreateNewOpp on Policy__c (after insert) { System.debug('Create New Opp Fired'); //List of Opportunities to Create and Associate Policy List<Opportunity> createOpps = new List<Opportunity>(); for (Policy__c polInfo : Trigger.new) { //Create Opportunity Opportunity createOpp = new Opportunity(); //Policy Number String polNumber = polInfo.Name; if (polNumber.containsIgnoreCase('APP')){ System.debug('Found New Policy Opportunity' + polInfo.Name); //Find Owner and Type of Business Account List<Account> acctId = new List<Account>([Select OwnerId, RecordTypeId From Account Where Id =:polInfo.account__c LIMIT 1]); List<RecordType> lookupRecId = new List<RecordType>([Select Id, Name From RecordType Where Id=:acctId.get(0).RecordTypeId LIMIT 1]); List<RecordType> recTypeList = new List<RecordType>(); if (lookupRecId.get(0).Name == 'Individual') { recTypeList = [Select Id From RecordType Where Name = 'Commercial Lines' LIMIT 1]; System.debug('Inside IF Record Type' + recTypeList.get(0).Id); } else { recTypeList = [Select Id From RecordType Where Name = 'Personal Lines' LIMIT 1]; System.debug('Inside IF Record Type' + recTypeList.get(0).Id); } System.debug('Outside IF Record Type' + recTypeList.get(0).Id); System.debug('Opporunity Account' + polInfo.account__c); //Set New Opportunity Values createOpp.Name = 'New ' + polInfo.Coverage_Detail__c + ' Opportunity'; createOpp.AccountId = polInfo.account__c; createOpp.RecordTypeId = recTypeList.get(0).Id; createOpp.StageName = 'Marketing'; createOpp.CloseDate = polInfo.Effective_Date__c; createOpp.Amount = polInfo.EstPremAmt__c; createOpp.RefSagittaID__c = polInfo.SagittaID__c; createOpp.OwnerId = acctId.get(0).OwnerId; createOpps.add(createOpp); } if (createOpps.size()>=1){ for (Opportunity opp : createOpps) { try { System.debug('Create these Opps' + createOpps); insert opp; } catch(DmlException e) { System.debug('The following exception has occurred during update: ' + e.getMessage()); } } } } }
Here is my test class. I have set (seeAllData=true).
@isTest(seeAllData=true) private class TestNewOpp { @isTest static void test_method_one() { DateTime dT = System.now(); Date myDate = date.newinstance(dT.year(), dT.month(), dT.day()); //Lookup RecordType Id RecordType typeOfRecord = [Select Id From RecordType Where Name = 'Individual' LIMIT 1]; //Lookup House User User acctOwner = [Select Id From User Where Sagitta_User_Code__c = 'HO' LIMIT 1]; // Create Account With Parameters // list Accounts to Update Account myAccount = new Account(); myAccount.Name = 'Test Account'; myAccount.Email__c = 'testing@rampartinsurance.com'; myAccount.Phone = '5555555555'; myAccount.RecordTypeId = typeOfRecord.Id; myAccount.OwnerId = acctOwner.Id; myAccount.Preferred_Method_of_Contact__c = 'Email'; insert myAccount; Account latestAccount = [Select Id, RecordTypeId From Account Where Id=: myAccount.Id LIMIT 1]; //Create Coverage for Test Coverages__c testCov = new Coverages__c(); testCov.Name = 'TEST1'; testCov.Description__c = 'Testing Coverage Detail'; insert testCov; Coverages__c latestCov = [Select Id From Coverages__c Where Id =: testCov.Id LIMIT 1]; //Create Policy Policy__c myPolicy = new Policy__c(); myPolicy.Name = 'APP12345'; myPolicy.Account__c = latestAccount.Id; myPolicy.EstPremAmt__c = 10000; myPolicy.Effective_Date__c = myDate; myPolicy.SagittaID__c = '10000'; myPolicy.Coverages__c = latestCov.Id; insert myPolicy; } }
- Terminusbot
- October 26, 2016
- Like
- 0
Test Class for Apex Scheduler that executes a Callout
I am trying to create a class that does nothing more than fire a set of Apex Scheduler classes I have created. Here is the test class I have created to execute them.
I am getting an error becuase in the Scheduler classes they do nothing more than fire off a Callout to an external system. The test class fails since the class is executing a callout class.
I was thinking about using "if (Test.isRunningTest())" and try and avoid this but wanted to see if anyone has any better design patterns here.
One of my scheduler classes. The other one is the exact same just calls a different callout.
I already have a Test Class and MockClass for the Callouts.
Thanks for you help.
@isTest(seeAllData=true) private class TestCronClass { @isTest static void executeCrons() { String sch = '0 0 23 * * ?'; Test.StartTest(); ClientDetlaCron clientCron = new ClientDetlaCron(); System.schedule('Test Client Cron', sch, clientCron); PolicyCronBatchQuery policyCron = new PolicyCronBatchQuery(); System.schedule('Test Policy Cron', sch, policyCron); Test.stopTest(); } }
I am getting an error becuase in the Scheduler classes they do nothing more than fire off a Callout to an external system. The test class fails since the class is executing a callout class.
I was thinking about using "if (Test.isRunningTest())" and try and avoid this but wanted to see if anyone has any better design patterns here.
One of my scheduler classes. The other one is the exact same just calls a different callout.
global class ClientDetlaCron implements Schedulable { global void execute(SchedulableContext sc) { // Fire Soap Request to Sagitta for Changes in Policy Data ClientBatchQuery.sendBatchQuery(); } }
I already have a Test Class and MockClass for the Callouts.
Thanks for you help.
- Terminusbot
- October 23, 2016
- Like
- 0
Sandbox to Production Deploy Issue: Code Coverage Over 95% and Fails
I am trying to deploy my Apex Classes and Trigger to Production. I have confirmed these code coverages in Mavensmate and Developer Console.
When I deploy. I get this error. I also see this error when I try and deploy from Eclipse.
I am starting to scramlbe here since I need these in Production by Monday. Thanks for any help you may be able to provide.
When I deploy. I get this error. I also see this error when I try and deploy from Eclipse.
I am starting to scramlbe here since I need these in Production by Monday. Thanks for any help you may be able to provide.
- Terminusbot
- October 22, 2016
- Like
- 0
Sandbox and Production IP - Integration Request Question
Like most companies we have a number of Sandbox envirnoments along with Production. We have integration confiugred in our Sandbox envirnoments that calls our companies Public IP and we have added a NAT to route those requests to an internal IP. Since the range of IPs are the same for Sandbox and Production how do you distinguish between Production / Sandbox requests??
We are getting close to migrating the new integration to Production and need to iron this out.
We are getting close to migrating the new integration to Production and need to iron this out.
- Terminusbot
- October 17, 2016
- Like
- 0
FATAL_ERROR System.TypeException: Invalid decimal: 3,259.00
I am getting an invalid decimal error when trying to update a field with a type of Current (16,2).
The value of aText is 3,259.00.
When I copy that exact value in the front end it saves no problem. Not sure why this is happening.
The value of aText is 3,259.00.
When I copy that exact value in the front end it saves no problem. Not sure why this is happening.
policyDetails.EstPremAmt__c = Decimal.valueOf(aText);
- Terminusbot
- August 25, 2016
- Like
- 0
Test Class: System.XmlException: Failed to parse XML due to: only whitespace content allowed before start tag??
Hello All.
I am running into a strange issue when executing a test class on a @future callout. The error message is below.
It is failing at 'doc.load(toParse);' which is where I load my XML response into the DOM for reading. Here is my callout
I am running into a strange issue when executing a test class on a @future callout. The error message is below.
System.XmlException: Failed to parse XML due to: only whitespace content allowed before start tag and not { (position: START_DOCUMENT seen {... @1:1)
It is failing at 'doc.load(toParse);' which is where I load my XML response into the DOM for reading. Here is my callout
public with sharing class ClientBatchQuery { @future (callout=true) public static void sendBatchQuery() { String account; String username; String password; String serverpool; //Get Sagitta Info Main Record Data List<SagittaInfo__c> sagittaSettings = new List<SagittaInfo__c>([Select Id, Name, account__c, username__c, password__c, serverpool__c, Client_Date__c, Client_GTTIME__c,Client_LTTIME__c, Client_Sync_Sent__c,Client_Sync_Minutes__c,UniVerse_Time__c,Current_UniVerse_Time__c from SagittaInfo__c where Name = 'MAIN']); //Set login credentials for Saggita if (sagittaSettings.size()>0){ account = sagittaSettings.get(0).account__c; username = sagittaSettings.get(0).username__c; password = sagittaSettings.get(0).password__c; serverpool = sagittaSettings.get(0).serverpool__c; } // Create XmlStreamWriter XmlStreamWriter writer = new XmlStreamWriter(); //Build PassThroughReq Soap XML writer.writeStartDocument('utf-8','1.0'); writer.writeStartElement(null,'soap12:Envelope',null); writer.writeAttribute(null,null,'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); writer.writeAttribute(null,null,'xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); writer.writeAttribute(null,null, 'xmlns:soap12', 'http://www.w3.org/2003/05/soap-envelope'); writer.writeStartElement(null,'soap12:Body', null); writer.writeStartElement(null,'PassThroughReq',null); writer.writeAttribute(null,null,'xmlns', 'http://amsservices.com/'); writer.writeStartElement(null,'XMLinput',null); writer.writeStartElement(null,'INPUT',null); writer.writeStartElement(null,'Account',null); writer.writeAttribute(null,null,'value', account); writer.writeEndElement(); // Account Close writer.writeStartElement(null,'Username',null); writer.writeAttribute(null,null,'value', username); writer.writeEndElement(); // Username Close writer.writeStartElement(null,'Password',null); writer.writeAttribute(null,null,'value', password); writer.writeEndElement(); // Password Close writer.writeStartElement(null,'Serverpool',null); writer.writeAttribute(null,null,'value', serverpool); writer.writeEndElement(); // Serverpool Close writer.writeStartElement(null,'Access',null); writer.writeAttribute(null,null,'statement', 'LIST CLIENTS WITH AUDIT.DATE.TIME GT \\'+ String.valueOf(sagittaSettings.get(0).UniVerse_Time__c) +'\\ *OUTPUT* CLIENT.CODE CAT.CODE.1 CLIENT.NAME ADDR1 ADDR2 CITY STATE ZIP.CODE PRIME.PROD PRIME.SERVICER.NAME PHONE1 PHONE2 EMAIL.ADDRESS'); writer.writeEndElement(); // Access Close writer.writeEndElement(); // INPUT Close writer.writeEndElement(); // XMLinput Close writer.writeEndElement(); // PassThroughReq Close writer.writeEndElement(); // Soap Body Close writer.writeEndElement(); // Envelope Body Close // Write XML to String Variable string xml = writer.getXmlString(); System.debug('XML OUTPUT' + xml); //End XmlStreamWriter writer.close(); // Create instance of HttpRequest, HttpResponse, and Http. Preparing to send to XML to Saggita HttpRequest req = new HttpRequest(); HttpResponse res = new HttpResponse(); Http http = new Http(); // Set Method, Endpoint, Header, and Body details for SOAP request. req.setMethod('POST'); req.setEndpoint('http://167.206.227.210/sagittaws/transporter.asmx'); req.setHeader('Content-Type', 'text/xml'); req.setHeader('SOAPAction','http://amsservices.com/PassThroughReq'); req.setBody(xml); //Execute Callout try { res = http.send(req); } catch (System.CalloutException e) { System.debug('Callout error: '+ e); System.debug('Response to String' + res.toString()); } // Creating XMLStreamReader to read the response - Looking for SagittaID and Sagitta Client Code // Clean XMl response from Sagitta - Call cleanXML method String bodyXMLFinal = XMLCleaner.cleanXML(res.getBody()); //Create List of all Policy Records and Attributes to Update and Insert List<Account> clientUpsert = new List<Account>(); String toParse = bodyXMLFinal; String fileAttrValue; String itemAttribute; //Create DOM to read XML response DOM.Document doc = new DOM.Document(); doc.load(toParse); //Get Root DOM.XMLNode root = doc.getRootElement(); String nms = root.getNameSpace(); System.Debug('namespace: ' + nms); // http://www.w3.org/2003/05/soap-envelope DOM.XMLNode body = root.getChildElement('Body', nms); // Gets the body of the XML System.Debug('body: ' + body); List<DOM.XMLNode> bodyChildrenList = body.getChildElements(); for (DOM.XMLNode passThroughReqResponse : bodyChildrenList) { System.Debug('passThroughReqResponse: ' + passThroughReqResponse.getName()); List<DOM.XMLNode> passThroughReqResultList = passThroughReqResponse.getChildElements(); for (DOM.XMLNode passThroughReqResult : passThroughReqResultList) { System.Debug('passThroughReqResult: ' + passThroughReqResult.getName()); List<DOM.XMLNode> pickResponseList = passThroughReqResult.getChildElements(); for (DOM.XMLNode pickResponse : pickResponseList) { System.Debug('pickResponse: ' + pickResponse.getName()); List<DOM.XMLNode> filesList = pickResponse.getChildElements(); for (DOM.XMLNode files : filesList) { System.Debug('files: ' + files.getName()); List<DOM.XMLNode> fileList = files.getChildElements(); for (DOM.XMLNode file : fileList) { System.Debug('file: ' + file.getName()); List<DOM.XMLNode> itemList = file.getChildElements(); for (DOM.XMLNode item : itemList) { System.Debug('item: ' + item.getName()); itemAttribute = item.getAttributeValue('sagitem', null); System.Debug('item attribute sagitem: ' + itemAttribute); Account accountDetails = new Account(); if (!itemAttribute.startsWith('WEBSERVICE')) { System.debug('Item is not WEBSERVICE' + itemAttribute + ' Entering Data'); System.debug ('Updated Policy Details: ' + accountDetails); System.debug('Running query on : ' + itemAttribute); List<Account> lookUpID = new List<Account> ([Select Id from Account where SagittaID__c =:itemAttribute]); System.debug('Results for queory on : ' + itemAttribute + ': ' + lookUpID); if (!lookupId.isEmpty()) { System.debug('ID IS NOT EMPTY: ' + lookupID); accountDetails.Id = string.valueOf(lookupID.get(0).Id); System.debug('Adding ID to Policy Object: ' + lookupID); System.debug ('Updated Policy Details: ' + accountDetails); } accountDetails.SagittaId__c = itemAttribute; List<DOM.XMLNode> aList = item.getChildElements(); for (DOM.XMLNode a : aList) { String aPosition = a.getName(); String aText = a.getText(); System.Debug('a: ' + aPosition); System.Debug('text: ' + aText); if (aPosition != null && aPosition == 'a1') { //Client Code accountDetails.Client_Code__c = aText; accountDetails.Preferred_Method_of_Contact__c = 'Email'; } if (aPosition != null && aPosition == 'a2') { //Category Code String catCode; if (aText == 'COM') { catCode = 'Business'; } else { catCode = 'Individual'; } List<recordtype> recTypeId = new List<recordtype>([Select Id from recordtype where Name=:catCode]); accountDetails.recordtypeid = recTypeId.get(0).Id; System.debug('Adding Category Code to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a3') { //Account Name accountDetails.Name = aText; System.debug('Adding Account Name to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a4') { //Address 1 accountDetails.BillingStreet = aText; System.debug('Adding Address 1 to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a5') { //Address 2 // //System.debug('Adding Coverages to Policy Object: ' + aText); //System.debug ('Updated Policy Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a6') { //City accountDetails.BillingCity = aText; System.debug('Adding City to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a7') { //State accountDetails.BillingState = aText; System.debug('Adding State to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a8') { //ZipCode accountDetails.BillingPostalCode = aText; System.debug('Adding Zip Code to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a9') { //Producer Code String prodCode = aText; List<User> producerCode = [Select Id From User where Sagitta_User_Code__c =:prodCode ]; accountDetails.OwnerId = string.valueOf(producerCode[0].Id); System.debug('Adding Producer Code to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a10') { //Account Executive accountDetails.Account_Exec__c = aText; System.debug('Adding Account Exec to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a11') { //Phone1 accountDetails.Phone = aText; System.debug('Adding Phone to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a12') { //Phone2 accountDetails.Phone_2__c = aText; System.debug('Adding Phone 2 to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a13') { //Email accountDetails.Email__c = aText; System.debug('Adding Status to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } //End of A# lists } // End For aList } //If Sagitta ID Exists System.debug('Does Account` Details Exist?' + accountDetails); if (accountDetails.Name != null) { System.debug('Yes, add to clientUpsert List' + accountDetails); System.debug('Account Upsert List Before Add' + clientUpsert); clientUpsert.add(accountDetails); System.debug('Account Upsert List After Add' + clientUpsert); } } //item } // file } //files } //pickResponse } //passThroughReqResult } //passThroughReqResponse try { System.debug('Upsert These Records' + clientUpsert); upsert clientUpsert; } catch(DmlException e) { System.debug('The following exception has occurred during Upsert: ' + e.getMessage()); } System.debug('Succesfully Upserted the Following.' + clientUpsert); //Update Latest Request Date, GTTIME, LTTIME for next Policy Delta Sync SagittaInfo__c sagInfo = new SagittaInfo__c(); sagInfo.Id = sagittaSettings.get(0).Id; sagInfo.Client_Sync_Sent__c = false; update sagInfo; } }
Has anyone run into this before? Did some searching around the forums and saw the use of Test.isRunning() but not sure I want to exclude portions of my class when testing.
Thanks as always!
- Terminusbot
- August 24, 2016
- Like
- 0
@isTest Class: Code Coverage and Argument can't be null error: Issue with SOQL query?
I am in the process of creating a test class on a @future callout. I am running into an issue when the class is fired by the test class it thinks variables are null when I am setting it in the class.
Here is my test class:
When it calls 'ClientBatchQuery.sendBatchQuery();' it fails on a variable it finds to be null. Here is a snippet of my class and how I am setting those variables. As you can see I am creating a list that is populated by a SOQL query. When the test class run it triggers an error when it gets to the 'writer.writeAttribute(null,null,'value', account);'. Indicating Argument can't be null. Is there an issue running a test class in conjuction with a SOQL query?
Here is my test class:
@isTest public class TestClientQueryCallout { @isTest static void testCallout() { // Set mock callout class Test.setMock(HttpCalloutMock.class, new MockClientQueryResponse()); // Call method to test. // This causes a fake response to be sent // from the class that implements HttpCalloutMock. Test.startTest(); ClientBatchQuery.sendBatchQuery(); Test.stopTest(); HttpRequest req = new HttpRequest(); MockClientQueryResponse mock = new MockClientQueryResponse(); HttpResponse res = mock.respond(req); // Verify response received contains fake values String contentType = res.getHeader('Content-Type'); System.assert(contentType == 'text/xml'); String actualValue = res.getBody(); String expectedValue = '{"foo":"bar"}'; System.assertEquals(actualValue, expectedValue); System.assertEquals(200, res.getStatusCode()); } }
When it calls 'ClientBatchQuery.sendBatchQuery();' it fails on a variable it finds to be null. Here is a snippet of my class and how I am setting those variables. As you can see I am creating a list that is populated by a SOQL query. When the test class run it triggers an error when it gets to the 'writer.writeAttribute(null,null,'value', account);'. Indicating Argument can't be null. Is there an issue running a test class in conjuction with a SOQL query?
public static void sendBatchQuery() { String account; String username; String password; String serverpool; //Get Sagitta Info Main Record Data List<SagittaInfo__c> sagittaSettings = new List<SagittaInfo__c>([Select Id, Name, account__c, username__c, password__c, serverpool__c, Client_Date__c, Client_GTTIME__c,Client_LTTIME__c, Client_Sync_Sent__c,Client_Sync_Minutes__c,UniVerse_Time__c,Current_UniVerse_Time__c from SagittaInfo__c where Name = 'MAIN']); //Set login credentials for Saggita if (sagittaSettings.size()>0){ account = sagittaSettings.get(0).account__c; username = sagittaSettings.get(0).username__c; password = sagittaSettings.get(0).password__c; serverpool = sagittaSettings.get(0).serverpool__c; } // Create XmlStreamWriter XmlStreamWriter writer = new XmlStreamWriter(); //Build PassThroughReq Soap XML writer.writeStartDocument('utf-8','1.0'); writer.writeStartElement(null,'soap12:Envelope',null); writer.writeAttribute(null,null,'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); writer.writeAttribute(null,null,'xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); writer.writeAttribute(null,null, 'xmlns:soap12', 'http://www.w3.org/2003/05/soap-envelope'); writer.writeStartElement(null,'soap12:Body', null); writer.writeStartElement(null,'PassThroughReq',null); writer.writeAttribute(null,null,'xmlns', 'http://amsservices.com/'); writer.writeStartElement(null,'XMLinput',null); writer.writeStartElement(null,'INPUT',null); writer.writeStartElement(null,'Account',null); writer.writeAttribute(null,null,'value', account); writer.writeEndElement(); // Account Close writer.writeStartElement(null,'Username',null); writer.writeAttribute(null,null,'value', username); writer.writeEndElement(); // Username Close writer.writeStartElement(null,'Password',null); writer.writeAttribute(null,null,'value', password); writer.writeEndElement(); // Password Close writer.writeStartElement(null,'Serverpool',null); writer.writeAttribute(null,null,'value', serverpool); writer.writeEndElement(); // Serverpool Close writer.writeStartElement(null,'Access',null); writer.writeAttribute(null,null,'statement', 'LIST CLIENTS WITH AUDIT.DATE.TIME GT \\'+ String.valueOf(sagittaSettings.get(0).UniVerse_Time__c) +'\\ *OUTPUT* CLIENT.CODE CAT.CODE.1 CLIENT.NAME ADDR1 ADDR2 CITY STATE ZIP.CODE PRIME.PROD PRIME.SERVICER.NAME PHONE1 PHONE2 EMAIL.ADDRESS'); writer.writeEndElement(); // Access Close writer.writeEndElement(); // INPUT Close writer.writeEndElement(); // XMLinput Close writer.writeEndElement(); // PassThroughReq Close writer.writeEndElement(); // Soap Body Close writer.writeEndElement(); // Envelope Body Close
- Terminusbot
- August 24, 2016
- Like
- 0
MockHttpResponse for @Future Callouts - Test Class
I'm reading through the documentation and the example provide shows the following for creating a test class using MockHttpResponse.
Since my class is @future it does not return anything. How do I approach creating the test class for a callout that does not return anything. I've been reading and see the use of Test.startTest() and Test.stopTest() but not sure where to apply that in my test class.
Thanks for the help.
@isTest private class CalloutClassTest { @isTest static void testCallout() { // Set mock callout class Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator()); // Call method to test. // This causes a fake response to be sent // from the class that implements HttpCalloutMock. HttpResponse res = CalloutClass.getInfoFromExternalService(); // Verify response received contains fake values String contentType = res.getHeader('Content-Type'); System.assert(contentType == 'application/json'); String actualValue = res.getBody(); String expectedValue = '{"foo":"bar"}'; System.assertEquals(actualValue, expectedValue); System.assertEquals(200, res.getStatusCode()); } }
Since my class is @future it does not return anything. How do I approach creating the test class for a callout that does not return anything. I've been reading and see the use of Test.startTest() and Test.stopTest() but not sure where to apply that in my test class.
Thanks for the help.
- Terminusbot
- August 24, 2016
- Like
- 0
Test Class: WebServiceMock - Any advice on how to create a test class for the following callout?
Here is my class that I need to create a test class for:
public class ConfirmAccount{ public static Boolean AsyncFlag = false; @Future(callout=true) public static void confirmAccountName(Set<ID> ids) { try { Map<ID, Account> mapAccnt = getAccounts(ids); //Initialize Sagitta Services SagittaServices.Results sResult; SagittaServices.TransporterSoap port = new SagittaServices.TransporterSoap(); SagittaServices.AuthenticationHeader authHeader = new SagittaServices.AuthenticationHeader(); SagittaServices.Post post = new SagittaServices.Post(); for(Account accnt : mapAccnt.values()){ //Creating instances for complex data types. Postal Code, Producers, Servicers, Categeory Codes SagittaServices.clientInsertMap accounts = new SagittaServices.clientInsertMap(); //Get Sagitta Code from Account Owner and Set Producer Code List<User> accountOwner = [Select Sagitta_User_Code__c From User where id =: accnt.ownerid]; String prodCode = string.valueOf(accountOwner[0].Sagitta_User_Code__c); SagittaServices.ProducerCd prod = new SagittaServices.ProducerCd(); prod.Producer1Cd = prodCode; //Servicer Codes SagittaServices.ServicerCd serv = new SagittaServices.ServicerCd(); serv.Servicer1Cd = 'HO'; //Category Codes String catCode1; if (accnt.RecordType.Name == 'Business') { catCode1 = 'COM'; } else { catCode1 = 'PER'; } SagittaServices.CatCd catCode = new SagittaServices.CatCd(); catCode.Cat1Cd = catCode1; //Postal Code SagittaServices.Post postCodes = new SagittaServices.Post(); postCodes.PostalCode = accnt.BillingPostalCode; //TODO: Understand and set Sic Code //SagittaServices.SicCd sicCode = new SagittaServices.SicCd(); //Generate Unique ID for GUID over to Sagitta String genGuid = string.ValueOf(Datetime.now().formatGMT('yyyyMMddHHmmssSSS')); //Set Login Credentials to AuthHeader authHeader.Account = 'xxxxx'; authHeader.Username = 'xxxxx'; authHeader.Password = 'xxxxx'; authHeader.Serverpool = 'xxxxx'; port.AuthenticationHeader = authHeader; //Client Insert Map accounts.Guid = genGuid; accounts.ClientName = accnt.Name; accounts.DivisionNumber = 01; accounts.Addr1 = accnt.BillingStreet; String Addr2; accounts.City = accnt.BillingCity; accounts.StateProvCd = accnt.BillingState; accounts.PostCd = postCodes; accounts.Phone1Number = long.ValueOf(accnt.Phone.replaceAll('\\D', '')); accounts.Phone2Number = long.ValueOf(accnt.Phone_2__c.replaceAll('\\D', '')); accounts.FaxNumber = accnt.Fax.replaceAll('\\D', ''); accounts.WebSiteLink = accnt.Website; accounts.ContactMethod = accnt.Preferred_Method_of_Contact__c; accounts.EmailAddr = accnt.Email__c; accounts.ProducerCd = prod; accounts.ServicerCd = serv; accounts.CatCd = catCode; accounts.NetCommissionPct = accnt.Net_Commision__c; accounts.FEIN = Integer.valueOf(accnt.FEIN__c); accounts.DateBusinessStarted = accnt.Business_Start_Date__c; accounts.InspectionContact = accnt.Inspection_Contact__c; accounts.InspectionPhoneNumber = long.ValueOf(accnt.Inspection_Phone_Number__c.replaceAll('\\D', '')); accounts.InspectionPhoneExtensionNumber = Integer.valueOf(accnt.Inspection_Phone_Extension_Number__c); accounts.AccountingContact = accnt.Accounting_Contact__c; accounts.AccountingPhoneNumber = long.ValueOf(accnt.Accounting_Phone_Number__c.replaceAll('\\D', '')); accounts.AccountingPhoneExtensionNumber = Integer.valueOf(accnt.Accounting_Phone_Extension_Number__c); accounts.Phone1ExtensionNumber = Integer.valueOf(accnt.Phone_Ext__c); accounts.Phone2ExtensionNumber = Integer.valueOf(accnt.Phone_2_Ext__c); //TODO: Add fields /* String ReferenceCd; String CommentaryRemarkText; String CreditTerms; String SourceCd; DateTime SourceDt; String LegalEntityCd; SagittaServices.BusinessNature BusinessNature; Srting SicCd; */ //Execute Callout - Client Insert sResult = port.clientInsert(accounts); System.debug('Success:'+sResult.Success+'SagittaId:'+sResult.SagittaId+'SagittaCode:'+sResult.SagittaCode+'Errors:'); //If Succesful, update Account record with Sagitta ID and Client Code If (sResult.SagittaId != null & sResult.SagittaCode !=null) { accnt.SagittaId__c = string.ValueOf(sResult.SagittaId); accnt.Client_Code__c = sResult.SagittaCode; //String BillToCd; update accnt; } } AsyncFlag = true; } catch (Exception ex) { System.debug('ERROR: '+ ex); } } private static Map<Id, Account> getAccounts(Set<ID> ids){ Map<Id, Account> accounts; accounts = new Map<ID, Account>([Select ID, Name,BillingStreet,BillingCity,BillingState,FEIN__c, BillingPostalCode,Phone,Phone_2__c,Email__c,Fax,Website, Billing_Payment_Type__c,Sic,Preferred_Method_of_Contact__c,Net_Commision__c,Business_Start_Date__c,Inspection_Contact__c, Inspection_Phone_Number__c,Accounting_Contact__c,Accounting_Phone_Number__c, Accounting_Phone_Extension_Number__c,Inspection_Phone_Extension_Number__c,Phone_2_Ext__c, Phone_Ext__c, ownerid,RecordType.Name from Account where ID in :ids and recordtypeid in (Select Id from RecordType where sobjecttype = 'Account')]); System.debug('Account Map Private' + accounts); return accounts; } }
- Terminusbot
- August 17, 2016
- Like
- 0
Using XMLStreamReader or Dom to Read SOAP Response from AS400
I am getting a unique SOAP response from a SOAP query request I am doing from Salesforce to an external system (AS400).
This response is a product of a query I send to the external system asking what has changed and to provide certain fields that have changed. If you notice the first response is a map of the fields that will be in the response. "<a1>POLICY.NUMBER</a1> <a2>CLIENT.CODE</a2>"..ect..
I have tried to use XMLStreamReader and the DOM class, but I'm having trouble actually getting to the Item and corresponding A1,A2,A3 elements. Any ideas on how best to handle this response?
Also, there will be cases where there is more than one record that is returned so I will have to find every "File" that is returned (other than the index File) and make sure to assign all the values associated with that given File. Then continue looping through onto the next File and assign the other fields / values to that record.
Example of XML Response:
Here is a code snippet that I have hacked to work, but it is not efficient and often times hangs due to CPU usage. This continues on for each A# tag.
This response is a product of a query I send to the external system asking what has changed and to provide certain fields that have changed. If you notice the first response is a map of the fields that will be in the response. "<a1>POLICY.NUMBER</a1> <a2>CLIENT.CODE</a2>"..ect..
I have tried to use XMLStreamReader and the DOM class, but I'm having trouble actually getting to the Item and corresponding A1,A2,A3 elements. Any ideas on how best to handle this response?
Also, there will be cases where there is more than one record that is returned so I will have to find every "File" that is returned (other than the index File) and make sure to assign all the values associated with that given File. Then continue looping through onto the next File and assign the other fields / values to that record.
Example of XML Response:
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <PassThroughReqResponse xmlns="http://amsservices.com/"> <PassThroughReqResult><?xml version="1.0"?> <PickResponse> <Files> <File sagfile="WORK.7864470"> <Item sagitem="WEBSERVICE.TAGS*WORK.7864470"> <a1>POLICY.NUMBER</a1> <a2>CLIENT.CODE</a2> <a3>EFF.DATE</a3> <a4>EXP.DATE</a4> <a5>COV</a5> <a6>INS</a6> <a7>TERM</a7> <a8>POLICY.STATUS</a8> <a9>BILLING.METHOD</a9> <a10>31</a10> <a11>32</a11> <a12>33</a12> <a13>POLICY.STATUS</a13> <a14>NEW.REN</a14> <a15>CHG.TIME</a15> </Item> </File> <File sagfile="WORK.7864470"> <Item sagitem="579615"> <a1>TESTINGNEW</a1> <a2>ZIMJO1</a2> <a3>08/08/16</a3> <a4>08/08/17</a4> <a5>ARA</a5> <a6>CER</a6> <a7>A</a7> <a9>Agency Bill</a9> <a14>NEW</a14> <a15>12:06:46</a15> </Item> </File> </Files> </PickResponse></PassThroughReqResult> </PassThroughReqResponse> </soap:Body> </soap:Envelope>
Here is a code snippet that I have hacked to work, but it is not efficient and often times hangs due to CPU usage. This continues on for each A# tag.
//Capture SagittaID List<String> sagittaID = new List<String>(); //List values to be returned List<String> sagittaResponseTag = new List<String>(); sagittaResponseTag.add('Item'); sagittaResponseTag.add('a1'); //Client Code sagittaResponseTag.add('a2'); //Policy Number sagittaResponseTag.add('a3'); //Effective Date sagittaResponseTag.add('a4'); //Expiration Date sagittaResponseTag.add('a5'); //Cov sagittaResponseTag.add('a6'); //Insuror sagittaResponseTag.add('a7'); //Term sagittaResponseTag.add('a8'); //Policy Status sagittaResponseTag.add('a9'); //Billing Method sagittaResponseTag.add('a10'); //Written Prem sagittaResponseTag.add('a11'); //Written Agency Prem sagittaResponseTag.add('a12'); //Writer Producer Prem sagittaResponseTag.add('a13'); // Policy Status sagittaResponseTag.add('a14'); // New or Renewal for (Integer i = 0; i < sagittaResponseTag.size(); i ++) { while (reader.hasNext()) { //while there are more XML events if (reader.getEventType() == XmlTag.START_ELEMENT) { //if this is the opening tag String localName = reader.getlocalName(); String listTag = string.valueOf(sagittaResponseTag.get(i)); System.debug('Inside Loop :' + i + 'Local Tag Name :' + localName + 'Does this equal :' + listTag); if (sagittaResponseTag.get(i) == reader.getlocalName()) { if (sagittaResponseTag.get(i) == 'Item' && reader.getLocalName() == 'Item') { for (Integer a = 0; a < reader.getAttributeCount(); a ++) { if (reader.getAttributeLocalName(a).equals('sagitem')) { theSagittaIdValue = reader.getAttributeValueAt(a); sagittaID.add(theSagittaIdValue); System.debug('Found SagittaID: ' + i + ' Value :'+ theSagittaIdValue); } } } } } reader.next(); //advance to the next XML event if ('a1' == reader.getlocalName()) { System.debug('Found A1'); while(reader.hasNext()) { //while there are more XML events if (reader.getEventType() == XmlTag.END_ELEMENT) { //if this is the closing tag break; //exist the loop } else if (reader.getEventType() == XmlTag.CHARACTERS) { //if this is the content between the tags theSagittaCodeValue = reader.getText(); // grab the content if(theSagittaCodeValue != null) { sagittaClientCode.add(theSagittaCodeValue); System.debug('Sagitta Client Code: Insert' + ':' + theSagittaCodeValue ); } } } } reader.next(); //advance to the next XML event
- Terminusbot
- August 17, 2016
- Like
- 0
Apex Map: SOQL Query - Data Retrieval at Index
I have created an Apex Map that I populated with a SOQL query. I am on the rerieving end, but getting an error that the index is not valid.
Here is what I am doing:
What am I doing wrong? When I debug the map to the logs here is what is in the Map.
Thanks for any tips and advice!
Here is what I am doing:
Map<ID, SagittaInfo__c> sagLogin = new Map<ID, SagittaInfo__c>([Select Id, Name, Account__c, Username__c, Password__c, Serverpool__c from SagittaInfo__c where Name = 'MAIN']); authHeader.Account = string.ValueOf(saglogin.get('Account__c')); authHeader.Username = string.ValueOf(saglogin.get('Username__c')); authHeader.Password = string.ValueOf(saglogin.get('Password__c')); authHeader.Serverpool = string.ValueOf(saglogin.get('Serverpool__c'));
What am I doing wrong? When I debug the map to the logs here is what is in the Map.
09:16:28:041 USER_DEBUG [2]|DEBUG|Map{a068A000000ZOcDQAW=SagittaInfo__c:{Id=a068A000000ZOcDQAW, Name=MAIN, Account__c=gemdata, Username__c=wksmt, Password__c=adminwk, Serverpool__c=websvc}}
Thanks for any tips and advice!
- Terminusbot
- August 16, 2016
- Like
- 0
Custom Button: Call Apex Class with JavaScript from Buttom {Error}
I created a button on a custom object: Policy__c.
I want the button to fire and call an Apex Class. The method of the class I am calling takes a Set called ids.
Here is my JavaScript:
The error I am recieving when button is selected is the following:
It is showing the records Id as the variable that it can't find. Any help would be appreciated.
Just for refrence here is the class and method I am trying to call.
I want the button to fire and call an Apex Class. The method of the class I am calling takes a Set called ids.
Here is my JavaScript:
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")} var mySet = new Set(); mySet.add({!Policy__c.Id}); var result = sforce.apex.execute("ClientDelta","sendQuery",{ids: mySet}); alert(result); window.location.reload();
The error I am recieving when button is selected is the following:
A problem with the OnClick JavaScript for this button or link was encountered: Can't find variable: a0019000002vmyy
It is showing the records Id as the variable that it can't find. Any help would be appreciated.
Just for refrence here is the class and method I am trying to call.
global class ClientDelta { @future (callout=true) @RemoteAction global static void sendQuery(Set<ID> ids) { ...... }
- Terminusbot
- August 15, 2016
- Like
- 0
Lightning Component - Data Tables Styling Issue
I am creating a lightning component and I'm trying to style the data table using the example in the Lightning Design System documentation. I'm having trouble getting this to render correctly. Any ideas?
Here is what the example looks like:
Link to example:
https://www.lightningdesignsystem.com/components/data-tables/?variant=base
Here is how mine renders:
Here is what I am doing in the Component:
Thanks!!
Here is what the example looks like:
Link to example:
https://www.lightningdesignsystem.com/components/data-tables/?variant=base
Here is how mine renders:
Here is what I am doing in the Component:
<aura:component controller="AddPoliciesApexController" implements="force:LightningQuickAction,force:hasRecordId"> <aura:attribute name="policies" type="Policy__c[]" /> <aura:attribute name="addToOpp" type="Boolean" /> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <table class="slds-table slds-table_bordered slds-table_cell-buffer slds-table_striped"> <thead> <tr class="slds-text-title_caps"> <th scope="col"> <div class="slds-truncate" title="Policy Number">POLICY NUMBER</div> </th> <th scope="col"> <div class="slds-truncate" title="Effective Date">EFFECTIVE DATE</div> </th> <th scope="col"> <div class="slds-truncate" title="Expiration Date">EXPIRATION DATE</div> </th> <th scope="col"> <div class="slds-truncate" title="Coverage Code">COVERAGE</div> </th> <th scope="col"> <div class="slds-truncate" title="Add to Opp">ADD TO OPP?</div> </th> </tr> </thead> <tbody> </tbody> <aura:iteration items="{!v.policies}" var="pol" > <tr> <th scope="row" data-label="Policy Number"> <div class="slds-truncate" title="Policy Number"> <a href="javascript:void(0);">{!pol.Name}</a> </div> </th> <td data-label="Effective Date"> <div class="slds-truncate" title="Effective Date">{!pol.Effective_Date__c}</div> </td> <td data-label="Expiration Date"> <div class="slds-truncate" title="Expiration Date">{!pol.Expiration_Date__c}</div> </td> <td data-label="Coverage Code"> <div class="slds-truncate" title="Coverage Code">{!pol.Coverage_Code_Product_Code__c }</div> </td> <td data-label="Add to Opp"> <div class="slds-truncate" title="Add to Opp"> <ui:inputCheckbox class="slds-form-element" label="Add to Opp?"/> </div> </td> </tr> </aura:iteration> </table> </aura:component>
Thanks!!
- Terminusbot
- May 28, 2017
- Like
- 0
Trigger Deploy Fail: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: List Index out of bounds: 0
I have created a trigger on a custom object and a test class to migrate it. I have over 95% code coverage and when I deploy to Production I get this error.
It can't find an ID I am querying for even though I know it exists in Production as well as Sandbox. Here is my trigger. I have set the line 38 in the trigger to BOLD and Underline so you can see it.
Here is my test class. I have set (seeAllData=true).
10:38:50:047 FATAL_ERROR System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateNewOpp: execution of AfterInsert 10:38:47:000 FATAL_ERROR Trigger.CreateNewOpp: line 38, column 1: []
It can't find an ID I am querying for even though I know it exists in Production as well as Sandbox. Here is my trigger. I have set the line 38 in the trigger to BOLD and Underline so you can see it.
trigger CreateNewOpp on Policy__c (after insert) { System.debug('Create New Opp Fired'); //List of Opportunities to Create and Associate Policy List<Opportunity> createOpps = new List<Opportunity>(); for (Policy__c polInfo : Trigger.new) { //Create Opportunity Opportunity createOpp = new Opportunity(); //Policy Number String polNumber = polInfo.Name; if (polNumber.containsIgnoreCase('APP')){ System.debug('Found New Policy Opportunity' + polInfo.Name); //Find Owner and Type of Business Account List<Account> acctId = new List<Account>([Select OwnerId, RecordTypeId From Account Where Id =:polInfo.account__c LIMIT 1]); List<RecordType> lookupRecId = new List<RecordType>([Select Id, Name From RecordType Where Id=:acctId.get(0).RecordTypeId LIMIT 1]); List<RecordType> recTypeList = new List<RecordType>(); if (lookupRecId.get(0).Name == 'Individual') { recTypeList = [Select Id From RecordType Where Name = 'Commercial Lines' LIMIT 1]; System.debug('Inside IF Record Type' + recTypeList.get(0).Id); } else { recTypeList = [Select Id From RecordType Where Name = 'Personal Lines' LIMIT 1]; System.debug('Inside IF Record Type' + recTypeList.get(0).Id); } System.debug('Outside IF Record Type' + recTypeList.get(0).Id); System.debug('Opporunity Account' + polInfo.account__c); //Set New Opportunity Values createOpp.Name = 'New ' + polInfo.Coverage_Detail__c + ' Opportunity'; createOpp.AccountId = polInfo.account__c; createOpp.RecordTypeId = recTypeList.get(0).Id; createOpp.StageName = 'Marketing'; createOpp.CloseDate = polInfo.Effective_Date__c; createOpp.Amount = polInfo.EstPremAmt__c; createOpp.RefSagittaID__c = polInfo.SagittaID__c; createOpp.OwnerId = acctId.get(0).OwnerId; createOpps.add(createOpp); } if (createOpps.size()>=1){ for (Opportunity opp : createOpps) { try { System.debug('Create these Opps' + createOpps); insert opp; } catch(DmlException e) { System.debug('The following exception has occurred during update: ' + e.getMessage()); } } } } }
Here is my test class. I have set (seeAllData=true).
@isTest(seeAllData=true) private class TestNewOpp { @isTest static void test_method_one() { DateTime dT = System.now(); Date myDate = date.newinstance(dT.year(), dT.month(), dT.day()); //Lookup RecordType Id RecordType typeOfRecord = [Select Id From RecordType Where Name = 'Individual' LIMIT 1]; //Lookup House User User acctOwner = [Select Id From User Where Sagitta_User_Code__c = 'HO' LIMIT 1]; // Create Account With Parameters // list Accounts to Update Account myAccount = new Account(); myAccount.Name = 'Test Account'; myAccount.Email__c = 'testing@rampartinsurance.com'; myAccount.Phone = '5555555555'; myAccount.RecordTypeId = typeOfRecord.Id; myAccount.OwnerId = acctOwner.Id; myAccount.Preferred_Method_of_Contact__c = 'Email'; insert myAccount; Account latestAccount = [Select Id, RecordTypeId From Account Where Id=: myAccount.Id LIMIT 1]; //Create Coverage for Test Coverages__c testCov = new Coverages__c(); testCov.Name = 'TEST1'; testCov.Description__c = 'Testing Coverage Detail'; insert testCov; Coverages__c latestCov = [Select Id From Coverages__c Where Id =: testCov.Id LIMIT 1]; //Create Policy Policy__c myPolicy = new Policy__c(); myPolicy.Name = 'APP12345'; myPolicy.Account__c = latestAccount.Id; myPolicy.EstPremAmt__c = 10000; myPolicy.Effective_Date__c = myDate; myPolicy.SagittaID__c = '10000'; myPolicy.Coverages__c = latestCov.Id; insert myPolicy; } }
- Terminusbot
- October 26, 2016
- Like
- 0
FATAL_ERROR System.TypeException: Invalid decimal: 3,259.00
I am getting an invalid decimal error when trying to update a field with a type of Current (16,2).
The value of aText is 3,259.00.
When I copy that exact value in the front end it saves no problem. Not sure why this is happening.
The value of aText is 3,259.00.
When I copy that exact value in the front end it saves no problem. Not sure why this is happening.
policyDetails.EstPremAmt__c = Decimal.valueOf(aText);
- Terminusbot
- August 25, 2016
- Like
- 0
Test Class: System.XmlException: Failed to parse XML due to: only whitespace content allowed before start tag??
Hello All.
I am running into a strange issue when executing a test class on a @future callout. The error message is below.
It is failing at 'doc.load(toParse);' which is where I load my XML response into the DOM for reading. Here is my callout
I am running into a strange issue when executing a test class on a @future callout. The error message is below.
System.XmlException: Failed to parse XML due to: only whitespace content allowed before start tag and not { (position: START_DOCUMENT seen {... @1:1)
It is failing at 'doc.load(toParse);' which is where I load my XML response into the DOM for reading. Here is my callout
public with sharing class ClientBatchQuery { @future (callout=true) public static void sendBatchQuery() { String account; String username; String password; String serverpool; //Get Sagitta Info Main Record Data List<SagittaInfo__c> sagittaSettings = new List<SagittaInfo__c>([Select Id, Name, account__c, username__c, password__c, serverpool__c, Client_Date__c, Client_GTTIME__c,Client_LTTIME__c, Client_Sync_Sent__c,Client_Sync_Minutes__c,UniVerse_Time__c,Current_UniVerse_Time__c from SagittaInfo__c where Name = 'MAIN']); //Set login credentials for Saggita if (sagittaSettings.size()>0){ account = sagittaSettings.get(0).account__c; username = sagittaSettings.get(0).username__c; password = sagittaSettings.get(0).password__c; serverpool = sagittaSettings.get(0).serverpool__c; } // Create XmlStreamWriter XmlStreamWriter writer = new XmlStreamWriter(); //Build PassThroughReq Soap XML writer.writeStartDocument('utf-8','1.0'); writer.writeStartElement(null,'soap12:Envelope',null); writer.writeAttribute(null,null,'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); writer.writeAttribute(null,null,'xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); writer.writeAttribute(null,null, 'xmlns:soap12', 'http://www.w3.org/2003/05/soap-envelope'); writer.writeStartElement(null,'soap12:Body', null); writer.writeStartElement(null,'PassThroughReq',null); writer.writeAttribute(null,null,'xmlns', 'http://amsservices.com/'); writer.writeStartElement(null,'XMLinput',null); writer.writeStartElement(null,'INPUT',null); writer.writeStartElement(null,'Account',null); writer.writeAttribute(null,null,'value', account); writer.writeEndElement(); // Account Close writer.writeStartElement(null,'Username',null); writer.writeAttribute(null,null,'value', username); writer.writeEndElement(); // Username Close writer.writeStartElement(null,'Password',null); writer.writeAttribute(null,null,'value', password); writer.writeEndElement(); // Password Close writer.writeStartElement(null,'Serverpool',null); writer.writeAttribute(null,null,'value', serverpool); writer.writeEndElement(); // Serverpool Close writer.writeStartElement(null,'Access',null); writer.writeAttribute(null,null,'statement', 'LIST CLIENTS WITH AUDIT.DATE.TIME GT \\'+ String.valueOf(sagittaSettings.get(0).UniVerse_Time__c) +'\\ *OUTPUT* CLIENT.CODE CAT.CODE.1 CLIENT.NAME ADDR1 ADDR2 CITY STATE ZIP.CODE PRIME.PROD PRIME.SERVICER.NAME PHONE1 PHONE2 EMAIL.ADDRESS'); writer.writeEndElement(); // Access Close writer.writeEndElement(); // INPUT Close writer.writeEndElement(); // XMLinput Close writer.writeEndElement(); // PassThroughReq Close writer.writeEndElement(); // Soap Body Close writer.writeEndElement(); // Envelope Body Close // Write XML to String Variable string xml = writer.getXmlString(); System.debug('XML OUTPUT' + xml); //End XmlStreamWriter writer.close(); // Create instance of HttpRequest, HttpResponse, and Http. Preparing to send to XML to Saggita HttpRequest req = new HttpRequest(); HttpResponse res = new HttpResponse(); Http http = new Http(); // Set Method, Endpoint, Header, and Body details for SOAP request. req.setMethod('POST'); req.setEndpoint('http://167.206.227.210/sagittaws/transporter.asmx'); req.setHeader('Content-Type', 'text/xml'); req.setHeader('SOAPAction','http://amsservices.com/PassThroughReq'); req.setBody(xml); //Execute Callout try { res = http.send(req); } catch (System.CalloutException e) { System.debug('Callout error: '+ e); System.debug('Response to String' + res.toString()); } // Creating XMLStreamReader to read the response - Looking for SagittaID and Sagitta Client Code // Clean XMl response from Sagitta - Call cleanXML method String bodyXMLFinal = XMLCleaner.cleanXML(res.getBody()); //Create List of all Policy Records and Attributes to Update and Insert List<Account> clientUpsert = new List<Account>(); String toParse = bodyXMLFinal; String fileAttrValue; String itemAttribute; //Create DOM to read XML response DOM.Document doc = new DOM.Document(); doc.load(toParse); //Get Root DOM.XMLNode root = doc.getRootElement(); String nms = root.getNameSpace(); System.Debug('namespace: ' + nms); // http://www.w3.org/2003/05/soap-envelope DOM.XMLNode body = root.getChildElement('Body', nms); // Gets the body of the XML System.Debug('body: ' + body); List<DOM.XMLNode> bodyChildrenList = body.getChildElements(); for (DOM.XMLNode passThroughReqResponse : bodyChildrenList) { System.Debug('passThroughReqResponse: ' + passThroughReqResponse.getName()); List<DOM.XMLNode> passThroughReqResultList = passThroughReqResponse.getChildElements(); for (DOM.XMLNode passThroughReqResult : passThroughReqResultList) { System.Debug('passThroughReqResult: ' + passThroughReqResult.getName()); List<DOM.XMLNode> pickResponseList = passThroughReqResult.getChildElements(); for (DOM.XMLNode pickResponse : pickResponseList) { System.Debug('pickResponse: ' + pickResponse.getName()); List<DOM.XMLNode> filesList = pickResponse.getChildElements(); for (DOM.XMLNode files : filesList) { System.Debug('files: ' + files.getName()); List<DOM.XMLNode> fileList = files.getChildElements(); for (DOM.XMLNode file : fileList) { System.Debug('file: ' + file.getName()); List<DOM.XMLNode> itemList = file.getChildElements(); for (DOM.XMLNode item : itemList) { System.Debug('item: ' + item.getName()); itemAttribute = item.getAttributeValue('sagitem', null); System.Debug('item attribute sagitem: ' + itemAttribute); Account accountDetails = new Account(); if (!itemAttribute.startsWith('WEBSERVICE')) { System.debug('Item is not WEBSERVICE' + itemAttribute + ' Entering Data'); System.debug ('Updated Policy Details: ' + accountDetails); System.debug('Running query on : ' + itemAttribute); List<Account> lookUpID = new List<Account> ([Select Id from Account where SagittaID__c =:itemAttribute]); System.debug('Results for queory on : ' + itemAttribute + ': ' + lookUpID); if (!lookupId.isEmpty()) { System.debug('ID IS NOT EMPTY: ' + lookupID); accountDetails.Id = string.valueOf(lookupID.get(0).Id); System.debug('Adding ID to Policy Object: ' + lookupID); System.debug ('Updated Policy Details: ' + accountDetails); } accountDetails.SagittaId__c = itemAttribute; List<DOM.XMLNode> aList = item.getChildElements(); for (DOM.XMLNode a : aList) { String aPosition = a.getName(); String aText = a.getText(); System.Debug('a: ' + aPosition); System.Debug('text: ' + aText); if (aPosition != null && aPosition == 'a1') { //Client Code accountDetails.Client_Code__c = aText; accountDetails.Preferred_Method_of_Contact__c = 'Email'; } if (aPosition != null && aPosition == 'a2') { //Category Code String catCode; if (aText == 'COM') { catCode = 'Business'; } else { catCode = 'Individual'; } List<recordtype> recTypeId = new List<recordtype>([Select Id from recordtype where Name=:catCode]); accountDetails.recordtypeid = recTypeId.get(0).Id; System.debug('Adding Category Code to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a3') { //Account Name accountDetails.Name = aText; System.debug('Adding Account Name to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a4') { //Address 1 accountDetails.BillingStreet = aText; System.debug('Adding Address 1 to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a5') { //Address 2 // //System.debug('Adding Coverages to Policy Object: ' + aText); //System.debug ('Updated Policy Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a6') { //City accountDetails.BillingCity = aText; System.debug('Adding City to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a7') { //State accountDetails.BillingState = aText; System.debug('Adding State to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a8') { //ZipCode accountDetails.BillingPostalCode = aText; System.debug('Adding Zip Code to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a9') { //Producer Code String prodCode = aText; List<User> producerCode = [Select Id From User where Sagitta_User_Code__c =:prodCode ]; accountDetails.OwnerId = string.valueOf(producerCode[0].Id); System.debug('Adding Producer Code to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a10') { //Account Executive accountDetails.Account_Exec__c = aText; System.debug('Adding Account Exec to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a11') { //Phone1 accountDetails.Phone = aText; System.debug('Adding Phone to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a12') { //Phone2 accountDetails.Phone_2__c = aText; System.debug('Adding Phone 2 to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } if (aPosition != null && aPosition == 'a13') { //Email accountDetails.Email__c = aText; System.debug('Adding Status to Account Object: ' + aText); System.debug ('Updated Account Details: ' + accountDetails); } //End of A# lists } // End For aList } //If Sagitta ID Exists System.debug('Does Account` Details Exist?' + accountDetails); if (accountDetails.Name != null) { System.debug('Yes, add to clientUpsert List' + accountDetails); System.debug('Account Upsert List Before Add' + clientUpsert); clientUpsert.add(accountDetails); System.debug('Account Upsert List After Add' + clientUpsert); } } //item } // file } //files } //pickResponse } //passThroughReqResult } //passThroughReqResponse try { System.debug('Upsert These Records' + clientUpsert); upsert clientUpsert; } catch(DmlException e) { System.debug('The following exception has occurred during Upsert: ' + e.getMessage()); } System.debug('Succesfully Upserted the Following.' + clientUpsert); //Update Latest Request Date, GTTIME, LTTIME for next Policy Delta Sync SagittaInfo__c sagInfo = new SagittaInfo__c(); sagInfo.Id = sagittaSettings.get(0).Id; sagInfo.Client_Sync_Sent__c = false; update sagInfo; } }
Has anyone run into this before? Did some searching around the forums and saw the use of Test.isRunning() but not sure I want to exclude portions of my class when testing.
Thanks as always!
- Terminusbot
- August 24, 2016
- Like
- 0
@isTest Class: Code Coverage and Argument can't be null error: Issue with SOQL query?
I am in the process of creating a test class on a @future callout. I am running into an issue when the class is fired by the test class it thinks variables are null when I am setting it in the class.
Here is my test class:
When it calls 'ClientBatchQuery.sendBatchQuery();' it fails on a variable it finds to be null. Here is a snippet of my class and how I am setting those variables. As you can see I am creating a list that is populated by a SOQL query. When the test class run it triggers an error when it gets to the 'writer.writeAttribute(null,null,'value', account);'. Indicating Argument can't be null. Is there an issue running a test class in conjuction with a SOQL query?
Here is my test class:
@isTest public class TestClientQueryCallout { @isTest static void testCallout() { // Set mock callout class Test.setMock(HttpCalloutMock.class, new MockClientQueryResponse()); // Call method to test. // This causes a fake response to be sent // from the class that implements HttpCalloutMock. Test.startTest(); ClientBatchQuery.sendBatchQuery(); Test.stopTest(); HttpRequest req = new HttpRequest(); MockClientQueryResponse mock = new MockClientQueryResponse(); HttpResponse res = mock.respond(req); // Verify response received contains fake values String contentType = res.getHeader('Content-Type'); System.assert(contentType == 'text/xml'); String actualValue = res.getBody(); String expectedValue = '{"foo":"bar"}'; System.assertEquals(actualValue, expectedValue); System.assertEquals(200, res.getStatusCode()); } }
When it calls 'ClientBatchQuery.sendBatchQuery();' it fails on a variable it finds to be null. Here is a snippet of my class and how I am setting those variables. As you can see I am creating a list that is populated by a SOQL query. When the test class run it triggers an error when it gets to the 'writer.writeAttribute(null,null,'value', account);'. Indicating Argument can't be null. Is there an issue running a test class in conjuction with a SOQL query?
public static void sendBatchQuery() { String account; String username; String password; String serverpool; //Get Sagitta Info Main Record Data List<SagittaInfo__c> sagittaSettings = new List<SagittaInfo__c>([Select Id, Name, account__c, username__c, password__c, serverpool__c, Client_Date__c, Client_GTTIME__c,Client_LTTIME__c, Client_Sync_Sent__c,Client_Sync_Minutes__c,UniVerse_Time__c,Current_UniVerse_Time__c from SagittaInfo__c where Name = 'MAIN']); //Set login credentials for Saggita if (sagittaSettings.size()>0){ account = sagittaSettings.get(0).account__c; username = sagittaSettings.get(0).username__c; password = sagittaSettings.get(0).password__c; serverpool = sagittaSettings.get(0).serverpool__c; } // Create XmlStreamWriter XmlStreamWriter writer = new XmlStreamWriter(); //Build PassThroughReq Soap XML writer.writeStartDocument('utf-8','1.0'); writer.writeStartElement(null,'soap12:Envelope',null); writer.writeAttribute(null,null,'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); writer.writeAttribute(null,null,'xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); writer.writeAttribute(null,null, 'xmlns:soap12', 'http://www.w3.org/2003/05/soap-envelope'); writer.writeStartElement(null,'soap12:Body', null); writer.writeStartElement(null,'PassThroughReq',null); writer.writeAttribute(null,null,'xmlns', 'http://amsservices.com/'); writer.writeStartElement(null,'XMLinput',null); writer.writeStartElement(null,'INPUT',null); writer.writeStartElement(null,'Account',null); writer.writeAttribute(null,null,'value', account); writer.writeEndElement(); // Account Close writer.writeStartElement(null,'Username',null); writer.writeAttribute(null,null,'value', username); writer.writeEndElement(); // Username Close writer.writeStartElement(null,'Password',null); writer.writeAttribute(null,null,'value', password); writer.writeEndElement(); // Password Close writer.writeStartElement(null,'Serverpool',null); writer.writeAttribute(null,null,'value', serverpool); writer.writeEndElement(); // Serverpool Close writer.writeStartElement(null,'Access',null); writer.writeAttribute(null,null,'statement', 'LIST CLIENTS WITH AUDIT.DATE.TIME GT \\'+ String.valueOf(sagittaSettings.get(0).UniVerse_Time__c) +'\\ *OUTPUT* CLIENT.CODE CAT.CODE.1 CLIENT.NAME ADDR1 ADDR2 CITY STATE ZIP.CODE PRIME.PROD PRIME.SERVICER.NAME PHONE1 PHONE2 EMAIL.ADDRESS'); writer.writeEndElement(); // Access Close writer.writeEndElement(); // INPUT Close writer.writeEndElement(); // XMLinput Close writer.writeEndElement(); // PassThroughReq Close writer.writeEndElement(); // Soap Body Close writer.writeEndElement(); // Envelope Body Close
- Terminusbot
- August 24, 2016
- Like
- 0
MockHttpResponse for @Future Callouts - Test Class
I'm reading through the documentation and the example provide shows the following for creating a test class using MockHttpResponse.
Since my class is @future it does not return anything. How do I approach creating the test class for a callout that does not return anything. I've been reading and see the use of Test.startTest() and Test.stopTest() but not sure where to apply that in my test class.
Thanks for the help.
@isTest private class CalloutClassTest { @isTest static void testCallout() { // Set mock callout class Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator()); // Call method to test. // This causes a fake response to be sent // from the class that implements HttpCalloutMock. HttpResponse res = CalloutClass.getInfoFromExternalService(); // Verify response received contains fake values String contentType = res.getHeader('Content-Type'); System.assert(contentType == 'application/json'); String actualValue = res.getBody(); String expectedValue = '{"foo":"bar"}'; System.assertEquals(actualValue, expectedValue); System.assertEquals(200, res.getStatusCode()); } }
Since my class is @future it does not return anything. How do I approach creating the test class for a callout that does not return anything. I've been reading and see the use of Test.startTest() and Test.stopTest() but not sure where to apply that in my test class.
Thanks for the help.
- Terminusbot
- August 24, 2016
- Like
- 0
Using XMLStreamReader or Dom to Read SOAP Response from AS400
I am getting a unique SOAP response from a SOAP query request I am doing from Salesforce to an external system (AS400).
This response is a product of a query I send to the external system asking what has changed and to provide certain fields that have changed. If you notice the first response is a map of the fields that will be in the response. "<a1>POLICY.NUMBER</a1> <a2>CLIENT.CODE</a2>"..ect..
I have tried to use XMLStreamReader and the DOM class, but I'm having trouble actually getting to the Item and corresponding A1,A2,A3 elements. Any ideas on how best to handle this response?
Also, there will be cases where there is more than one record that is returned so I will have to find every "File" that is returned (other than the index File) and make sure to assign all the values associated with that given File. Then continue looping through onto the next File and assign the other fields / values to that record.
Example of XML Response:
Here is a code snippet that I have hacked to work, but it is not efficient and often times hangs due to CPU usage. This continues on for each A# tag.
This response is a product of a query I send to the external system asking what has changed and to provide certain fields that have changed. If you notice the first response is a map of the fields that will be in the response. "<a1>POLICY.NUMBER</a1> <a2>CLIENT.CODE</a2>"..ect..
I have tried to use XMLStreamReader and the DOM class, but I'm having trouble actually getting to the Item and corresponding A1,A2,A3 elements. Any ideas on how best to handle this response?
Also, there will be cases where there is more than one record that is returned so I will have to find every "File" that is returned (other than the index File) and make sure to assign all the values associated with that given File. Then continue looping through onto the next File and assign the other fields / values to that record.
Example of XML Response:
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <PassThroughReqResponse xmlns="http://amsservices.com/"> <PassThroughReqResult><?xml version="1.0"?> <PickResponse> <Files> <File sagfile="WORK.7864470"> <Item sagitem="WEBSERVICE.TAGS*WORK.7864470"> <a1>POLICY.NUMBER</a1> <a2>CLIENT.CODE</a2> <a3>EFF.DATE</a3> <a4>EXP.DATE</a4> <a5>COV</a5> <a6>INS</a6> <a7>TERM</a7> <a8>POLICY.STATUS</a8> <a9>BILLING.METHOD</a9> <a10>31</a10> <a11>32</a11> <a12>33</a12> <a13>POLICY.STATUS</a13> <a14>NEW.REN</a14> <a15>CHG.TIME</a15> </Item> </File> <File sagfile="WORK.7864470"> <Item sagitem="579615"> <a1>TESTINGNEW</a1> <a2>ZIMJO1</a2> <a3>08/08/16</a3> <a4>08/08/17</a4> <a5>ARA</a5> <a6>CER</a6> <a7>A</a7> <a9>Agency Bill</a9> <a14>NEW</a14> <a15>12:06:46</a15> </Item> </File> </Files> </PickResponse></PassThroughReqResult> </PassThroughReqResponse> </soap:Body> </soap:Envelope>
Here is a code snippet that I have hacked to work, but it is not efficient and often times hangs due to CPU usage. This continues on for each A# tag.
//Capture SagittaID List<String> sagittaID = new List<String>(); //List values to be returned List<String> sagittaResponseTag = new List<String>(); sagittaResponseTag.add('Item'); sagittaResponseTag.add('a1'); //Client Code sagittaResponseTag.add('a2'); //Policy Number sagittaResponseTag.add('a3'); //Effective Date sagittaResponseTag.add('a4'); //Expiration Date sagittaResponseTag.add('a5'); //Cov sagittaResponseTag.add('a6'); //Insuror sagittaResponseTag.add('a7'); //Term sagittaResponseTag.add('a8'); //Policy Status sagittaResponseTag.add('a9'); //Billing Method sagittaResponseTag.add('a10'); //Written Prem sagittaResponseTag.add('a11'); //Written Agency Prem sagittaResponseTag.add('a12'); //Writer Producer Prem sagittaResponseTag.add('a13'); // Policy Status sagittaResponseTag.add('a14'); // New or Renewal for (Integer i = 0; i < sagittaResponseTag.size(); i ++) { while (reader.hasNext()) { //while there are more XML events if (reader.getEventType() == XmlTag.START_ELEMENT) { //if this is the opening tag String localName = reader.getlocalName(); String listTag = string.valueOf(sagittaResponseTag.get(i)); System.debug('Inside Loop :' + i + 'Local Tag Name :' + localName + 'Does this equal :' + listTag); if (sagittaResponseTag.get(i) == reader.getlocalName()) { if (sagittaResponseTag.get(i) == 'Item' && reader.getLocalName() == 'Item') { for (Integer a = 0; a < reader.getAttributeCount(); a ++) { if (reader.getAttributeLocalName(a).equals('sagitem')) { theSagittaIdValue = reader.getAttributeValueAt(a); sagittaID.add(theSagittaIdValue); System.debug('Found SagittaID: ' + i + ' Value :'+ theSagittaIdValue); } } } } } reader.next(); //advance to the next XML event if ('a1' == reader.getlocalName()) { System.debug('Found A1'); while(reader.hasNext()) { //while there are more XML events if (reader.getEventType() == XmlTag.END_ELEMENT) { //if this is the closing tag break; //exist the loop } else if (reader.getEventType() == XmlTag.CHARACTERS) { //if this is the content between the tags theSagittaCodeValue = reader.getText(); // grab the content if(theSagittaCodeValue != null) { sagittaClientCode.add(theSagittaCodeValue); System.debug('Sagitta Client Code: Insert' + ':' + theSagittaCodeValue ); } } } } reader.next(); //advance to the next XML event
- Terminusbot
- August 17, 2016
- Like
- 0
Date Format Bug? Giving wrong day of the month
I am getting the current date using system.now and then trying to format my date into this format 'MM/dd/yyyy'.
When I log the current date is shows today (2016-08-11) which of course is correct. But, when I format the date is reflects the date as yesrterday (08/10/2016).
I am spinning my wheels. Has anyone run into this? Here is what I am doing.
When I log the current date is shows today (2016-08-11) which of course is correct. But, when I format the date is reflects the date as yesrterday (08/10/2016).
I am spinning my wheels. Has anyone run into this? Here is what I am doing.
DateTime now = system.now().date(); String day = now.format('dd'); String nowFormat = now.format('MM/dd/yyyy','EST'); System.debug('Right now Date: ' + now); System.debug('Day of the Month: ' + day); System.debug('Full Date: ' + nowFormat);
- Terminusbot
- August 11, 2016
- Like
- 0
Apex List: SOQL query Question
I am trying to get a string value off the User object. When I run a debug it is returning not only the Sagitta_User_Code__C, but the ID as well. I just want to get the Sagitta_User_Code__c. How do I isolate just the value of the Sagitta_User_Code__c.
Debug Log:
List<User> accountOwner = [Select Sagitta_User_Code__c From User where id =: accnt.ownerid]; System.debug('Sagitta Login: ' + '' + accountOwner);
Debug Log:
|USER_DEBUG|[22]|DEBUG|Sagitta Login: User:{Sagitta_User_Code__c=ral, Id=005400000032HgHAAU}
- Terminusbot
- June 28, 2016
- Like
- 0
Parent to Child Query
Parent Object: Account
Child Object:Sagitta Sequences
Master detail field to Accounts: Account
API Name: Account__c
Child Relationship Name: Sagitta_Sequences
I am trying to run a query from the account object and get the Sagitta Sequences Name field. This works to return the records that have the child record associated.
Thanks for the help.
Child Object:Sagitta Sequences
Master detail field to Accounts: Account
API Name: Account__c
Child Relationship Name: Sagitta_Sequences
I am trying to run a query from the account object and get the Sagitta Sequences Name field. This works to return the records that have the child record associated.
Select id, name FROM Account WHERE id in (Select account__c From Sagitta_Sequence__c)I am trying to include the Sagitta_Sequence__c.Name from the child object but I keep getting an error. I was trying this:
Select id, name, Sagitta_Sequence__c.Name FROM Account WHERE id in (Select account__c From Sagitta_Sequence__c)
Thanks for the help.
- Terminusbot
- June 27, 2016
- Like
- 0