-
ChatterFeed
-
1Best Answers
-
6Likes Received
-
0Likes Given
-
36Questions
-
26Replies
Auto number : Apex class issue
But having standard autonumber will create new number for each child record created??
my requirement is to write logic for below condition :
==================
Parent : opportunity 1
Child records :
Pol - 1000 - v0
Pol - 1000 - v1 (if you observe the numbring 1000 is common for both child under opportunity 1)
===================
Parent : opportunity 2
Child records :
Pol - 1001 - v0
Pol - 1001 - v1 (if you observe the numbring 1001 is common for both child under opportunity 2)
==================
Parent : opportunity 3
Child records :
Pol - 1002 - v0
Pol - 1002 - v1 (if you observe the numbring 1002 is common for both child under opportunity 3)
- Rst123
- February 07, 2017
- Like
- 0
Auto number : i have a requirement where i need to have a auto number generated for child record
Parent - opportunity
Child - Policy
============
i have a requirement where i need to have a auto number generated for child record(policy) , but child records for 1 parent(opportunity) should be like Pol - 1000 - v0
Pol - 1000 - v1
2nd opportunity child record format :
Pol - 1001 - v0
Pol - 1001 - v2
3rd opportunity child record format :
Pol - 1002 - v0
Pol - 1002 - v1
i.e if parent record is same then child record will have same number with different version, increment in number will be based on (set of policy records) realted to parent records , so policy records having same parent will have same number.
- Rst123
- February 07, 2017
- Like
- 0
- Rst123
- August 22, 2014
- Like
- 0
- Rst123
- August 22, 2014
- Like
- 0
- Rst123
- August 22, 2014
- Like
- 0
Error : Constructor not Defined : Btach class
1> we need to query Policy_Type__c from which we will query all records of object(whichever is defined like account,contact etc) in Entity_Name__c
2> Condition__c is a text field where we define the condition on which SOQL will run .
3>After we get all records of object from Entity_Name__c we need to update these records in another object Audit_Trail__c
I'm getting Error : Constructor not Defined : Btach class when i'm trying to execute it in Developer console
Batch Class :-
global class POLICY implements Database.Batchable<sObject>, Database.Stateful{
Policy_Store__c myVariable = new Policy_Store__c();
String objectname = myVariable.Entity_Name__c;
String Condition = myVariable.Condition__c;
String query1;
String query2;
//Constructor
global POLICY(String query2){
query1 = 'Select Id, Name From '+objectname+' Limit 10000';
List<sObject> L = database.query(query1);
query2 = 'Select Id, Name,Policy_Type__c,Entity_Name__c,('+query1+') From Policy_Store__c where Policy_Type__c = "SOQL" and '+String.valueOf(Condition)+'';
List<sObject> L2 = database.query(query2);
}
// Start Method
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query2);
}
// Execute Mehod
global void execute(
Database.BatchableContext BC,
List<Policy_Store__c> scope){
//for(sObject s : scope){
//Summary = s.get('Policy_Store__c.Object_Name__c');
//}
Audit_Trail__c[] AudT = new List<Audit_Trail__c>();
for (Audit_Trail__c Au : AudT) {
Au.Entity_Name__c = myVariable.Entity_Name__c;
AudT.add(Au);
}
if(AudT.size()>0){
insert AudT;
}
}
global void finish(Database.BatchableContext BC){
}
}
- Rst123
- April 04, 2014
- Like
- 0
Data Retention/deletion based on rules in salesforce
Does anyone has any idea...how to acheive and setup rules(Policies) in salesforce based on which data retention/deletion can be done.
i need Detailed design for rule runner if someone can help me on this
or
Any code architecture.
Rule Runner
The Rule Runner would be a Batch Job which would be scheduled to run on a daily/weekly basis. The Rule Runner would fetch the Retention Rules for each Object and run them against the SFDC database to get the list of Objects that meet the requirement. References to the matched Objects would be added to the Audit table if it does not already exist. The framework would create instances of one of the Policy classes, and execute them to get the required results.
- Rst123
- March 12, 2014
- Like
- 1
Need help on Code coverage issue...
https://docs.google.com/document/d/1i3OjMQ1sPvaV0TKaKIG0O8dfHb4ILTAPie_86F66KxM/edit?usp=sharing
I have written a test class for a Apex class but its not covering and showing only 5% coverage...
Can you help me in getting code coverage :-
Test Class :-
I have written a test class for a Apex class but its not covering and showing only 5% coverage...
Can you help me in getting code coverage :-
I have highlighted the link of my CLASS below
@isTest
private class TestABC {
static testMethod void specialReplaceAmpersandTest() {
String testString = 'test&replacement';
String resultString = 'test%26replacement';
System.assertEquals(Utility.specialReplaceAmpersand(testString),resultString);
}
static testMethod void urlEncodeTest()
{
String testString = 'test&url%encode%test';
String resultString = 'test%26url%25encode%25test';
System.assertEquals(Utility.urlEncode(testString),resultString);
}
static testMethod void differentiateListsTest()
{
List<String> masterList = new List<String>();
masterList.add('Element1');
masterList.add('Element2');
masterList.add('Element3');
List<String> childList = new List<String>();
childList.add('Element2');
List<String> resultList = new List<String>();
resultList.add('Element1');
resultList.add('Element3');
System.assertEquals(Utility.differentiateLists(masterList,childList),resultList);
}
static testMethod void substractSetTest()
{
Set<String> set1 = new Set<String>();
set1.add('Element1');
set1.add('Element2');
set1.add('Element3');
Set<String> set2 = new Set<String>();
set2.add('Element2');
Set<String> resultSet = new Set<String>();
resultSet.add('Element1');
resultSet.add('Element3');
System.assertEquals(Utility.SubstractSet(set1,set2), resultSet);
}
Static testMethod void checkForNullTest()
{
String str1 = 'testStr1';
String str2 = 'testStr2';
String str3;
Decimal decVal1 = 10.0;
Decimal decVal2 = 11.0;
Decimal decVal3;
Integer intVal1 = 10;
Integer intVal2 = 11;
Integer intVal3;
Boolean bool1 = true;
Boolean bool2 = false;
String str4 = 'T' ;
Date dt1 = system.today();
Date dt2 = system.today() + 1;
Date dt3;
DateTime datTime1 = DateTime.now();
DateTime datTime2 = DateTime.now() + 1;
DateTime datTime3;
system.assertEquals(Utility.checkForNull(str1,str2),str2);
system.assertEquals(Utility.checkForNull(str1,str3),str1);
system.assertEquals(Utility.checkForNull(decVal1,decVal2),decVal2);
system.assertEquals(Utility.checkForNull(decVal1,decVal3),decVal1);
system.assertEquals(Utility.checkForNull(intVal1,intVal2),intVal2);
system.assertEquals(Utility.checkForNull(intVal1,intVal3),intVal1);
system.assertEquals(Utility.checkForNull(bool1,bool2),bool2);
system.assertEquals(Utility.checkForNull(bool1,str4),bool1);
system.assertEquals(Utility.checkForNull(dt1,dt2),dt2);
system.assertEquals(Utility.checkForNull(dt1,dt3),dt1);
system.assertEquals(Utility.checkForNull(datTime1,datTime2),datTime2);
system.assertEquals(Utility.checkForNull(datTime1,datTime3),datTime1);
}
static testMethod void getPhoneEscapedTest()
{
String FullNumber = '203-000-007x2345';
String phoneNumber = '203000007';
String extension = '2345';
System.assertEquals(Utility.getPhoneEscaped(FullNumber,true),phoneNumber);
System.assertEquals(Utility.getPhoneEscaped(FullNumber,false),extension);
}
static testMethod void testEncrypt()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g%3D%3D';
System.assertEquals(Utility.EncryptId(Value),Test);
}
static testMethod void testEncryptIdB64()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g==';
System.assertEquals(Utility.EncryptIdB64(Value),Test);
}
static testMethod void testsaveMultipleLogsToDataStore()
{
integer TEST_SIZE = 5 ;
String [] idList = new String[0] ;
String [] strList = new String[0] ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account',Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail');
aList.add(testAccount) ;
}
insert aList;
for (Account a:aList)
idList.add(a.Id) ;
for (integer i=0 ;i < TEST_SIZE ;i++){
String str = '' ;
for (integer k=0 ; k < 700;k++)
str+='AAAAAAAAAAAA ' ;
System.debug('--- ' + str.length());
strList.add(str) ;
}
Test.startTest() ;
System.debug('ID List size : ' + idList.size() + ' StringList size: ' + strList.size());
Utility.saveMultipleLogsToDataStore(idList, 'Test', strList) ;
Integer count = [select count() from Data_Store__c where Parent_Object__c = 'Test'] ;
System.assertEquals(TEST_SIZE*2, count) ; // String is going to be split into 2
Test.stopTest();
}
static testMethod void testcheckLimits(){
integer TEST_SIZE = 1 ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account'+i,Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail'+i);
aList.add(testAccount) ;
}
insert aList;
String debugX = '******* Test log' ;
debugX = Utility.checkLimits(debugX) ;
System.assertEquals(debugX.indexof('RESOURCE USAGE')>0, true) ;
}
}
APEX Class :-
https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FtTIAU#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=ALLQUESTIONS&id=906F00000009FuHIAU (https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FtTIAU#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=ALLQUESTIONS&id=906F00000009FuHIAU (https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FtTIAU#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=ALLQUESTIONS&id=906F00000009FuHIAU))
- Rst123
- February 19, 2014
- Like
- 1
Code coverage Issue :-
https://docs.google.com/document/d/1i3OjMQ1sPvaV0TKaKIG0O8dfHb4ILTAPie_86F66KxM/edit?usp=sharing
I have written a test class for a Apex class but its not covering and showing only 5% coverage...
Can you help me in getting code coverage :-
Test Class :-
I have written a test class for a Apex class but its not covering and showing only 5% coverage...
Can you help me in getting code coverage :-
I have highlighted the link of my CLASS below
@isTest
private class TestABC {
static testMethod void specialReplaceAmpersandTest() {
String testString = 'test&replacement';
String resultString = 'test%26replacement';
System.assertEquals(Utility.specialReplaceAmpersand(testString),resultString);
}
static testMethod void urlEncodeTest()
{
String testString = 'test&url%encode%test';
String resultString = 'test%26url%25encode%25test';
System.assertEquals(Utility.urlEncode(testString),resultString);
}
static testMethod void differentiateListsTest()
{
List<String> masterList = new List<String>();
masterList.add('Element1');
masterList.add('Element2');
masterList.add('Element3');
List<String> childList = new List<String>();
childList.add('Element2');
List<String> resultList = new List<String>();
resultList.add('Element1');
resultList.add('Element3');
System.assertEquals(Utility.differentiateLists(masterList,childList),resultList);
}
static testMethod void substractSetTest()
{
Set<String> set1 = new Set<String>();
set1.add('Element1');
set1.add('Element2');
set1.add('Element3');
Set<String> set2 = new Set<String>();
set2.add('Element2');
Set<String> resultSet = new Set<String>();
resultSet.add('Element1');
resultSet.add('Element3');
System.assertEquals(Utility.SubstractSet(set1,set2), resultSet);
}
Static testMethod void checkForNullTest()
{
String str1 = 'testStr1';
String str2 = 'testStr2';
String str3;
Decimal decVal1 = 10.0;
Decimal decVal2 = 11.0;
Decimal decVal3;
Integer intVal1 = 10;
Integer intVal2 = 11;
Integer intVal3;
Boolean bool1 = true;
Boolean bool2 = false;
String str4 = 'T' ;
Date dt1 = system.today();
Date dt2 = system.today() + 1;
Date dt3;
DateTime datTime1 = DateTime.now();
DateTime datTime2 = DateTime.now() + 1;
DateTime datTime3;
system.assertEquals(Utility.checkForNull(str1,str2),str2);
system.assertEquals(Utility.checkForNull(str1,str3),str1);
system.assertEquals(Utility.checkForNull(decVal1,decVal2),decVal2);
system.assertEquals(Utility.checkForNull(decVal1,decVal3),decVal1);
system.assertEquals(Utility.checkForNull(intVal1,intVal2),intVal2);
system.assertEquals(Utility.checkForNull(intVal1,intVal3),intVal1);
system.assertEquals(Utility.checkForNull(bool1,bool2),bool2);
system.assertEquals(Utility.checkForNull(bool1,str4),bool1);
system.assertEquals(Utility.checkForNull(dt1,dt2),dt2);
system.assertEquals(Utility.checkForNull(dt1,dt3),dt1);
system.assertEquals(Utility.checkForNull(datTime1,datTime2),datTime2);
system.assertEquals(Utility.checkForNull(datTime1,datTime3),datTime1);
}
static testMethod void getPhoneEscapedTest()
{
String FullNumber = '203-000-007x2345';
String phoneNumber = '203000007';
String extension = '2345';
System.assertEquals(Utility.getPhoneEscaped(FullNumber,true),phoneNumber);
System.assertEquals(Utility.getPhoneEscaped(FullNumber,false),extension);
}
static testMethod void testEncrypt()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g%3D%3D';
System.assertEquals(Utility.EncryptId(Value),Test);
}
static testMethod void testEncryptIdB64()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g==';
System.assertEquals(Utility.EncryptIdB64(Value),Test);
}
static testMethod void testsaveMultipleLogsToDataStore()
{
integer TEST_SIZE = 5 ;
String [] idList = new String[0] ;
String [] strList = new String[0] ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account',Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail');
aList.add(testAccount) ;
}
insert aList;
for (Account a:aList)
idList.add(a.Id) ;
for (integer i=0 ;i < TEST_SIZE ;i++){
String str = '' ;
for (integer k=0 ; k < 700;k++)
str+='AAAAAAAAAAAA ' ;
System.debug('--- ' + str.length());
strList.add(str) ;
}
Test.startTest() ;
System.debug('ID List size : ' + idList.size() + ' StringList size: ' + strList.size());
Utility.saveMultipleLogsToDataStore(idList, 'Test', strList) ;
Integer count = [select count() from Data_Store__c where Parent_Object__c = 'Test'] ;
System.assertEquals(TEST_SIZE*2, count) ; // String is going to be split into 2
Test.stopTest();
}
static testMethod void testcheckLimits(){
integer TEST_SIZE = 1 ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account'+i,Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail'+i);
aList.add(testAccount) ;
}
insert aList;
String debugX = '******* Test log' ;
debugX = Utility.checkLimits(debugX) ;
System.assertEquals(debugX.indexof('RESOURCE USAGE')>0, true) ;
}
}
APEX Class :-
https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FtTIAU#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=ALLQUESTIONS&id=906F00000009FuHIAU (https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FtTIAU#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=ALLQUESTIONS&id=906F00000009FuHIAU)
- Rst123
- February 19, 2014
- Like
- 1
Help in incresing test Coverage
link :- https://docs.google.com/document/d/1i3OjMQ1sPvaV0TKaKIG0O8dfHb4ILTAPie_86F66KxM/edit?usp=sharing
Test Class :-
I have written a test class for a Apex class but its not covering and showing only 5% coverage...
Can you help me in getting code coverage :-
I have highlighted the link of my CLASS below
@isTest
private class TestABC {
static testMethod void specialReplaceAmpersandTest() {
String testString = 'test&replacement';
String resultString = 'test%26replacement';
System.assertEquals(Utility.specialReplaceAmpersand(testString),resultString);
}
static testMethod void urlEncodeTest()
{
String testString = 'test&url%encode%test';
String resultString = 'test%26url%25encode%25test';
System.assertEquals(Utility.urlEncode(testString),resultString);
}
static testMethod void differentiateListsTest()
{
List<String> masterList = new List<String>();
masterList.add('Element1');
masterList.add('Element2');
masterList.add('Element3');
List<String> childList = new List<String>();
childList.add('Element2');
List<String> resultList = new List<String>();
resultList.add('Element1');
resultList.add('Element3');
System.assertEquals(Utility.differentiateLists(masterList,childList),resultList);
}
static testMethod void substractSetTest()
{
Set<String> set1 = new Set<String>();
set1.add('Element1');
set1.add('Element2');
set1.add('Element3');
Set<String> set2 = new Set<String>();
set2.add('Element2');
Set<String> resultSet = new Set<String>();
resultSet.add('Element1');
resultSet.add('Element3');
System.assertEquals(Utility.SubstractSet(set1,set2), resultSet);
}
Static testMethod void checkForNullTest()
{
String str1 = 'testStr1';
String str2 = 'testStr2';
String str3;
Decimal decVal1 = 10.0;
Decimal decVal2 = 11.0;
Decimal decVal3;
Integer intVal1 = 10;
Integer intVal2 = 11;
Integer intVal3;
Boolean bool1 = true;
Boolean bool2 = false;
String str4 = 'T' ;
Date dt1 = system.today();
Date dt2 = system.today() + 1;
Date dt3;
DateTime datTime1 = DateTime.now();
DateTime datTime2 = DateTime.now() + 1;
DateTime datTime3;
system.assertEquals(Utility.checkForNull(str1,str2),str2);
system.assertEquals(Utility.checkForNull(str1,str3),str1);
system.assertEquals(Utility.checkForNull(decVal1,decVal2),decVal2);
system.assertEquals(Utility.checkForNull(decVal1,decVal3),decVal1);
system.assertEquals(Utility.checkForNull(intVal1,intVal2),intVal2);
system.assertEquals(Utility.checkForNull(intVal1,intVal3),intVal1);
system.assertEquals(Utility.checkForNull(bool1,bool2),bool2);
system.assertEquals(Utility.checkForNull(bool1,str4),bool1);
system.assertEquals(Utility.checkForNull(dt1,dt2),dt2);
system.assertEquals(Utility.checkForNull(dt1,dt3),dt1);
system.assertEquals(Utility.checkForNull(datTime1,datTime2),datTime2);
system.assertEquals(Utility.checkForNull(datTime1,datTime3),datTime1);
}
static testMethod void getPhoneEscapedTest()
{
String FullNumber = '203-000-007x2345';
String phoneNumber = '203000007';
String extension = '2345';
System.assertEquals(Utility.getPhoneEscaped(FullNumber,true),phoneNumber);
System.assertEquals(Utility.getPhoneEscaped(FullNumber,false),extension);
}
static testMethod void testEncrypt()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g%3D%3D';
System.assertEquals(Utility.EncryptId(Value),Test);
}
static testMethod void testEncryptIdB64()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g==';
System.assertEquals(Utility.EncryptIdB64(Value),Test);
}
static testMethod void testsaveMultipleLogsToDataStore()
{
integer TEST_SIZE = 5 ;
String [] idList = new String[0] ;
String [] strList = new String[0] ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account',Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail');
aList.add(testAccount) ;
}
insert aList;
for (Account a:aList)
idList.add(a.Id) ;
for (integer i=0 ;i < TEST_SIZE ;i++){
String str = '' ;
for (integer k=0 ; k < 700;k++)
str+='AAAAAAAAAAAA ' ;
System.debug('--- ' + str.length());
strList.add(str) ;
}
Test.startTest() ;
System.debug('ID List size : ' + idList.size() + ' StringList size: ' + strList.size());
Utility.saveMultipleLogsToDataStore(idList, 'Test', strList) ;
Integer count = [select count() from Data_Store__c where Parent_Object__c = 'Test'] ;
System.assertEquals(TEST_SIZE*2, count) ; // String is going to be split into 2
Test.stopTest();
}
static testMethod void testcheckLimits(){
integer TEST_SIZE = 1 ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account'+i,Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail'+i);
aList.add(testAccount) ;
}
insert aList;
String debugX = '******* Test log' ;
debugX = Utility.checkLimits(debugX) ;
System.assertEquals(debugX.indexof('RESOURCE USAGE')>0, true) ;
}
}
- Rst123
- February 18, 2014
- Like
- 1
Test class Coverage issue ...
Can you help me in getting code coverage :-
I have highlighted the link of my CLASS below
@isTest
private class TestABC {
static testMethod void specialReplaceAmpersandTest() {
String testString = 'test&replacement';
String resultString = 'test%26replacement';
System.assertEquals(Utility.specialReplaceAmpersand(testString),resultString);
}
static testMethod void urlEncodeTest()
{
String testString = 'test&url%encode%test';
String resultString = 'test%26url%25encode%25test';
System.assertEquals(Utility.urlEncode(testString),resultString);
}
static testMethod void differentiateListsTest()
{
List<String> masterList = new List<String>();
masterList.add('Element1');
masterList.add('Element2');
masterList.add('Element3');
List<String> childList = new List<String>();
childList.add('Element2');
List<String> resultList = new List<String>();
resultList.add('Element1');
resultList.add('Element3');
System.assertEquals(Utility.differentiateLists(masterList,childList),resultList);
}
static testMethod void substractSetTest()
{
Set<String> set1 = new Set<String>();
set1.add('Element1');
set1.add('Element2');
set1.add('Element3');
Set<String> set2 = new Set<String>();
set2.add('Element2');
Set<String> resultSet = new Set<String>();
resultSet.add('Element1');
resultSet.add('Element3');
System.assertEquals(Utility.SubstractSet(set1,set2), resultSet);
}
Static testMethod void checkForNullTest()
{
String str1 = 'testStr1';
String str2 = 'testStr2';
String str3;
Decimal decVal1 = 10.0;
Decimal decVal2 = 11.0;
Decimal decVal3;
Integer intVal1 = 10;
Integer intVal2 = 11;
Integer intVal3;
Boolean bool1 = true;
Boolean bool2 = false;
String str4 = 'T' ;
Date dt1 = system.today();
Date dt2 = system.today() + 1;
Date dt3;
DateTime datTime1 = DateTime.now();
DateTime datTime2 = DateTime.now() + 1;
DateTime datTime3;
system.assertEquals(Utility.checkForNull(str1,str2),str2);
system.assertEquals(Utility.checkForNull(str1,str3),str1);
system.assertEquals(Utility.checkForNull(decVal1,decVal2),decVal2);
system.assertEquals(Utility.checkForNull(decVal1,decVal3),decVal1);
system.assertEquals(Utility.checkForNull(intVal1,intVal2),intVal2);
system.assertEquals(Utility.checkForNull(intVal1,intVal3),intVal1);
system.assertEquals(Utility.checkForNull(bool1,bool2),bool2);
system.assertEquals(Utility.checkForNull(bool1,str4),bool1);
system.assertEquals(Utility.checkForNull(dt1,dt2),dt2);
system.assertEquals(Utility.checkForNull(dt1,dt3),dt1);
system.assertEquals(Utility.checkForNull(datTime1,datTime2),datTime2);
system.assertEquals(Utility.checkForNull(datTime1,datTime3),datTime1);
}
static testMethod void getPhoneEscapedTest()
{
String FullNumber = '203-000-007x2345';
String phoneNumber = '203000007';
String extension = '2345';
System.assertEquals(Utility.getPhoneEscaped(FullNumber,true),phoneNumber);
System.assertEquals(Utility.getPhoneEscaped(FullNumber,false),extension);
}
static testMethod void testEncrypt()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g%3D%3D';
System.assertEquals(Utility.EncryptId(Value),Test);
}
static testMethod void testEncryptIdB64()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g==';
System.assertEquals(Utility.EncryptIdB64(Value),Test);
}
static testMethod void testsaveMultipleLogsToDataStore()
{
integer TEST_SIZE = 5 ;
String [] idList = new String[0] ;
String [] strList = new String[0] ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account',Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail');
aList.add(testAccount) ;
}
insert aList;
for (Account a:aList)
idList.add(a.Id) ;
for (integer i=0 ;i < TEST_SIZE ;i++){
String str = '' ;
for (integer k=0 ; k < 700;k++)
str+='AAAAAAAAAAAA ' ;
System.debug('--- ' + str.length());
strList.add(str) ;
}
Test.startTest() ;
System.debug('ID List size : ' + idList.size() + ' StringList size: ' + strList.size());
Utility.saveMultipleLogsToDataStore(idList, 'Test', strList) ;
Integer count = [select count() from Data_Store__c where Parent_Object__c = 'Test'] ;
System.assertEquals(TEST_SIZE*2, count) ; // String is going to be split into 2
Test.stopTest();
}
static testMethod void testcheckLimits(){
integer TEST_SIZE = 1 ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account'+i,Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail'+i);
aList.add(testAccount) ;
}
insert aList;
String debugX = '******* Test log' ;
debugX = Utility.checkLimits(debugX) ;
System.assertEquals(debugX.indexof('RESOURCE USAGE')>0, true) ;
}
}
APEX CLASS :
https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FtTIAU#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=ALLQUESTIONS&id=906F00000009FuHIAU (https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FtTIAU#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=ALLQUESTIONS&id=906F00000009FuHIAU)
- Rst123
- February 18, 2014
- Like
- 0
Test class coverage Issue...
@isTest
private class TestABC {
static testMethod void specialReplaceAmpersandTest() {
String testString = 'test&replacement';
String resultString = 'test%26replacement';
System.assertEquals(Utility.specialReplaceAmpersand(testString),resultString);
}
static testMethod void urlEncodeTest()
{
String testString = 'test&url%encode%test';
String resultString = 'test%26url%25encode%25test';
System.assertEquals(Utility.urlEncode(testString),resultString);
}
static testMethod void differentiateListsTest()
{
List<String> masterList = new List<String>();
masterList.add('Element1');
masterList.add('Element2');
masterList.add('Element3');
List<String> childList = new List<String>();
childList.add('Element2');
List<String> resultList = new List<String>();
resultList.add('Element1');
resultList.add('Element3');
System.assertEquals(Utility.differentiateLists(masterList,childList),resultList);
}
static testMethod void substractSetTest()
{
Set<String> set1 = new Set<String>();
set1.add('Element1');
set1.add('Element2');
set1.add('Element3');
Set<String> set2 = new Set<String>();
set2.add('Element2');
Set<String> resultSet = new Set<String>();
resultSet.add('Element1');
resultSet.add('Element3');
System.assertEquals(Utility.SubstractSet(set1,set2), resultSet);
}
Static testMethod void checkForNullTest()
{
String str1 = 'testStr1';
String str2 = 'testStr2';
String str3;
Decimal decVal1 = 10.0;
Decimal decVal2 = 11.0;
Decimal decVal3;
Integer intVal1 = 10;
Integer intVal2 = 11;
Integer intVal3;
Boolean bool1 = true;
Boolean bool2 = false;
String str4 = 'T' ;
Date dt1 = system.today();
Date dt2 = system.today() + 1;
Date dt3;
DateTime datTime1 = DateTime.now();
DateTime datTime2 = DateTime.now() + 1;
DateTime datTime3;
system.assertEquals(Utility.checkForNull(str1,str2),str2);
system.assertEquals(Utility.checkForNull(str1,str3),str1);
system.assertEquals(Utility.checkForNull(decVal1,decVal2),decVal2);
system.assertEquals(Utility.checkForNull(decVal1,decVal3),decVal1);
system.assertEquals(Utility.checkForNull(intVal1,intVal2),intVal2);
system.assertEquals(Utility.checkForNull(intVal1,intVal3),intVal1);
system.assertEquals(Utility.checkForNull(bool1,bool2),bool2);
system.assertEquals(Utility.checkForNull(bool1,str4),bool1);
system.assertEquals(Utility.checkForNull(dt1,dt2),dt2);
system.assertEquals(Utility.checkForNull(dt1,dt3),dt1);
system.assertEquals(Utility.checkForNull(datTime1,datTime2),datTime2);
system.assertEquals(Utility.checkForNull(datTime1,datTime3),datTime1);
}
static testMethod void getPhoneEscapedTest()
{
String FullNumber = '203-000-007x2345';
String phoneNumber = '203000007';
String extension = '2345';
System.assertEquals(Utility.getPhoneEscaped(FullNumber,true),phoneNumber);
System.assertEquals(Utility.getPhoneEscaped(FullNumber,false),extension);
}
static testMethod void testEncrypt()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g%3D%3D';
System.assertEquals(Utility.EncryptId(Value),Test);
}
static testMethod void testEncryptIdB64()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g==';
System.assertEquals(Utility.EncryptIdB64(Value),Test);
}
static testMethod void testsaveMultipleLogsToDataStore()
{
integer TEST_SIZE = 5 ;
String [] idList = new String[0] ;
String [] strList = new String[0] ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account',Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail');
aList.add(testAccount) ;
}
insert aList;
for (Account a:aList)
idList.add(a.Id) ;
for (integer i=0 ;i < TEST_SIZE ;i++){
String str = '' ;
for (integer k=0 ; k < 700;k++)
str+='AAAAAAAAAAAA ' ;
System.debug('--- ' + str.length());
strList.add(str) ;
}
Test.startTest() ;
System.debug('ID List size : ' + idList.size() + ' StringList size: ' + strList.size());
Utility.saveMultipleLogsToDataStore(idList, 'Test', strList) ;
Integer count = [select count() from Data_Store__c where Parent_Object__c = 'Test'] ;
System.assertEquals(TEST_SIZE*2, count) ; // String is going to be split into 2
Test.stopTest();
}
static testMethod void testcheckLimits(){
integer TEST_SIZE = 1 ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account'+i,Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail'+i);
aList.add(testAccount) ;
}
insert aList;
String debugX = '******* Test log' ;
debugX = Utility.checkLimits(debugX) ;
System.assertEquals(debugX.indexof('RESOURCE USAGE')>0, true) ;
}
}
- Rst123
- February 18, 2014
- Like
- 0
FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [Account__c]
I'm getting the below error
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [Account__c]
I have highlighted the method below i'm getting the error :-
I have a master Look field Account__c on object :VVLOC__c
Criteria : -Account Record TypeequalsPartner Record Type
Code :-
@IsTest(SeeAllData=False)
private class TestCreditApprovalUtility {
static testmethod void testCalculateAppRemAmount()
{
Set<String> caOwnerId = new Set<String>();
User u;
Account a;
User thisUser = [ select Id,UserRole.Name,Profile.Name from User where Id = :UserInfo.getUserId() ];
//UserRole r = [select id,UserRole.Name,Profile.Name from User where id = :caOwnerId];
System.runAs ( thisUser ) {
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
u = new User(Alias = 'standt', Email='standarduser@testorg.com',userroleid = thisUser.UserRole.Id,
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US'
, ProfileId = p.Id ,TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testGE.com');
insert u;
}
Set<Id> AccountId = new Set<Id>();
Set<Id> ParentId = new Set<Id>();
Set<Id> OpIds = new Set<Id>();
Set<Id> CaIds = new Set<Id>();
List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();
//Opportunity[] opps=[Select Credit_approval__c from Opportunity where Id in :caopps.keyset()];
//Account account = [Select Id,Name,ParentId from Account where Id in :AccountId];
//Create test account
List<Account> acct = new List<Account>();
Account account = new Account();
account.recordtype=new recordtype(name='Customer Record Type');
account.Name = 'Test';
account.BillingStreet = '123 Some St.';
account.BillingCity = 'Somewhere';
account.BillingState = 'CT';
account.BillingPostalCode = '12345';
account.ParentId = account.Id;
System.runAs(u) {
insert account;
}
// Create a new Partner Account
Account partner = new Account();
partner.recordtype=new recordtype(name='Partner Record Type');
partner.Name = 'Test Partner';
partner.BillingStreet = '123 Some St.';
partner.BillingCity = 'Somewhere';
partner.BillingState = 'CT';
partner.BillingPostalCode = '12345';
insert partner;
// Create a test opportunity to associate with Credit Approvals and Quote
List<Opportunity> OpList= new List<Opportunity>();
Opportunity opportunity = new Opportunity();
opportunity.OwnerId = userinfo.getUserId();
opportunity.AccountId = account.Id;
opportunity.Name = 'Test';
opportunity.StageName = 'Lead';
opportunity.CloseDate = Date.today();
opportunity.Amount=1000;
OpList.add(opportunity);
insert OpList;
for(Opportunity o : OpList){
OpIds.add(o.Id);
}
//Changes made for Audit Cleanup :Increase test class coverage
//Creating test Quote
Quote__c quote= new Quote__c();
quote.Product__c='FMV';
quote.Opportunity__c=opportunity.id;
quote.Include_For_Risk__c=true;
insert quote;
//End of Changes made for Audit Cleanup :Increase test class coverage
//Create test takedowns to associate with opportunity
List<Takedown__c> takedowns= new List<Takedown__c>();
Takedown__c Tk1= new Takedown__c();
Tk1.Name= 'Test T1';
Tk1.Opportunity__c= opportunity.id;
Tk1.CurrencyIsoCode= 'USD';
Tk1.Total_Amount_Financed__c=1000.00;
takedowns.add(Tk1);
Takedown__c Tk2= new Takedown__c();
Tk2.Name= 'Test T2';
Tk2.Opportunity__c= opportunity.id;
Tk2.CurrencyIsoCode= 'USD';
Tk2.Total_Amount_Financed__c=700.00;
takedowns.add(Tk2);
insert takedowns;
Utility.isOwnerUpdate=true;
Utility.IsStageChange=true;
}
// =========Second test method================
static testmethod void testCreditApproval()
{
Set<Id> OpIds = new Set<Id>();
Set<Id> CaIds = new Set<Id>();
Account account = new Account();
Account partner = new Account();
Opportunity opportunity = new Opportunity();
List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();
//Create test Credit Approvals
Credit_Approval__c CA1=new Credit_Approval__c();
CA1.Partner__c=partner.id;
CA1.Account__c=account.id ;
CA1.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA1.Approved_Amount_With_Tolerance__c= 10000;
CA1.Approved_Amount__c= 10000;
CA1.Application_Type__c= 'Line Of Credit';
CA1.Submittal_Status__c= 'Decisioned';
CA1.Risk_Decision__c='Approved';
CA1.LOC_Adjustment_Amount__c= 200.00;
//CA1.Approval_Expiration_Date__c= myDate;
CAList.add(CA1);
Credit_Approval__c CA2=new Credit_Approval__c();
CA2.Partner__c=partner.id;
CA2.Account__c=account.id ;
CA2.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA2.Approved_Amount_With_Tolerance__c= 100.00;
CA2.Approved_Amount__c= 10000;
CA2.LOC_Adjustment_Amount__c= 200.00;
CA2.Application_Type__c= 'Line Of Credit';
CA2.Submittal_Status__c= 'Referred';
CA2.Risk_Decision__c='Approved';
//CA2.Credit_Line_ID__c= creditLine2.id;
//CA2.Approval_Expiration_Date__c= myDate;
CAList.add(CA2);
Credit_Approval__c CA3=new Credit_Approval__c();
CA3.Partner__c=partner.id;
CA3.Account__c=account.id ;
CA3.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA3.Approved_Amount_With_Tolerance__c= 100.00;
CA3.Approved_Amount__c= 10000;
CA3.LOC_Adjustment_Amount__c= 200.00;
CA3.Application_Type__c= 'Deal - Multiple Takedown';
CA3.Submittal_Status__c= 'Test';
CA3.Risk_Decision__c='Approved';
//CA3.Credit_Line_ID__c= creditLine2.id;
//CA3.Approval_Expiration_Date__c= myDate;
CA3.Opportunity__c=opportunity.id;
CAList.add(CA3);
Credit_Approval__c CA4=new Credit_Approval__c();
CA4.Partner__c=partner.id;
CA4.Account__c=account.id ;
CA4.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA4.Approved_Amount_With_Tolerance__c= 10000.00;
CA4.Approved_Amount__c= 10000;
CA4.LOC_Adjustment_Amount__c= 200.00;
CA4.Application_Type__c= 'Deal - Multiple Takedown';
CA4.Submittal_Status__c= 'Decisioned';
CA4.Risk_Decision__c='Approved';
//CA4.Credit_Line_ID__c= creditLine2.id;
//CA4.Approval_Expiration_Date__c= myDate;
CA4.Opportunity__c=opportunity.id;
CAList.add(CA4);
insert CAList;
for(Credit_Approval__c c : CAList){
CaIds.add(c.Id);
}
//Create test Credit Approvals to make them as child Credit Approvals
Credit_Approval__c creditLine1 =new Credit_Approval__c();
creditLine1.Account__c=account.id ;
creditLine1.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine1.Application_Type__c= 'Deal - Multiple Takedown';
creditLine1.Approved_Amount_With_Tolerance__c= 1000.00;
creditLine1.Approved_Amount__c= 200.00;
creditLine1.Submittal_Status__c= 'Decisioned';
creditLine1.Risk_Decision__c='Approved';
creditLine1.Credit_Line_ID__c= CA1.id;
CreditLineList.add(creditLine1);
Credit_Approval__c creditLine2 =new Credit_Approval__c();
creditLine2.Account__c=account.id ;
creditLine2.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine2.Application_Type__c= 'Deal - Multiple Takedown';
creditLine2.Approved_Amount_With_Tolerance__c= 100.00;
creditLine2.Approved_Amount__c= 200.00;
creditLine2.Submittal_Status__c= 'Referred';
creditLine2.Risk_Decision__c='Approved';
creditLine2.Credit_Line_ID__c= CA2.id;
creditLine2.LOC_Adjustment_Amount__c= 200.00;
CreditLineList.add(creditLine2);
Credit_Approval__c creditLine3 =new Credit_Approval__c();
creditLine3.Account__c=account.id ;
creditLine3.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine3.Application_Type__c= 'Deal - Multiple Takedown';
creditLine3.Approved_Amount_With_Tolerance__c= 100.00;
creditLine3.Approved_Amount__c= 200.00;
creditLine3.Submittal_Status__c= 'Referred';
creditLine3.Risk_Decision__c='Approved';
creditLine3.Credit_Line_ID__c= null;
creditLine3.LOC_Adjustment_Amount__c= 200.00;
CreditLineList.add(creditLine3);
insert CreditLineList;
Test.startTest();
//CA1.Approved_Amount_With_Tolerance__c= 20000;
//update CAList;
Map<Id,Decimal> UsedAmt= CreditApprovalUtility.GetUsedAmounts(CaIds);
List<Credit_Approval__c> ca = [Select Id,Amount_Approved_Remaining__c from Credit_Approval__c where Id in :CaIds];
Map<Id,decimal> RemAm= CreditApprovalUtility.CalculateAppRemAmount(null);
Map<Id,decimal> RemAmount= CreditApprovalUtility.CalculateAppRemAmount(CAList);
//system.assertEquals(9800.00,RemAmount.get(CA1.id));
Map<Id,decimal> RemAmountt= CreditApprovalUtility.CalculateAppRemAmount(CreditLineList);
//Changes made for Audit Cleanup :Increase test class coverage
Map<Id,double> PaymentStreamTerm= CreditApprovalUtility.GetPaymentStreamTerm(OpIds);
//system.assertEquals(0.0,PaymentStreamTerm.get(opportunity.id));
//End of Changes made for Audit Cleanup :Increase test class coverage
Test.stopTest();
}
static testmethod void testCreditApproval1()
{
Credit_Approval__c CA=new Credit_Approval__c();
set<id> recordtypeids=new set<id>();
recordtype rectyp = new recordtype();
Set<Id> OpIds = new Set<Id>();
Set<Id> CaIds = new Set<Id>();
Set<Id> AccountId = new Set<Id>();
Set<Id> ParentId = new Set<Id>();
Set<Id> OpId = new Set<Id>();
Set<Id> CAPartnerIds = new Set<Id>();
Account account = new Account();
List<Account> acct = new List<Account>();
//Account account = new Account();
account.recordtype=new recordtype(name='Customer Record Type');
account.Name = 'Test';
account.BillingStreet = '123 Some St.';
account.BillingCity = 'Somewhere';
account.BillingState = 'CT';
account.BillingPostalCode = '12345';
account.ParentId = account.Id;
insert account;
Account partner = new Account();
Opportunity opportunity = new Opportunity();
List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();
VVLOC__c vloc = new VVLOC__c();
vloc.Account__c = Account.ID;
vloc.Vendor_Loc_Status__c = 'INA';
vloc.Name = vloc.Id;
vloc.Vendor_Location__c ='Test';
account.ParentId = account.Id;
Insert vloc;
}
}
- Rst123
- February 18, 2014
- Like
- 0
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Account__c]: [Account__c]
I have highlighted the method below :-
@IsTest(SeeAllData=False)
private class TestCreditApprovalUtility {
static testmethod void testCalculateAppRemAmount()
{
Set<String> caOwnerId = new Set<String>();
User u;
Account a;
User thisUser = [ select Id,UserRole.Name,Profile.Name from User where Id = :UserInfo.getUserId() ];
//UserRole r = [select id,UserRole.Name,Profile.Name from User where id = :caOwnerId];
System.runAs ( thisUser ) {
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
u = new User(Alias = 'standt', Email='standarduser@testorg.com',userroleid = thisUser.UserRole.Id,
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US'
, ProfileId = p.Id ,TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testGE.com');
insert u;
}
Set<Id> AccountId = new Set<Id>();
Set<Id> ParentId = new Set<Id>();
Set<Id> OpIds = new Set<Id>();
Set<Id> CaIds = new Set<Id>();
List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();
//Opportunity[] opps=[Select Credit_approval__c from Opportunity where Id in :caopps.keyset()];
//Account account = [Select Id,Name,ParentId from Account where Id in :AccountId];
//Create test account
List<Account> acct = new List<Account>();
Account account = new Account();
account.recordtype=new recordtype(name='Customer Record Type');
account.Name = 'Test';
account.BillingStreet = '123 Some St.';
account.BillingCity = 'Somewhere';
account.BillingState = 'CT';
account.BillingPostalCode = '12345';
account.ParentId = account.Id;
System.runAs(u) {
insert account;
}
// Create a new Partner Account
Account partner = new Account();
partner.recordtype=new recordtype(name='Partner Record Type');
partner.Name = 'Test Partner';
partner.BillingStreet = '123 Some St.';
partner.BillingCity = 'Somewhere';
partner.BillingState = 'CT';
partner.BillingPostalCode = '12345';
insert partner;
// Create a test opportunity to associate with Credit Approvals and Quote
List<Opportunity> OpList= new List<Opportunity>();
Opportunity opportunity = new Opportunity();
opportunity.OwnerId = userinfo.getUserId();
opportunity.AccountId = account.Id;
opportunity.Name = 'Test';
opportunity.StageName = 'Lead';
opportunity.CloseDate = Date.today();
opportunity.Amount=1000;
OpList.add(opportunity);
insert OpList;
for(Opportunity o : OpList){
OpIds.add(o.Id);
}
//Changes made for Audit Cleanup :Increase test class coverage
//Creating test Quote
Quote__c quote= new Quote__c();
quote.Product__c='FMV';
quote.Opportunity__c=opportunity.id;
quote.Include_For_Risk__c=true;
insert quote;
//End of Changes made for Audit Cleanup :Increase test class coverage
//Create test takedowns to associate with opportunity
List<Takedown__c> takedowns= new List<Takedown__c>();
Takedown__c Tk1= new Takedown__c();
Tk1.Name= 'Test T1';
Tk1.Opportunity__c= opportunity.id;
Tk1.CurrencyIsoCode= 'USD';
Tk1.Total_Amount_Financed__c=1000.00;
takedowns.add(Tk1);
Takedown__c Tk2= new Takedown__c();
Tk2.Name= 'Test T2';
Tk2.Opportunity__c= opportunity.id;
Tk2.CurrencyIsoCode= 'USD';
Tk2.Total_Amount_Financed__c=700.00;
takedowns.add(Tk2);
insert takedowns;
Utility.isOwnerUpdate=true;
Utility.IsStageChange=true;
}
// =========Second test method================
static testmethod void testCreditApproval()
{
Set<Id> OpIds = new Set<Id>();
Set<Id> CaIds = new Set<Id>();
Account account = new Account();
Account partner = new Account();
Opportunity opportunity = new Opportunity();
List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();
//Create test Credit Approvals
Credit_Approval__c CA1=new Credit_Approval__c();
CA1.Partner__c=partner.id;
CA1.Account__c=account.id ;
CA1.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA1.Approved_Amount_With_Tolerance__c= 10000;
CA1.Approved_Amount__c= 10000;
CA1.Application_Type__c= 'Line Of Credit';
CA1.Submittal_Status__c= 'Decisioned';
CA1.Risk_Decision__c='Approved';
CA1.LOC_Adjustment_Amount__c= 200.00;
//CA1.Approval_Expiration_Date__c= myDate;
CAList.add(CA1);
Credit_Approval__c CA2=new Credit_Approval__c();
CA2.Partner__c=partner.id;
CA2.Account__c=account.id ;
CA2.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA2.Approved_Amount_With_Tolerance__c= 100.00;
CA2.Approved_Amount__c= 10000;
CA2.LOC_Adjustment_Amount__c= 200.00;
CA2.Application_Type__c= 'Line Of Credit';
CA2.Submittal_Status__c= 'Referred';
CA2.Risk_Decision__c='Approved';
//CA2.Credit_Line_ID__c= creditLine2.id;
//CA2.Approval_Expiration_Date__c= myDate;
CAList.add(CA2);
Credit_Approval__c CA3=new Credit_Approval__c();
CA3.Partner__c=partner.id;
CA3.Account__c=account.id ;
CA3.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA3.Approved_Amount_With_Tolerance__c= 100.00;
CA3.Approved_Amount__c= 10000;
CA3.LOC_Adjustment_Amount__c= 200.00;
CA3.Application_Type__c= 'Deal - Multiple Takedown';
CA3.Submittal_Status__c= 'Test';
CA3.Risk_Decision__c='Approved';
//CA3.Credit_Line_ID__c= creditLine2.id;
//CA3.Approval_Expiration_Date__c= myDate;
CA3.Opportunity__c=opportunity.id;
CAList.add(CA3);
Credit_Approval__c CA4=new Credit_Approval__c();
CA4.Partner__c=partner.id;
CA4.Account__c=account.id ;
CA4.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA4.Approved_Amount_With_Tolerance__c= 10000.00;
CA4.Approved_Amount__c= 10000;
CA4.LOC_Adjustment_Amount__c= 200.00;
CA4.Application_Type__c= 'Deal - Multiple Takedown';
CA4.Submittal_Status__c= 'Decisioned';
CA4.Risk_Decision__c='Approved';
//CA4.Credit_Line_ID__c= creditLine2.id;
//CA4.Approval_Expiration_Date__c= myDate;
CA4.Opportunity__c=opportunity.id;
CAList.add(CA4);
insert CAList;
for(Credit_Approval__c c : CAList){
CaIds.add(c.Id);
}
//Create test Credit Approvals to make them as child Credit Approvals
Credit_Approval__c creditLine1 =new Credit_Approval__c();
creditLine1.Account__c=account.id ;
creditLine1.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine1.Application_Type__c= 'Deal - Multiple Takedown';
creditLine1.Approved_Amount_With_Tolerance__c= 1000.00;
creditLine1.Approved_Amount__c= 200.00;
creditLine1.Submittal_Status__c= 'Decisioned';
creditLine1.Risk_Decision__c='Approved';
creditLine1.Credit_Line_ID__c= CA1.id;
CreditLineList.add(creditLine1);
Credit_Approval__c creditLine2 =new Credit_Approval__c();
creditLine2.Account__c=account.id ;
creditLine2.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine2.Application_Type__c= 'Deal - Multiple Takedown';
creditLine2.Approved_Amount_With_Tolerance__c= 100.00;
creditLine2.Approved_Amount__c= 200.00;
creditLine2.Submittal_Status__c= 'Referred';
creditLine2.Risk_Decision__c='Approved';
creditLine2.Credit_Line_ID__c= CA2.id;
creditLine2.LOC_Adjustment_Amount__c= 200.00;
CreditLineList.add(creditLine2);
Credit_Approval__c creditLine3 =new Credit_Approval__c();
creditLine3.Account__c=account.id ;
creditLine3.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine3.Application_Type__c= 'Deal - Multiple Takedown';
creditLine3.Approved_Amount_With_Tolerance__c= 100.00;
creditLine3.Approved_Amount__c= 200.00;
creditLine3.Submittal_Status__c= 'Referred';
creditLine3.Risk_Decision__c='Approved';
creditLine3.Credit_Line_ID__c= null;
creditLine3.LOC_Adjustment_Amount__c= 200.00;
CreditLineList.add(creditLine3);
insert CreditLineList;
Test.startTest();
//CA1.Approved_Amount_With_Tolerance__c= 20000;
//update CAList;
Map<Id,Decimal> UsedAmt= CreditApprovalUtility.GetUsedAmounts(CaIds);
List<Credit_Approval__c> ca = [Select Id,Amount_Approved_Remaining__c from Credit_Approval__c where Id in :CaIds];
Map<Id,decimal> RemAm= CreditApprovalUtility.CalculateAppRemAmount(null);
Map<Id,decimal> RemAmount= CreditApprovalUtility.CalculateAppRemAmount(CAList);
//system.assertEquals(9800.00,RemAmount.get(CA1.id));
Map<Id,decimal> RemAmountt= CreditApprovalUtility.CalculateAppRemAmount(CreditLineList);
//Changes made for Audit Cleanup :Increase test class coverage
Map<Id,double> PaymentStreamTerm= CreditApprovalUtility.GetPaymentStreamTerm(OpIds);
//system.assertEquals(0.0,PaymentStreamTerm.get(opportunity.id));
//End of Changes made for Audit Cleanup :Increase test class coverage
Test.stopTest();
}
static testmethod void testCreditApproval1()
{
Credit_Approval__c CA=new Credit_Approval__c();
set<id> recordtypeids=new set<id>();
recordtype rectyp = new recordtype();
Set<Id> OpIds = new Set<Id>();
Set<Id> CaIds = new Set<Id>();
Set<Id> AccountId = new Set<Id>();
Set<Id> ParentId = new Set<Id>();
Set<Id> OpId = new Set<Id>();
Set<Id> CAPartnerIds = new Set<Id>();
Account account = new Account();
Account partner = new Account();
Opportunity opportunity = new Opportunity();
List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();
VVLOC__c vloc = new VVLOC__c();
vloc.Account__c = account.Name;
vloc.Vendor_Loc_Status__c = 'INA';
vloc.Name = vloc.Id;
vloc.Vendor_Location__c ='Test';
account.ParentId = account.Id;
Insert vloc;
}
}
- Rst123
- February 17, 2014
- Like
- 0
Avoid Too many SOQL queries: 101 in test class?
@IsTest
private class TestCreditApprovalUtility {
static testmethod void testCalculateAppRemAmount()
{
//Create test account
Account account = new Account();
account.recordtype=new recordtype(name='Customer Record Type');
account.Name = 'Test';
account.BillingStreet = '123 Some St.';
account.BillingCity = 'Somewhere';
account.BillingState = 'CT';
account.BillingPostalCode = '12345';
insert account;
// Create a new Partner Account
Account partner = new Account();
partner.recordtype=new recordtype(name='Partner Record Type');
partner.Name = 'Test Partner';
partner.BillingStreet = '123 Some St.';
partner.BillingCity = 'Somewhere';
partner.BillingState = 'CT';
partner.BillingPostalCode = '12345';
insert partner;
// Create a test opportunity to associate with Credit Approvals and Quote
List<Opportunity> OpList= new List<Opportunity>();
Opportunity opportunity = new Opportunity();
opportunity.OwnerId = userinfo.getUserId();
opportunity.AccountId = account.Id;
opportunity.Name = 'Test';
opportunity.StageName = 'Lead';
opportunity.CloseDate = Date.today();
opportunity.Amount=1000;
OpList.add(opportunity);
insert OpList;
Set<Id> OpIds = new Set<Id>();
for(Opportunity o : OpList){
OpIds.add(o.Id);
}
//Changes made for Audit Cleanup :Increase test class coverage
//Creating test Quote
Quote__c quote= new Quote__c();
quote.Product__c='FMV';
quote.Opportunity__c=opportunity.id;
quote.Include_For_Risk__c=true;
insert quote;
//End of Changes made for Audit Cleanup :Increase test class coverage
//Create test takedowns to associate with opportunity
List<Takedown__c> takedowns= new List<Takedown__c>();
Takedown__c Tk1= new Takedown__c();
Tk1.Name= 'Test T1';
Tk1.Opportunity__c= opportunity.id;
Tk1.CurrencyIsoCode= 'USD';
Tk1.Total_Amount_Financed__c=1000.00;
takedowns.add(Tk1);
Takedown__c Tk2= new Takedown__c();
Tk2.Name= 'Test T2';
Tk2.Opportunity__c= opportunity.id;
Tk2.CurrencyIsoCode= 'USD';
Tk2.Total_Amount_Financed__c=700.00;
takedowns.add(Tk2);
insert takedowns;
Utility.isOwnerUpdate=true;
Utility.IsStageChange=true;
//Create test Credit Approvals
List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
Credit_Approval__c CA1=new Credit_Approval__c();
CA1.Partner__c=partner.id;
CA1.Account__c=account.id ;
CA1.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA1.Approved_Amount_With_Tolerance__c= 10000;
CA1.Approved_Amount__c= 10000;
CA1.Application_Type__c= 'Line Of Credit';
CA1.Submittal_Status__c= 'Decisioned';
CA1.Risk_Decision__c='Approved';
CA1.LOC_Adjustment_Amount__c= 200.00;
//CA1.Approval_Expiration_Date__c= myDate;
CAList.add(CA1);
Credit_Approval__c CA2=new Credit_Approval__c();
CA2.Partner__c=partner.id;
CA2.Account__c=account.id ;
CA2.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA2.Approved_Amount_With_Tolerance__c= 100.00;
CA2.Approved_Amount__c= 10000;
//CA2.LOC_Adjustment_Amount__c= 200.00;
CA2.Application_Type__c= 'Line Of Credit';
CA2.Submittal_Status__c= 'Referred';
CA2.Risk_Decision__c='Approved';
//CA2.Credit_Line_ID__c= creditLine2.id;
//CA2.Approval_Expiration_Date__c= myDate;
CAList.add(CA2);
Credit_Approval__c CA3=new Credit_Approval__c();
CA3.Partner__c=partner.id;
CA3.Account__c=account.id ;
CA3.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA3.Approved_Amount_With_Tolerance__c= 100.00;
CA3.Approved_Amount__c= 10000;
CA3.LOC_Adjustment_Amount__c= 200.00;
CA3.Application_Type__c= 'Deal - Multiple Takedown';
CA3.Submittal_Status__c= 'Test';
CA3.Risk_Decision__c='Approved';
//CA3.Credit_Line_ID__c= creditLine2.id;
//CA3.Approval_Expiration_Date__c= myDate;
CA3.Opportunity__c=opportunity.id;
CAList.add(CA3);
Credit_Approval__c CA4=new Credit_Approval__c();
CA4.Partner__c=partner.id;
CA4.Account__c=account.id ;
CA4.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA4.Approved_Amount_With_Tolerance__c= 10000.00;
CA4.Approved_Amount__c= 10000;
CA4.LOC_Adjustment_Amount__c= 200.00;
CA4.Application_Type__c= 'Deal - Multiple Takedown';
CA4.Submittal_Status__c= 'Decisioned';
CA4.Risk_Decision__c='Approved';
//CA4.Credit_Line_ID__c= creditLine2.id;
//CA4.Approval_Expiration_Date__c= myDate;
CA4.Opportunity__c=opportunity.id;
CAList.add(CA4);
insert CAList;
Set<Id> CaIds = new Set<Id>();
for(Credit_Approval__c c : CAList){
CaIds.add(c.Id);
}
//Create test Credit Approvals to make them as child Credit Approvals
List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();
Credit_Approval__c creditLine1 =new Credit_Approval__c();
creditLine1.Account__c=account.id ;
creditLine1.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine1.Application_Type__c= 'Deal - Multiple Takedown';
creditLine1.Approved_Amount_With_Tolerance__c= 1000.00;
creditLine1.Approved_Amount__c= 200.00;
creditLine1.Submittal_Status__c= 'Decisioned';
creditLine1.Risk_Decision__c='Approved';
creditLine1.Credit_Line_ID__c= CA1.id;
CreditLineList.add(creditLine1);
Credit_Approval__c creditLine2 =new Credit_Approval__c();
creditLine2.Account__c=account.id ;
creditLine2.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine2.Application_Type__c= 'Deal - Multiple Takedown';
creditLine2.Approved_Amount_With_Tolerance__c= 100.00;
creditLine2.Approved_Amount__c= 200.00;
creditLine2.Submittal_Status__c= 'Referred';
creditLine2.Risk_Decision__c='Approved';
creditLine2.Credit_Line_ID__c= CA2.id;
creditLine2.LOC_Adjustment_Amount__c= 200.00;
CreditLineList.add(creditLine2);
Credit_Approval__c creditLine3 =new Credit_Approval__c();
creditLine3.Account__c=account.id ;
creditLine3.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine3.Application_Type__c= 'Deal - Multiple Takedown';
creditLine3.Approved_Amount_With_Tolerance__c= 100.00;
creditLine3.Approved_Amount__c= 200.00;
creditLine3.Submittal_Status__c= 'Referred';
creditLine3.Risk_Decision__c='Approved';
creditLine3.Credit_Line_ID__c= null;
creditLine3.LOC_Adjustment_Amount__c= 200.00;
CreditLineList.add(creditLine3);
insert CreditLineList;
Test.startTest();
//CA1.Approved_Amount_With_Tolerance__c= 20000;
//update CAList;
Map<Id,Decimal> UsedAmt= CreditApprovalUtility.GetUsedAmounts(CaIds);
List<Credit_Approval__c> ca = [Select Id,Amount_Approved_Remaining__c from Credit_Approval__c where Id in :CaIds];
Map<Id,decimal> RemAm= CreditApprovalUtility.CalculateAppRemAmount(null);
Map<Id,decimal> RemAmount= CreditApprovalUtility.CalculateAppRemAmount(CAList);
system.assertEquals(9800.00,RemAmount.get(CA1.id));
Map<Id,decimal> RemAmountt= CreditApprovalUtility.CalculateAppRemAmount(CreditLineList);
Map<Id,double> PaymentStreamTerm= CreditApprovalUtility.GetPaymentStreamTerm(OpIds);
system.assertEquals(0.0,PaymentStreamTerm.get(opportunity.id));
Test.stopTest();
}
}
Can you help in revoving this error
- Rst123
- February 14, 2014
- Like
- 0
Too many SOQL queries: 101
Highlighted the line i'm getting Too many SOQL queries: 101
if(trigger.isAfter){
if(caids.size()>0){
Set<Id> RelCreditApprovalId= new Set<Id>();
for(credit_approval__c ca:trigger.new){
if(caids.contains(ca.id)){
if(ca.Credit_Line_Id__c!=null){
system.debug('Credit Line Id (LOC): '+ca.Credit_Line_Id__c);
RelCreditApprovalId.add(ca.Credit_Line_Id__c);
}
}
}
List<Credit_Approval__c> RelCreditApprovalList= [select Id,Application_Type__c,Credit_Line_ID__c,Submittal_Status__c,Approved_Amount__c,Approved_Amount_With_Tolerance__c,LOC_Adjustment_Amount__c, Risk_Decision__c,Amount_Approved_Remaining__c,
Credit_Line_ID__r.Submittal_Status__c,Credit_Line_ID__r.Approved_Amount__c,Credit_Line_ID__r.Approved_Amount_With_Tolerance__c,Credit_Line_ID__r.Risk_Decision__c,Opportunity__c
from Credit_Approval__c where Id in :RelCreditApprovalId];
if(RelCreditApprovalList!=null && RelCreditApprovalList.size()>0){
try{
update RelCreditApprovalList;
}catch(DMLException e){
system.debug('/nDML Exception : '+e.getmessage());
}
}
}
}
- Rst123
- February 12, 2014
- Like
- 0
ERROR : Too many SOQL queries: 101
I'm getting error"Too many SOQL queries: 101" in line User user1 = [Select id, Profile.Name from User where Id= :UserInfo.getUserId() ]; of code below :-
I have highlighted the line below.
//Method added for Sending AFD to Siebel
if(trigger.isBefore && trigger.isUpdate){
Set<String> caOwnerId = new Set<String>();
Map<Id,User> ownerRole = new Map<Id,User>();
String s_profile = null; //Addition for Defect 13928
for(Credit_Approval__c ca:trigger.new){
caOwnerId.add(ca.OwnerId);
}
if(caOwnerId.size()>0){
ownerRole = new Map<Id,User>([select id,UserRole.Name from User where id = :caOwnerId]);
}
User user1 = [Select id, Profile.Name from User where Id= :UserInfo.getUserId() ];
s_profile = user1.Profile.Name;
for(Credit_Approval__c ca:trigger.new){
if(OwnerRole.get(ca.OwnerId)!=null && !'GE Integration User'.equalsIgnoreCase(s_profile)){
//if(OwnerRole.get(ca.OwnerId)!=null{
if(OwnerRole.get(ca.OwnerId).UserRole!=null && OwnerRole.get(ca.OwnerId).UserRole.Name.contains('HFS')&& OwnerRole.get(ca.OwnerId).UserRole.Name.contains('Zone')){// HFS Project Change - Add null check
ca.Flow_Struc__c = 'Flow';
}
if(OwnerRole.get(ca.OwnerId).UserRole!=null && OwnerRole.get(ca.OwnerId).UserRole.Name.contains('HFS')&& !OwnerRole.get(ca.OwnerId).UserRole.Name.contains('Zone')){// HFS Project Change - Add null check
ca.Flow_Struc__c = 'Structured';
}
}
}
}
}
Can you please help me out on this to acheive this.
- Rst123
- February 12, 2014
- Like
- 0
ERROR : Too many SOQL queries: 101
I'm getting error"Too many SOQL queries: 101" in line User user1 = [Select id, Profile.Name from User where Id= :UserInfo.getUserId() ]; of code below :-
I have highlighted the line below.
//Method added for Sending AFD to Siebel
if(trigger.isBefore && trigger.isUpdate){
Set<String> caOwnerId = new Set<String>();
Map<Id,User> ownerRole = new Map<Id,User>();
String s_profile = null; //Addition for Defect 13928
for(Credit_Approval__c ca:trigger.new){
caOwnerId.add(ca.OwnerId);
}
if(caOwnerId.size()>0){
ownerRole = new Map<Id,User>([select id,UserRole.Name from User where id = :caOwnerId]);
}
User user1 = [Select id, Profile.Name from User where Id= :UserInfo.getUserId() ];
s_profile = user1.Profile.Name;
for(Credit_Approval__c ca:trigger.new){
if(OwnerRole.get(ca.OwnerId)!=null && !'GE Integration User'.equalsIgnoreCase(s_profile)){
//if(OwnerRole.get(ca.OwnerId)!=null{
if(OwnerRole.get(ca.OwnerId).UserRole!=null && OwnerRole.get(ca.OwnerId).UserRole.Name.contains('HFS')&& OwnerRole.get(ca.OwnerId).UserRole.Name.contains('Zone')){// HFS Project Change - Add null check
ca.Flow_Struc__c = 'Flow';
}
if(OwnerRole.get(ca.OwnerId).UserRole!=null && OwnerRole.get(ca.OwnerId).UserRole.Name.contains('HFS')&& !OwnerRole.get(ca.OwnerId).UserRole.Name.contains('Zone')){// HFS Project Change - Add null check
ca.Flow_Struc__c = 'Structured';
}
}
}
}
}
- Rst123
- February 12, 2014
- Like
- 0
Help!! Format result in column
Hi,
I'm getting the result of total price of 2 opportunityline item in one row 25225.17 37837.75 format
where as i want the result in different row i.e total price of opportunityline item should come in front of respective lineitem
25225.17
37837.75
My code :-
public Class cOpportunity{
public Product2 opppr1 {get;set;}
public Opportunity opp {get;set;}
public Account acc1 {get;set;}
public Boolean selected{get;set;}
public String convertPrice {get;set;}
//public Decimal convertPrice {get;set;}
List<OpportunityLineItem> oppLineLst;
cOpportunity(Opportunity o){
convertPrice = ''; opp=o;
selected=false;
For(OpportunityLineItem ol :o.OpportunityLineItems){
Double conversionRate = [SELECT conversionrate,IsoCode FROM currencytype WHERE isocode =:ol.CurrencyIsoCode LIMIT 1].conversionRate;
// if(!convertPrice.contains(String.ValueOf(ol.TotalPrice * conversionRate)))
if(ol.CurrencyIsoCode != 'USD')
convertPrice += '\n\r'+ (ol.TotalPrice * (1/conversionRate)).setscale(2)+'\n\r';
else
convertPrice += '\n\r'+ (ol.TotalPrice).setscale(2) +'\n\r';
}
}
}
- Rst123
- November 21, 2013
- Like
- 0
SObject row was retrieved via SOQL without querying field:OpportunityLineItem.CurrencyIsoCode.
Hi,
I'm Getting below error :-
Error Message System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: OpportunityLineItem.CurrencyIsoCode
Class.SearchOpptyPageController.cOpportunity.<init>: line 530, column 1 Class.SearchOpptyPageController.getOpportunities: line 509, column 1 Class.SearchOpptyPageTest.opptyTest1: line 182, column 1
<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Controller Method due to which i'm getting error is :-
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
public List<cOpportunity> getOpportunities(){
opportunityList = new List<cOpportunity>();
for(Opportunity o : (List<Opportunity>)con.getRecords()) {
if(ModalityString != null || PortfolioString != null){
if(o.OpportunityLineItems.size() > 0){
opportunityList.add(new cOpportunity(o));
}
}
else{
opportunityList.add(new cOpportunity(o)); <<<<<<<<<<ERROR-1 Line 509>>>>>>>>>>>>>>>>>
}
}
return opportunityList;
}
public Class cOpportunity{
public Product2 opppr1 {get;set;}
public Opportunity opp {get;set;}
public Account acc1 {get;set;} public Boolean selected{get;set;}
public String convertPrice {get;set;}
//public Decimal convertPrice {get;set;}
List<OpportunityLineItem> oppLineLst;
cOpportunity(Opportunity o){
convertPrice = '';
opp=o;
selected=false;
oppLineLst = [Select convertCurrency(TotalPrice),id,CurrencyIsoCode From OpportunityLineItem where OpportunityId =: o.Id];
oppLineLst = new List<OpportunityLineItem>();
For(OpportunityLineItem ol :o.OpportunityLineItems){
Double conversionRate = [SELECT conversionrate,isocode FROM currencytype WHERE isocode =:ol.CurrencyIsoCode LIMIT 1].conversionRate; <<<<<<<<<<<<<<ERROR -2 Line 530>>>>>>>>>>>>> >>>>>>>>>>>>
// if(!convertPrice.contains(String.ValueOf(ol.TotalPrice * conversionRate)))
if(ol.CurrencyIsoCode != 'USD')
convertPrice += '\n\r'+ (ol.TotalPrice * (1/conversionRate)).setscale(2)+'\n\r';
else convertPrice += '\n\r'+ (ol.TotalPrice).setscale(2) +'\n\r';
}
}
}
- Rst123
- November 20, 2013
- Like
- 0
Data Retention/deletion based on rules in salesforce
Does anyone has any idea...how to acheive and setup rules(Policies) in salesforce based on which data retention/deletion can be done.
i need Detailed design for rule runner if someone can help me on this
or
Any code architecture.
Rule Runner
The Rule Runner would be a Batch Job which would be scheduled to run on a daily/weekly basis. The Rule Runner would fetch the Retention Rules for each Object and run them against the SFDC database to get the list of Objects that meet the requirement. References to the matched Objects would be added to the Audit table if it does not already exist. The framework would create instances of one of the Policy classes, and execute them to get the required results.
- Rst123
- March 12, 2014
- Like
- 1
Need help on Code coverage issue...
https://docs.google.com/document/d/1i3OjMQ1sPvaV0TKaKIG0O8dfHb4ILTAPie_86F66KxM/edit?usp=sharing
I have written a test class for a Apex class but its not covering and showing only 5% coverage...
Can you help me in getting code coverage :-
Test Class :-
I have written a test class for a Apex class but its not covering and showing only 5% coverage...
Can you help me in getting code coverage :-
I have highlighted the link of my CLASS below
@isTest
private class TestABC {
static testMethod void specialReplaceAmpersandTest() {
String testString = 'test&replacement';
String resultString = 'test%26replacement';
System.assertEquals(Utility.specialReplaceAmpersand(testString),resultString);
}
static testMethod void urlEncodeTest()
{
String testString = 'test&url%encode%test';
String resultString = 'test%26url%25encode%25test';
System.assertEquals(Utility.urlEncode(testString),resultString);
}
static testMethod void differentiateListsTest()
{
List<String> masterList = new List<String>();
masterList.add('Element1');
masterList.add('Element2');
masterList.add('Element3');
List<String> childList = new List<String>();
childList.add('Element2');
List<String> resultList = new List<String>();
resultList.add('Element1');
resultList.add('Element3');
System.assertEquals(Utility.differentiateLists(masterList,childList),resultList);
}
static testMethod void substractSetTest()
{
Set<String> set1 = new Set<String>();
set1.add('Element1');
set1.add('Element2');
set1.add('Element3');
Set<String> set2 = new Set<String>();
set2.add('Element2');
Set<String> resultSet = new Set<String>();
resultSet.add('Element1');
resultSet.add('Element3');
System.assertEquals(Utility.SubstractSet(set1,set2), resultSet);
}
Static testMethod void checkForNullTest()
{
String str1 = 'testStr1';
String str2 = 'testStr2';
String str3;
Decimal decVal1 = 10.0;
Decimal decVal2 = 11.0;
Decimal decVal3;
Integer intVal1 = 10;
Integer intVal2 = 11;
Integer intVal3;
Boolean bool1 = true;
Boolean bool2 = false;
String str4 = 'T' ;
Date dt1 = system.today();
Date dt2 = system.today() + 1;
Date dt3;
DateTime datTime1 = DateTime.now();
DateTime datTime2 = DateTime.now() + 1;
DateTime datTime3;
system.assertEquals(Utility.checkForNull(str1,str2),str2);
system.assertEquals(Utility.checkForNull(str1,str3),str1);
system.assertEquals(Utility.checkForNull(decVal1,decVal2),decVal2);
system.assertEquals(Utility.checkForNull(decVal1,decVal3),decVal1);
system.assertEquals(Utility.checkForNull(intVal1,intVal2),intVal2);
system.assertEquals(Utility.checkForNull(intVal1,intVal3),intVal1);
system.assertEquals(Utility.checkForNull(bool1,bool2),bool2);
system.assertEquals(Utility.checkForNull(bool1,str4),bool1);
system.assertEquals(Utility.checkForNull(dt1,dt2),dt2);
system.assertEquals(Utility.checkForNull(dt1,dt3),dt1);
system.assertEquals(Utility.checkForNull(datTime1,datTime2),datTime2);
system.assertEquals(Utility.checkForNull(datTime1,datTime3),datTime1);
}
static testMethod void getPhoneEscapedTest()
{
String FullNumber = '203-000-007x2345';
String phoneNumber = '203000007';
String extension = '2345';
System.assertEquals(Utility.getPhoneEscaped(FullNumber,true),phoneNumber);
System.assertEquals(Utility.getPhoneEscaped(FullNumber,false),extension);
}
static testMethod void testEncrypt()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g%3D%3D';
System.assertEquals(Utility.EncryptId(Value),Test);
}
static testMethod void testEncryptIdB64()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g==';
System.assertEquals(Utility.EncryptIdB64(Value),Test);
}
static testMethod void testsaveMultipleLogsToDataStore()
{
integer TEST_SIZE = 5 ;
String [] idList = new String[0] ;
String [] strList = new String[0] ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account',Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail');
aList.add(testAccount) ;
}
insert aList;
for (Account a:aList)
idList.add(a.Id) ;
for (integer i=0 ;i < TEST_SIZE ;i++){
String str = '' ;
for (integer k=0 ; k < 700;k++)
str+='AAAAAAAAAAAA ' ;
System.debug('--- ' + str.length());
strList.add(str) ;
}
Test.startTest() ;
System.debug('ID List size : ' + idList.size() + ' StringList size: ' + strList.size());
Utility.saveMultipleLogsToDataStore(idList, 'Test', strList) ;
Integer count = [select count() from Data_Store__c where Parent_Object__c = 'Test'] ;
System.assertEquals(TEST_SIZE*2, count) ; // String is going to be split into 2
Test.stopTest();
}
static testMethod void testcheckLimits(){
integer TEST_SIZE = 1 ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account'+i,Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail'+i);
aList.add(testAccount) ;
}
insert aList;
String debugX = '******* Test log' ;
debugX = Utility.checkLimits(debugX) ;
System.assertEquals(debugX.indexof('RESOURCE USAGE')>0, true) ;
}
}
APEX Class :-
https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FtTIAU#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=ALLQUESTIONS&id=906F00000009FuHIAU (https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FtTIAU#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=ALLQUESTIONS&id=906F00000009FuHIAU (https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FtTIAU#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=ALLQUESTIONS&id=906F00000009FuHIAU))
- Rst123
- February 19, 2014
- Like
- 1
Code coverage Issue :-
https://docs.google.com/document/d/1i3OjMQ1sPvaV0TKaKIG0O8dfHb4ILTAPie_86F66KxM/edit?usp=sharing
I have written a test class for a Apex class but its not covering and showing only 5% coverage...
Can you help me in getting code coverage :-
Test Class :-
I have written a test class for a Apex class but its not covering and showing only 5% coverage...
Can you help me in getting code coverage :-
I have highlighted the link of my CLASS below
@isTest
private class TestABC {
static testMethod void specialReplaceAmpersandTest() {
String testString = 'test&replacement';
String resultString = 'test%26replacement';
System.assertEquals(Utility.specialReplaceAmpersand(testString),resultString);
}
static testMethod void urlEncodeTest()
{
String testString = 'test&url%encode%test';
String resultString = 'test%26url%25encode%25test';
System.assertEquals(Utility.urlEncode(testString),resultString);
}
static testMethod void differentiateListsTest()
{
List<String> masterList = new List<String>();
masterList.add('Element1');
masterList.add('Element2');
masterList.add('Element3');
List<String> childList = new List<String>();
childList.add('Element2');
List<String> resultList = new List<String>();
resultList.add('Element1');
resultList.add('Element3');
System.assertEquals(Utility.differentiateLists(masterList,childList),resultList);
}
static testMethod void substractSetTest()
{
Set<String> set1 = new Set<String>();
set1.add('Element1');
set1.add('Element2');
set1.add('Element3');
Set<String> set2 = new Set<String>();
set2.add('Element2');
Set<String> resultSet = new Set<String>();
resultSet.add('Element1');
resultSet.add('Element3');
System.assertEquals(Utility.SubstractSet(set1,set2), resultSet);
}
Static testMethod void checkForNullTest()
{
String str1 = 'testStr1';
String str2 = 'testStr2';
String str3;
Decimal decVal1 = 10.0;
Decimal decVal2 = 11.0;
Decimal decVal3;
Integer intVal1 = 10;
Integer intVal2 = 11;
Integer intVal3;
Boolean bool1 = true;
Boolean bool2 = false;
String str4 = 'T' ;
Date dt1 = system.today();
Date dt2 = system.today() + 1;
Date dt3;
DateTime datTime1 = DateTime.now();
DateTime datTime2 = DateTime.now() + 1;
DateTime datTime3;
system.assertEquals(Utility.checkForNull(str1,str2),str2);
system.assertEquals(Utility.checkForNull(str1,str3),str1);
system.assertEquals(Utility.checkForNull(decVal1,decVal2),decVal2);
system.assertEquals(Utility.checkForNull(decVal1,decVal3),decVal1);
system.assertEquals(Utility.checkForNull(intVal1,intVal2),intVal2);
system.assertEquals(Utility.checkForNull(intVal1,intVal3),intVal1);
system.assertEquals(Utility.checkForNull(bool1,bool2),bool2);
system.assertEquals(Utility.checkForNull(bool1,str4),bool1);
system.assertEquals(Utility.checkForNull(dt1,dt2),dt2);
system.assertEquals(Utility.checkForNull(dt1,dt3),dt1);
system.assertEquals(Utility.checkForNull(datTime1,datTime2),datTime2);
system.assertEquals(Utility.checkForNull(datTime1,datTime3),datTime1);
}
static testMethod void getPhoneEscapedTest()
{
String FullNumber = '203-000-007x2345';
String phoneNumber = '203000007';
String extension = '2345';
System.assertEquals(Utility.getPhoneEscaped(FullNumber,true),phoneNumber);
System.assertEquals(Utility.getPhoneEscaped(FullNumber,false),extension);
}
static testMethod void testEncrypt()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g%3D%3D';
System.assertEquals(Utility.EncryptId(Value),Test);
}
static testMethod void testEncryptIdB64()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g==';
System.assertEquals(Utility.EncryptIdB64(Value),Test);
}
static testMethod void testsaveMultipleLogsToDataStore()
{
integer TEST_SIZE = 5 ;
String [] idList = new String[0] ;
String [] strList = new String[0] ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account',Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail');
aList.add(testAccount) ;
}
insert aList;
for (Account a:aList)
idList.add(a.Id) ;
for (integer i=0 ;i < TEST_SIZE ;i++){
String str = '' ;
for (integer k=0 ; k < 700;k++)
str+='AAAAAAAAAAAA ' ;
System.debug('--- ' + str.length());
strList.add(str) ;
}
Test.startTest() ;
System.debug('ID List size : ' + idList.size() + ' StringList size: ' + strList.size());
Utility.saveMultipleLogsToDataStore(idList, 'Test', strList) ;
Integer count = [select count() from Data_Store__c where Parent_Object__c = 'Test'] ;
System.assertEquals(TEST_SIZE*2, count) ; // String is going to be split into 2
Test.stopTest();
}
static testMethod void testcheckLimits(){
integer TEST_SIZE = 1 ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account'+i,Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail'+i);
aList.add(testAccount) ;
}
insert aList;
String debugX = '******* Test log' ;
debugX = Utility.checkLimits(debugX) ;
System.assertEquals(debugX.indexof('RESOURCE USAGE')>0, true) ;
}
}
APEX Class :-
https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FtTIAU#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=ALLQUESTIONS&id=906F00000009FuHIAU (https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FtTIAU#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=ALLQUESTIONS&id=906F00000009FuHIAU)
- Rst123
- February 19, 2014
- Like
- 1
Help in incresing test Coverage
link :- https://docs.google.com/document/d/1i3OjMQ1sPvaV0TKaKIG0O8dfHb4ILTAPie_86F66KxM/edit?usp=sharing
Test Class :-
I have written a test class for a Apex class but its not covering and showing only 5% coverage...
Can you help me in getting code coverage :-
I have highlighted the link of my CLASS below
@isTest
private class TestABC {
static testMethod void specialReplaceAmpersandTest() {
String testString = 'test&replacement';
String resultString = 'test%26replacement';
System.assertEquals(Utility.specialReplaceAmpersand(testString),resultString);
}
static testMethod void urlEncodeTest()
{
String testString = 'test&url%encode%test';
String resultString = 'test%26url%25encode%25test';
System.assertEquals(Utility.urlEncode(testString),resultString);
}
static testMethod void differentiateListsTest()
{
List<String> masterList = new List<String>();
masterList.add('Element1');
masterList.add('Element2');
masterList.add('Element3');
List<String> childList = new List<String>();
childList.add('Element2');
List<String> resultList = new List<String>();
resultList.add('Element1');
resultList.add('Element3');
System.assertEquals(Utility.differentiateLists(masterList,childList),resultList);
}
static testMethod void substractSetTest()
{
Set<String> set1 = new Set<String>();
set1.add('Element1');
set1.add('Element2');
set1.add('Element3');
Set<String> set2 = new Set<String>();
set2.add('Element2');
Set<String> resultSet = new Set<String>();
resultSet.add('Element1');
resultSet.add('Element3');
System.assertEquals(Utility.SubstractSet(set1,set2), resultSet);
}
Static testMethod void checkForNullTest()
{
String str1 = 'testStr1';
String str2 = 'testStr2';
String str3;
Decimal decVal1 = 10.0;
Decimal decVal2 = 11.0;
Decimal decVal3;
Integer intVal1 = 10;
Integer intVal2 = 11;
Integer intVal3;
Boolean bool1 = true;
Boolean bool2 = false;
String str4 = 'T' ;
Date dt1 = system.today();
Date dt2 = system.today() + 1;
Date dt3;
DateTime datTime1 = DateTime.now();
DateTime datTime2 = DateTime.now() + 1;
DateTime datTime3;
system.assertEquals(Utility.checkForNull(str1,str2),str2);
system.assertEquals(Utility.checkForNull(str1,str3),str1);
system.assertEquals(Utility.checkForNull(decVal1,decVal2),decVal2);
system.assertEquals(Utility.checkForNull(decVal1,decVal3),decVal1);
system.assertEquals(Utility.checkForNull(intVal1,intVal2),intVal2);
system.assertEquals(Utility.checkForNull(intVal1,intVal3),intVal1);
system.assertEquals(Utility.checkForNull(bool1,bool2),bool2);
system.assertEquals(Utility.checkForNull(bool1,str4),bool1);
system.assertEquals(Utility.checkForNull(dt1,dt2),dt2);
system.assertEquals(Utility.checkForNull(dt1,dt3),dt1);
system.assertEquals(Utility.checkForNull(datTime1,datTime2),datTime2);
system.assertEquals(Utility.checkForNull(datTime1,datTime3),datTime1);
}
static testMethod void getPhoneEscapedTest()
{
String FullNumber = '203-000-007x2345';
String phoneNumber = '203000007';
String extension = '2345';
System.assertEquals(Utility.getPhoneEscaped(FullNumber,true),phoneNumber);
System.assertEquals(Utility.getPhoneEscaped(FullNumber,false),extension);
}
static testMethod void testEncrypt()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g%3D%3D';
System.assertEquals(Utility.EncryptId(Value),Test);
}
static testMethod void testEncryptIdB64()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g==';
System.assertEquals(Utility.EncryptIdB64(Value),Test);
}
static testMethod void testsaveMultipleLogsToDataStore()
{
integer TEST_SIZE = 5 ;
String [] idList = new String[0] ;
String [] strList = new String[0] ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account',Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail');
aList.add(testAccount) ;
}
insert aList;
for (Account a:aList)
idList.add(a.Id) ;
for (integer i=0 ;i < TEST_SIZE ;i++){
String str = '' ;
for (integer k=0 ; k < 700;k++)
str+='AAAAAAAAAAAA ' ;
System.debug('--- ' + str.length());
strList.add(str) ;
}
Test.startTest() ;
System.debug('ID List size : ' + idList.size() + ' StringList size: ' + strList.size());
Utility.saveMultipleLogsToDataStore(idList, 'Test', strList) ;
Integer count = [select count() from Data_Store__c where Parent_Object__c = 'Test'] ;
System.assertEquals(TEST_SIZE*2, count) ; // String is going to be split into 2
Test.stopTest();
}
static testMethod void testcheckLimits(){
integer TEST_SIZE = 1 ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account'+i,Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail'+i);
aList.add(testAccount) ;
}
insert aList;
String debugX = '******* Test log' ;
debugX = Utility.checkLimits(debugX) ;
System.assertEquals(debugX.indexof('RESOURCE USAGE')>0, true) ;
}
}
- Rst123
- February 18, 2014
- Like
- 1
currency conversion issue like want to display AUD 450,000.00 (USD 455,843.92) to USD 455,843.92
i have created a visualforce page diplaying set of fields data in columns :-
My Column :-
<apex:column headerValue="Total Price(USD)">
<apex:repeat value="{!varOpp.opp.OpportunityLineItems}" var="PrdLst" rendered="{!if(varOpp.opp.OpportunityLineItems.size>0 , true, false)}" >
<apex:outputField value="{!PrdLst.TotalPrice}"/><br/>
<apex:param value="{!convertCurrencyWithApexCode}"/>
</apex:repeat>
</apex:column>
Now, I'm getting the data in AUD 450,000.00 (USD 455,843.92) format where i want to display only USD 455,843.92
- Rst123
- November 08, 2013
- Like
- 1
Currency conversion to USD in visualforce directly...
Requirement :-
We need to convert the value in column = Total price(USD) in USD (currently its showing user default currency value)
i.e whatever the currency maybe...it should get it convert into USD and display in Visualforcepage
<apex:column headerValue="Total Price(USD)">
<apex:repeat value="{!varOpp.opp.OpportunityLineItems}" var="PrdLst" rendered="{!if(varOpp.opp.OpportunityLineItems.size>0 , true, false)}" >
<apex:outputText value="{0,Number,currency}"> <apex:param value="{!PrdLst.TotalPrice}" /> </apex:outputText><br/>
</apex:repeat>
</apex:column>
Now, I want to get the value displayed in PrdLst.TotalPrice in USD currency.
- Rst123
- November 07, 2013
- Like
- 1
Auto number : i have a requirement where i need to have a auto number generated for child record
Parent - opportunity
Child - Policy
============
i have a requirement where i need to have a auto number generated for child record(policy) , but child records for 1 parent(opportunity) should be like Pol - 1000 - v0
Pol - 1000 - v1
2nd opportunity child record format :
Pol - 1001 - v0
Pol - 1001 - v2
3rd opportunity child record format :
Pol - 1002 - v0
Pol - 1002 - v1
i.e if parent record is same then child record will have same number with different version, increment in number will be based on (set of policy records) realted to parent records , so policy records having same parent will have same number.
- Rst123
- February 07, 2017
- Like
- 0
Error : Constructor not Defined : Btach class
1> we need to query Policy_Type__c from which we will query all records of object(whichever is defined like account,contact etc) in Entity_Name__c
2> Condition__c is a text field where we define the condition on which SOQL will run .
3>After we get all records of object from Entity_Name__c we need to update these records in another object Audit_Trail__c
I'm getting Error : Constructor not Defined : Btach class when i'm trying to execute it in Developer console
Batch Class :-
global class POLICY implements Database.Batchable<sObject>, Database.Stateful{
Policy_Store__c myVariable = new Policy_Store__c();
String objectname = myVariable.Entity_Name__c;
String Condition = myVariable.Condition__c;
String query1;
String query2;
//Constructor
global POLICY(String query2){
query1 = 'Select Id, Name From '+objectname+' Limit 10000';
List<sObject> L = database.query(query1);
query2 = 'Select Id, Name,Policy_Type__c,Entity_Name__c,('+query1+') From Policy_Store__c where Policy_Type__c = "SOQL" and '+String.valueOf(Condition)+'';
List<sObject> L2 = database.query(query2);
}
// Start Method
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query2);
}
// Execute Mehod
global void execute(
Database.BatchableContext BC,
List<Policy_Store__c> scope){
//for(sObject s : scope){
//Summary = s.get('Policy_Store__c.Object_Name__c');
//}
Audit_Trail__c[] AudT = new List<Audit_Trail__c>();
for (Audit_Trail__c Au : AudT) {
Au.Entity_Name__c = myVariable.Entity_Name__c;
AudT.add(Au);
}
if(AudT.size()>0){
insert AudT;
}
}
global void finish(Database.BatchableContext BC){
}
}
- Rst123
- April 04, 2014
- Like
- 0
Test class Coverage issue ...
Can you help me in getting code coverage :-
I have highlighted the link of my CLASS below
@isTest
private class TestABC {
static testMethod void specialReplaceAmpersandTest() {
String testString = 'test&replacement';
String resultString = 'test%26replacement';
System.assertEquals(Utility.specialReplaceAmpersand(testString),resultString);
}
static testMethod void urlEncodeTest()
{
String testString = 'test&url%encode%test';
String resultString = 'test%26url%25encode%25test';
System.assertEquals(Utility.urlEncode(testString),resultString);
}
static testMethod void differentiateListsTest()
{
List<String> masterList = new List<String>();
masterList.add('Element1');
masterList.add('Element2');
masterList.add('Element3');
List<String> childList = new List<String>();
childList.add('Element2');
List<String> resultList = new List<String>();
resultList.add('Element1');
resultList.add('Element3');
System.assertEquals(Utility.differentiateLists(masterList,childList),resultList);
}
static testMethod void substractSetTest()
{
Set<String> set1 = new Set<String>();
set1.add('Element1');
set1.add('Element2');
set1.add('Element3');
Set<String> set2 = new Set<String>();
set2.add('Element2');
Set<String> resultSet = new Set<String>();
resultSet.add('Element1');
resultSet.add('Element3');
System.assertEquals(Utility.SubstractSet(set1,set2), resultSet);
}
Static testMethod void checkForNullTest()
{
String str1 = 'testStr1';
String str2 = 'testStr2';
String str3;
Decimal decVal1 = 10.0;
Decimal decVal2 = 11.0;
Decimal decVal3;
Integer intVal1 = 10;
Integer intVal2 = 11;
Integer intVal3;
Boolean bool1 = true;
Boolean bool2 = false;
String str4 = 'T' ;
Date dt1 = system.today();
Date dt2 = system.today() + 1;
Date dt3;
DateTime datTime1 = DateTime.now();
DateTime datTime2 = DateTime.now() + 1;
DateTime datTime3;
system.assertEquals(Utility.checkForNull(str1,str2),str2);
system.assertEquals(Utility.checkForNull(str1,str3),str1);
system.assertEquals(Utility.checkForNull(decVal1,decVal2),decVal2);
system.assertEquals(Utility.checkForNull(decVal1,decVal3),decVal1);
system.assertEquals(Utility.checkForNull(intVal1,intVal2),intVal2);
system.assertEquals(Utility.checkForNull(intVal1,intVal3),intVal1);
system.assertEquals(Utility.checkForNull(bool1,bool2),bool2);
system.assertEquals(Utility.checkForNull(bool1,str4),bool1);
system.assertEquals(Utility.checkForNull(dt1,dt2),dt2);
system.assertEquals(Utility.checkForNull(dt1,dt3),dt1);
system.assertEquals(Utility.checkForNull(datTime1,datTime2),datTime2);
system.assertEquals(Utility.checkForNull(datTime1,datTime3),datTime1);
}
static testMethod void getPhoneEscapedTest()
{
String FullNumber = '203-000-007x2345';
String phoneNumber = '203000007';
String extension = '2345';
System.assertEquals(Utility.getPhoneEscaped(FullNumber,true),phoneNumber);
System.assertEquals(Utility.getPhoneEscaped(FullNumber,false),extension);
}
static testMethod void testEncrypt()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g%3D%3D';
System.assertEquals(Utility.EncryptId(Value),Test);
}
static testMethod void testEncryptIdB64()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g==';
System.assertEquals(Utility.EncryptIdB64(Value),Test);
}
static testMethod void testsaveMultipleLogsToDataStore()
{
integer TEST_SIZE = 5 ;
String [] idList = new String[0] ;
String [] strList = new String[0] ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account',Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail');
aList.add(testAccount) ;
}
insert aList;
for (Account a:aList)
idList.add(a.Id) ;
for (integer i=0 ;i < TEST_SIZE ;i++){
String str = '' ;
for (integer k=0 ; k < 700;k++)
str+='AAAAAAAAAAAA ' ;
System.debug('--- ' + str.length());
strList.add(str) ;
}
Test.startTest() ;
System.debug('ID List size : ' + idList.size() + ' StringList size: ' + strList.size());
Utility.saveMultipleLogsToDataStore(idList, 'Test', strList) ;
Integer count = [select count() from Data_Store__c where Parent_Object__c = 'Test'] ;
System.assertEquals(TEST_SIZE*2, count) ; // String is going to be split into 2
Test.stopTest();
}
static testMethod void testcheckLimits(){
integer TEST_SIZE = 1 ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account'+i,Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail'+i);
aList.add(testAccount) ;
}
insert aList;
String debugX = '******* Test log' ;
debugX = Utility.checkLimits(debugX) ;
System.assertEquals(debugX.indexof('RESOURCE USAGE')>0, true) ;
}
}
APEX CLASS :
https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FtTIAU#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=ALLQUESTIONS&id=906F00000009FuHIAU (https://developer.salesforce.com/forums/ForumsMain?id=906F00000009FtTIAU#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=ALLQUESTIONS&id=906F00000009FuHIAU)
- Rst123
- February 18, 2014
- Like
- 0
Test class coverage Issue...
@isTest
private class TestABC {
static testMethod void specialReplaceAmpersandTest() {
String testString = 'test&replacement';
String resultString = 'test%26replacement';
System.assertEquals(Utility.specialReplaceAmpersand(testString),resultString);
}
static testMethod void urlEncodeTest()
{
String testString = 'test&url%encode%test';
String resultString = 'test%26url%25encode%25test';
System.assertEquals(Utility.urlEncode(testString),resultString);
}
static testMethod void differentiateListsTest()
{
List<String> masterList = new List<String>();
masterList.add('Element1');
masterList.add('Element2');
masterList.add('Element3');
List<String> childList = new List<String>();
childList.add('Element2');
List<String> resultList = new List<String>();
resultList.add('Element1');
resultList.add('Element3');
System.assertEquals(Utility.differentiateLists(masterList,childList),resultList);
}
static testMethod void substractSetTest()
{
Set<String> set1 = new Set<String>();
set1.add('Element1');
set1.add('Element2');
set1.add('Element3');
Set<String> set2 = new Set<String>();
set2.add('Element2');
Set<String> resultSet = new Set<String>();
resultSet.add('Element1');
resultSet.add('Element3');
System.assertEquals(Utility.SubstractSet(set1,set2), resultSet);
}
Static testMethod void checkForNullTest()
{
String str1 = 'testStr1';
String str2 = 'testStr2';
String str3;
Decimal decVal1 = 10.0;
Decimal decVal2 = 11.0;
Decimal decVal3;
Integer intVal1 = 10;
Integer intVal2 = 11;
Integer intVal3;
Boolean bool1 = true;
Boolean bool2 = false;
String str4 = 'T' ;
Date dt1 = system.today();
Date dt2 = system.today() + 1;
Date dt3;
DateTime datTime1 = DateTime.now();
DateTime datTime2 = DateTime.now() + 1;
DateTime datTime3;
system.assertEquals(Utility.checkForNull(str1,str2),str2);
system.assertEquals(Utility.checkForNull(str1,str3),str1);
system.assertEquals(Utility.checkForNull(decVal1,decVal2),decVal2);
system.assertEquals(Utility.checkForNull(decVal1,decVal3),decVal1);
system.assertEquals(Utility.checkForNull(intVal1,intVal2),intVal2);
system.assertEquals(Utility.checkForNull(intVal1,intVal3),intVal1);
system.assertEquals(Utility.checkForNull(bool1,bool2),bool2);
system.assertEquals(Utility.checkForNull(bool1,str4),bool1);
system.assertEquals(Utility.checkForNull(dt1,dt2),dt2);
system.assertEquals(Utility.checkForNull(dt1,dt3),dt1);
system.assertEquals(Utility.checkForNull(datTime1,datTime2),datTime2);
system.assertEquals(Utility.checkForNull(datTime1,datTime3),datTime1);
}
static testMethod void getPhoneEscapedTest()
{
String FullNumber = '203-000-007x2345';
String phoneNumber = '203000007';
String extension = '2345';
System.assertEquals(Utility.getPhoneEscaped(FullNumber,true),phoneNumber);
System.assertEquals(Utility.getPhoneEscaped(FullNumber,false),extension);
}
static testMethod void testEncrypt()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g%3D%3D';
System.assertEquals(Utility.EncryptId(Value),Test);
}
static testMethod void testEncryptIdB64()
{
String Value = '003M0000008tN30';
String Test = 'JiW2d9ABjkbJ15c0jFQg7g==';
System.assertEquals(Utility.EncryptIdB64(Value),Test);
}
static testMethod void testsaveMultipleLogsToDataStore()
{
integer TEST_SIZE = 5 ;
String [] idList = new String[0] ;
String [] strList = new String[0] ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account',Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail');
aList.add(testAccount) ;
}
insert aList;
for (Account a:aList)
idList.add(a.Id) ;
for (integer i=0 ;i < TEST_SIZE ;i++){
String str = '' ;
for (integer k=0 ; k < 700;k++)
str+='AAAAAAAAAAAA ' ;
System.debug('--- ' + str.length());
strList.add(str) ;
}
Test.startTest() ;
System.debug('ID List size : ' + idList.size() + ' StringList size: ' + strList.size());
Utility.saveMultipleLogsToDataStore(idList, 'Test', strList) ;
Integer count = [select count() from Data_Store__c where Parent_Object__c = 'Test'] ;
System.assertEquals(TEST_SIZE*2, count) ; // String is going to be split into 2
Test.stopTest();
}
static testMethod void testcheckLimits(){
integer TEST_SIZE = 1 ;
List<Account> aList = new List<Account>() ;
for (integer i=0 ;i < TEST_SIZE ;i++){
Account testAccount = new Account(Name='Test Account'+i,Request_Merge__c = TRUE,Account_Merge_Details__c='Test Detail'+i);
aList.add(testAccount) ;
}
insert aList;
String debugX = '******* Test log' ;
debugX = Utility.checkLimits(debugX) ;
System.assertEquals(debugX.indexof('RESOURCE USAGE')>0, true) ;
}
}
- Rst123
- February 18, 2014
- Like
- 0
FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [Account__c]
I'm getting the below error
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [Account__c]
I have highlighted the method below i'm getting the error :-
I have a master Look field Account__c on object :VVLOC__c
Criteria : -Account Record TypeequalsPartner Record Type
Code :-
@IsTest(SeeAllData=False)
private class TestCreditApprovalUtility {
static testmethod void testCalculateAppRemAmount()
{
Set<String> caOwnerId = new Set<String>();
User u;
Account a;
User thisUser = [ select Id,UserRole.Name,Profile.Name from User where Id = :UserInfo.getUserId() ];
//UserRole r = [select id,UserRole.Name,Profile.Name from User where id = :caOwnerId];
System.runAs ( thisUser ) {
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
u = new User(Alias = 'standt', Email='standarduser@testorg.com',userroleid = thisUser.UserRole.Id,
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US'
, ProfileId = p.Id ,TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testGE.com');
insert u;
}
Set<Id> AccountId = new Set<Id>();
Set<Id> ParentId = new Set<Id>();
Set<Id> OpIds = new Set<Id>();
Set<Id> CaIds = new Set<Id>();
List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();
//Opportunity[] opps=[Select Credit_approval__c from Opportunity where Id in :caopps.keyset()];
//Account account = [Select Id,Name,ParentId from Account where Id in :AccountId];
//Create test account
List<Account> acct = new List<Account>();
Account account = new Account();
account.recordtype=new recordtype(name='Customer Record Type');
account.Name = 'Test';
account.BillingStreet = '123 Some St.';
account.BillingCity = 'Somewhere';
account.BillingState = 'CT';
account.BillingPostalCode = '12345';
account.ParentId = account.Id;
System.runAs(u) {
insert account;
}
// Create a new Partner Account
Account partner = new Account();
partner.recordtype=new recordtype(name='Partner Record Type');
partner.Name = 'Test Partner';
partner.BillingStreet = '123 Some St.';
partner.BillingCity = 'Somewhere';
partner.BillingState = 'CT';
partner.BillingPostalCode = '12345';
insert partner;
// Create a test opportunity to associate with Credit Approvals and Quote
List<Opportunity> OpList= new List<Opportunity>();
Opportunity opportunity = new Opportunity();
opportunity.OwnerId = userinfo.getUserId();
opportunity.AccountId = account.Id;
opportunity.Name = 'Test';
opportunity.StageName = 'Lead';
opportunity.CloseDate = Date.today();
opportunity.Amount=1000;
OpList.add(opportunity);
insert OpList;
for(Opportunity o : OpList){
OpIds.add(o.Id);
}
//Changes made for Audit Cleanup :Increase test class coverage
//Creating test Quote
Quote__c quote= new Quote__c();
quote.Product__c='FMV';
quote.Opportunity__c=opportunity.id;
quote.Include_For_Risk__c=true;
insert quote;
//End of Changes made for Audit Cleanup :Increase test class coverage
//Create test takedowns to associate with opportunity
List<Takedown__c> takedowns= new List<Takedown__c>();
Takedown__c Tk1= new Takedown__c();
Tk1.Name= 'Test T1';
Tk1.Opportunity__c= opportunity.id;
Tk1.CurrencyIsoCode= 'USD';
Tk1.Total_Amount_Financed__c=1000.00;
takedowns.add(Tk1);
Takedown__c Tk2= new Takedown__c();
Tk2.Name= 'Test T2';
Tk2.Opportunity__c= opportunity.id;
Tk2.CurrencyIsoCode= 'USD';
Tk2.Total_Amount_Financed__c=700.00;
takedowns.add(Tk2);
insert takedowns;
Utility.isOwnerUpdate=true;
Utility.IsStageChange=true;
}
// =========Second test method================
static testmethod void testCreditApproval()
{
Set<Id> OpIds = new Set<Id>();
Set<Id> CaIds = new Set<Id>();
Account account = new Account();
Account partner = new Account();
Opportunity opportunity = new Opportunity();
List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();
//Create test Credit Approvals
Credit_Approval__c CA1=new Credit_Approval__c();
CA1.Partner__c=partner.id;
CA1.Account__c=account.id ;
CA1.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA1.Approved_Amount_With_Tolerance__c= 10000;
CA1.Approved_Amount__c= 10000;
CA1.Application_Type__c= 'Line Of Credit';
CA1.Submittal_Status__c= 'Decisioned';
CA1.Risk_Decision__c='Approved';
CA1.LOC_Adjustment_Amount__c= 200.00;
//CA1.Approval_Expiration_Date__c= myDate;
CAList.add(CA1);
Credit_Approval__c CA2=new Credit_Approval__c();
CA2.Partner__c=partner.id;
CA2.Account__c=account.id ;
CA2.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA2.Approved_Amount_With_Tolerance__c= 100.00;
CA2.Approved_Amount__c= 10000;
CA2.LOC_Adjustment_Amount__c= 200.00;
CA2.Application_Type__c= 'Line Of Credit';
CA2.Submittal_Status__c= 'Referred';
CA2.Risk_Decision__c='Approved';
//CA2.Credit_Line_ID__c= creditLine2.id;
//CA2.Approval_Expiration_Date__c= myDate;
CAList.add(CA2);
Credit_Approval__c CA3=new Credit_Approval__c();
CA3.Partner__c=partner.id;
CA3.Account__c=account.id ;
CA3.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA3.Approved_Amount_With_Tolerance__c= 100.00;
CA3.Approved_Amount__c= 10000;
CA3.LOC_Adjustment_Amount__c= 200.00;
CA3.Application_Type__c= 'Deal - Multiple Takedown';
CA3.Submittal_Status__c= 'Test';
CA3.Risk_Decision__c='Approved';
//CA3.Credit_Line_ID__c= creditLine2.id;
//CA3.Approval_Expiration_Date__c= myDate;
CA3.Opportunity__c=opportunity.id;
CAList.add(CA3);
Credit_Approval__c CA4=new Credit_Approval__c();
CA4.Partner__c=partner.id;
CA4.Account__c=account.id ;
CA4.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA4.Approved_Amount_With_Tolerance__c= 10000.00;
CA4.Approved_Amount__c= 10000;
CA4.LOC_Adjustment_Amount__c= 200.00;
CA4.Application_Type__c= 'Deal - Multiple Takedown';
CA4.Submittal_Status__c= 'Decisioned';
CA4.Risk_Decision__c='Approved';
//CA4.Credit_Line_ID__c= creditLine2.id;
//CA4.Approval_Expiration_Date__c= myDate;
CA4.Opportunity__c=opportunity.id;
CAList.add(CA4);
insert CAList;
for(Credit_Approval__c c : CAList){
CaIds.add(c.Id);
}
//Create test Credit Approvals to make them as child Credit Approvals
Credit_Approval__c creditLine1 =new Credit_Approval__c();
creditLine1.Account__c=account.id ;
creditLine1.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine1.Application_Type__c= 'Deal - Multiple Takedown';
creditLine1.Approved_Amount_With_Tolerance__c= 1000.00;
creditLine1.Approved_Amount__c= 200.00;
creditLine1.Submittal_Status__c= 'Decisioned';
creditLine1.Risk_Decision__c='Approved';
creditLine1.Credit_Line_ID__c= CA1.id;
CreditLineList.add(creditLine1);
Credit_Approval__c creditLine2 =new Credit_Approval__c();
creditLine2.Account__c=account.id ;
creditLine2.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine2.Application_Type__c= 'Deal - Multiple Takedown';
creditLine2.Approved_Amount_With_Tolerance__c= 100.00;
creditLine2.Approved_Amount__c= 200.00;
creditLine2.Submittal_Status__c= 'Referred';
creditLine2.Risk_Decision__c='Approved';
creditLine2.Credit_Line_ID__c= CA2.id;
creditLine2.LOC_Adjustment_Amount__c= 200.00;
CreditLineList.add(creditLine2);
Credit_Approval__c creditLine3 =new Credit_Approval__c();
creditLine3.Account__c=account.id ;
creditLine3.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine3.Application_Type__c= 'Deal - Multiple Takedown';
creditLine3.Approved_Amount_With_Tolerance__c= 100.00;
creditLine3.Approved_Amount__c= 200.00;
creditLine3.Submittal_Status__c= 'Referred';
creditLine3.Risk_Decision__c='Approved';
creditLine3.Credit_Line_ID__c= null;
creditLine3.LOC_Adjustment_Amount__c= 200.00;
CreditLineList.add(creditLine3);
insert CreditLineList;
Test.startTest();
//CA1.Approved_Amount_With_Tolerance__c= 20000;
//update CAList;
Map<Id,Decimal> UsedAmt= CreditApprovalUtility.GetUsedAmounts(CaIds);
List<Credit_Approval__c> ca = [Select Id,Amount_Approved_Remaining__c from Credit_Approval__c where Id in :CaIds];
Map<Id,decimal> RemAm= CreditApprovalUtility.CalculateAppRemAmount(null);
Map<Id,decimal> RemAmount= CreditApprovalUtility.CalculateAppRemAmount(CAList);
//system.assertEquals(9800.00,RemAmount.get(CA1.id));
Map<Id,decimal> RemAmountt= CreditApprovalUtility.CalculateAppRemAmount(CreditLineList);
//Changes made for Audit Cleanup :Increase test class coverage
Map<Id,double> PaymentStreamTerm= CreditApprovalUtility.GetPaymentStreamTerm(OpIds);
//system.assertEquals(0.0,PaymentStreamTerm.get(opportunity.id));
//End of Changes made for Audit Cleanup :Increase test class coverage
Test.stopTest();
}
static testmethod void testCreditApproval1()
{
Credit_Approval__c CA=new Credit_Approval__c();
set<id> recordtypeids=new set<id>();
recordtype rectyp = new recordtype();
Set<Id> OpIds = new Set<Id>();
Set<Id> CaIds = new Set<Id>();
Set<Id> AccountId = new Set<Id>();
Set<Id> ParentId = new Set<Id>();
Set<Id> OpId = new Set<Id>();
Set<Id> CAPartnerIds = new Set<Id>();
Account account = new Account();
List<Account> acct = new List<Account>();
//Account account = new Account();
account.recordtype=new recordtype(name='Customer Record Type');
account.Name = 'Test';
account.BillingStreet = '123 Some St.';
account.BillingCity = 'Somewhere';
account.BillingState = 'CT';
account.BillingPostalCode = '12345';
account.ParentId = account.Id;
insert account;
Account partner = new Account();
Opportunity opportunity = new Opportunity();
List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();
VVLOC__c vloc = new VVLOC__c();
vloc.Account__c = Account.ID;
vloc.Vendor_Loc_Status__c = 'INA';
vloc.Name = vloc.Id;
vloc.Vendor_Location__c ='Test';
account.ParentId = account.Id;
Insert vloc;
}
}
- Rst123
- February 18, 2014
- Like
- 0
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Account__c]: [Account__c]
I have highlighted the method below :-
@IsTest(SeeAllData=False)
private class TestCreditApprovalUtility {
static testmethod void testCalculateAppRemAmount()
{
Set<String> caOwnerId = new Set<String>();
User u;
Account a;
User thisUser = [ select Id,UserRole.Name,Profile.Name from User where Id = :UserInfo.getUserId() ];
//UserRole r = [select id,UserRole.Name,Profile.Name from User where id = :caOwnerId];
System.runAs ( thisUser ) {
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
u = new User(Alias = 'standt', Email='standarduser@testorg.com',userroleid = thisUser.UserRole.Id,
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US'
, ProfileId = p.Id ,TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testGE.com');
insert u;
}
Set<Id> AccountId = new Set<Id>();
Set<Id> ParentId = new Set<Id>();
Set<Id> OpIds = new Set<Id>();
Set<Id> CaIds = new Set<Id>();
List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();
//Opportunity[] opps=[Select Credit_approval__c from Opportunity where Id in :caopps.keyset()];
//Account account = [Select Id,Name,ParentId from Account where Id in :AccountId];
//Create test account
List<Account> acct = new List<Account>();
Account account = new Account();
account.recordtype=new recordtype(name='Customer Record Type');
account.Name = 'Test';
account.BillingStreet = '123 Some St.';
account.BillingCity = 'Somewhere';
account.BillingState = 'CT';
account.BillingPostalCode = '12345';
account.ParentId = account.Id;
System.runAs(u) {
insert account;
}
// Create a new Partner Account
Account partner = new Account();
partner.recordtype=new recordtype(name='Partner Record Type');
partner.Name = 'Test Partner';
partner.BillingStreet = '123 Some St.';
partner.BillingCity = 'Somewhere';
partner.BillingState = 'CT';
partner.BillingPostalCode = '12345';
insert partner;
// Create a test opportunity to associate with Credit Approvals and Quote
List<Opportunity> OpList= new List<Opportunity>();
Opportunity opportunity = new Opportunity();
opportunity.OwnerId = userinfo.getUserId();
opportunity.AccountId = account.Id;
opportunity.Name = 'Test';
opportunity.StageName = 'Lead';
opportunity.CloseDate = Date.today();
opportunity.Amount=1000;
OpList.add(opportunity);
insert OpList;
for(Opportunity o : OpList){
OpIds.add(o.Id);
}
//Changes made for Audit Cleanup :Increase test class coverage
//Creating test Quote
Quote__c quote= new Quote__c();
quote.Product__c='FMV';
quote.Opportunity__c=opportunity.id;
quote.Include_For_Risk__c=true;
insert quote;
//End of Changes made for Audit Cleanup :Increase test class coverage
//Create test takedowns to associate with opportunity
List<Takedown__c> takedowns= new List<Takedown__c>();
Takedown__c Tk1= new Takedown__c();
Tk1.Name= 'Test T1';
Tk1.Opportunity__c= opportunity.id;
Tk1.CurrencyIsoCode= 'USD';
Tk1.Total_Amount_Financed__c=1000.00;
takedowns.add(Tk1);
Takedown__c Tk2= new Takedown__c();
Tk2.Name= 'Test T2';
Tk2.Opportunity__c= opportunity.id;
Tk2.CurrencyIsoCode= 'USD';
Tk2.Total_Amount_Financed__c=700.00;
takedowns.add(Tk2);
insert takedowns;
Utility.isOwnerUpdate=true;
Utility.IsStageChange=true;
}
// =========Second test method================
static testmethod void testCreditApproval()
{
Set<Id> OpIds = new Set<Id>();
Set<Id> CaIds = new Set<Id>();
Account account = new Account();
Account partner = new Account();
Opportunity opportunity = new Opportunity();
List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();
//Create test Credit Approvals
Credit_Approval__c CA1=new Credit_Approval__c();
CA1.Partner__c=partner.id;
CA1.Account__c=account.id ;
CA1.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA1.Approved_Amount_With_Tolerance__c= 10000;
CA1.Approved_Amount__c= 10000;
CA1.Application_Type__c= 'Line Of Credit';
CA1.Submittal_Status__c= 'Decisioned';
CA1.Risk_Decision__c='Approved';
CA1.LOC_Adjustment_Amount__c= 200.00;
//CA1.Approval_Expiration_Date__c= myDate;
CAList.add(CA1);
Credit_Approval__c CA2=new Credit_Approval__c();
CA2.Partner__c=partner.id;
CA2.Account__c=account.id ;
CA2.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA2.Approved_Amount_With_Tolerance__c= 100.00;
CA2.Approved_Amount__c= 10000;
CA2.LOC_Adjustment_Amount__c= 200.00;
CA2.Application_Type__c= 'Line Of Credit';
CA2.Submittal_Status__c= 'Referred';
CA2.Risk_Decision__c='Approved';
//CA2.Credit_Line_ID__c= creditLine2.id;
//CA2.Approval_Expiration_Date__c= myDate;
CAList.add(CA2);
Credit_Approval__c CA3=new Credit_Approval__c();
CA3.Partner__c=partner.id;
CA3.Account__c=account.id ;
CA3.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA3.Approved_Amount_With_Tolerance__c= 100.00;
CA3.Approved_Amount__c= 10000;
CA3.LOC_Adjustment_Amount__c= 200.00;
CA3.Application_Type__c= 'Deal - Multiple Takedown';
CA3.Submittal_Status__c= 'Test';
CA3.Risk_Decision__c='Approved';
//CA3.Credit_Line_ID__c= creditLine2.id;
//CA3.Approval_Expiration_Date__c= myDate;
CA3.Opportunity__c=opportunity.id;
CAList.add(CA3);
Credit_Approval__c CA4=new Credit_Approval__c();
CA4.Partner__c=partner.id;
CA4.Account__c=account.id ;
CA4.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
CA4.Approved_Amount_With_Tolerance__c= 10000.00;
CA4.Approved_Amount__c= 10000;
CA4.LOC_Adjustment_Amount__c= 200.00;
CA4.Application_Type__c= 'Deal - Multiple Takedown';
CA4.Submittal_Status__c= 'Decisioned';
CA4.Risk_Decision__c='Approved';
//CA4.Credit_Line_ID__c= creditLine2.id;
//CA4.Approval_Expiration_Date__c= myDate;
CA4.Opportunity__c=opportunity.id;
CAList.add(CA4);
insert CAList;
for(Credit_Approval__c c : CAList){
CaIds.add(c.Id);
}
//Create test Credit Approvals to make them as child Credit Approvals
Credit_Approval__c creditLine1 =new Credit_Approval__c();
creditLine1.Account__c=account.id ;
creditLine1.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine1.Application_Type__c= 'Deal - Multiple Takedown';
creditLine1.Approved_Amount_With_Tolerance__c= 1000.00;
creditLine1.Approved_Amount__c= 200.00;
creditLine1.Submittal_Status__c= 'Decisioned';
creditLine1.Risk_Decision__c='Approved';
creditLine1.Credit_Line_ID__c= CA1.id;
CreditLineList.add(creditLine1);
Credit_Approval__c creditLine2 =new Credit_Approval__c();
creditLine2.Account__c=account.id ;
creditLine2.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine2.Application_Type__c= 'Deal - Multiple Takedown';
creditLine2.Approved_Amount_With_Tolerance__c= 100.00;
creditLine2.Approved_Amount__c= 200.00;
creditLine2.Submittal_Status__c= 'Referred';
creditLine2.Risk_Decision__c='Approved';
creditLine2.Credit_Line_ID__c= CA2.id;
creditLine2.LOC_Adjustment_Amount__c= 200.00;
CreditLineList.add(creditLine2);
Credit_Approval__c creditLine3 =new Credit_Approval__c();
creditLine3.Account__c=account.id ;
creditLine3.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
creditLine3.Application_Type__c= 'Deal - Multiple Takedown';
creditLine3.Approved_Amount_With_Tolerance__c= 100.00;
creditLine3.Approved_Amount__c= 200.00;
creditLine3.Submittal_Status__c= 'Referred';
creditLine3.Risk_Decision__c='Approved';
creditLine3.Credit_Line_ID__c= null;
creditLine3.LOC_Adjustment_Amount__c= 200.00;
CreditLineList.add(creditLine3);
insert CreditLineList;
Test.startTest();
//CA1.Approved_Amount_With_Tolerance__c= 20000;
//update CAList;
Map<Id,Decimal> UsedAmt= CreditApprovalUtility.GetUsedAmounts(CaIds);
List<Credit_Approval__c> ca = [Select Id,Amount_Approved_Remaining__c from Credit_Approval__c where Id in :CaIds];
Map<Id,decimal> RemAm= CreditApprovalUtility.CalculateAppRemAmount(null);
Map<Id,decimal> RemAmount= CreditApprovalUtility.CalculateAppRemAmount(CAList);
//system.assertEquals(9800.00,RemAmount.get(CA1.id));
Map<Id,decimal> RemAmountt= CreditApprovalUtility.CalculateAppRemAmount(CreditLineList);
//Changes made for Audit Cleanup :Increase test class coverage
Map<Id,double> PaymentStreamTerm= CreditApprovalUtility.GetPaymentStreamTerm(OpIds);
//system.assertEquals(0.0,PaymentStreamTerm.get(opportunity.id));
//End of Changes made for Audit Cleanup :Increase test class coverage
Test.stopTest();
}
static testmethod void testCreditApproval1()
{
Credit_Approval__c CA=new Credit_Approval__c();
set<id> recordtypeids=new set<id>();
recordtype rectyp = new recordtype();
Set<Id> OpIds = new Set<Id>();
Set<Id> CaIds = new Set<Id>();
Set<Id> AccountId = new Set<Id>();
Set<Id> ParentId = new Set<Id>();
Set<Id> OpId = new Set<Id>();
Set<Id> CAPartnerIds = new Set<Id>();
Account account = new Account();
Account partner = new Account();
Opportunity opportunity = new Opportunity();
List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();
VVLOC__c vloc = new VVLOC__c();
vloc.Account__c = account.Name;
vloc.Vendor_Loc_Status__c = 'INA';
vloc.Name = vloc.Id;
vloc.Vendor_Location__c ='Test';
account.ParentId = account.Id;
Insert vloc;
}
}
- Rst123
- February 17, 2014
- Like
- 0
ERROR : Too many SOQL queries: 101
I'm getting error"Too many SOQL queries: 101" in line User user1 = [Select id, Profile.Name from User where Id= :UserInfo.getUserId() ]; of code below :-
I have highlighted the line below.
//Method added for Sending AFD to Siebel
if(trigger.isBefore && trigger.isUpdate){
Set<String> caOwnerId = new Set<String>();
Map<Id,User> ownerRole = new Map<Id,User>();
String s_profile = null; //Addition for Defect 13928
for(Credit_Approval__c ca:trigger.new){
caOwnerId.add(ca.OwnerId);
}
if(caOwnerId.size()>0){
ownerRole = new Map<Id,User>([select id,UserRole.Name from User where id = :caOwnerId]);
}
User user1 = [Select id, Profile.Name from User where Id= :UserInfo.getUserId() ];
s_profile = user1.Profile.Name;
for(Credit_Approval__c ca:trigger.new){
if(OwnerRole.get(ca.OwnerId)!=null && !'GE Integration User'.equalsIgnoreCase(s_profile)){
//if(OwnerRole.get(ca.OwnerId)!=null{
if(OwnerRole.get(ca.OwnerId).UserRole!=null && OwnerRole.get(ca.OwnerId).UserRole.Name.contains('HFS')&& OwnerRole.get(ca.OwnerId).UserRole.Name.contains('Zone')){// HFS Project Change - Add null check
ca.Flow_Struc__c = 'Flow';
}
if(OwnerRole.get(ca.OwnerId).UserRole!=null && OwnerRole.get(ca.OwnerId).UserRole.Name.contains('HFS')&& !OwnerRole.get(ca.OwnerId).UserRole.Name.contains('Zone')){// HFS Project Change - Add null check
ca.Flow_Struc__c = 'Structured';
}
}
}
}
}
Can you please help me out on this to acheive this.
- Rst123
- February 12, 2014
- Like
- 0
ERROR : Too many SOQL queries: 101
I'm getting error"Too many SOQL queries: 101" in line User user1 = [Select id, Profile.Name from User where Id= :UserInfo.getUserId() ]; of code below :-
I have highlighted the line below.
//Method added for Sending AFD to Siebel
if(trigger.isBefore && trigger.isUpdate){
Set<String> caOwnerId = new Set<String>();
Map<Id,User> ownerRole = new Map<Id,User>();
String s_profile = null; //Addition for Defect 13928
for(Credit_Approval__c ca:trigger.new){
caOwnerId.add(ca.OwnerId);
}
if(caOwnerId.size()>0){
ownerRole = new Map<Id,User>([select id,UserRole.Name from User where id = :caOwnerId]);
}
User user1 = [Select id, Profile.Name from User where Id= :UserInfo.getUserId() ];
s_profile = user1.Profile.Name;
for(Credit_Approval__c ca:trigger.new){
if(OwnerRole.get(ca.OwnerId)!=null && !'GE Integration User'.equalsIgnoreCase(s_profile)){
//if(OwnerRole.get(ca.OwnerId)!=null{
if(OwnerRole.get(ca.OwnerId).UserRole!=null && OwnerRole.get(ca.OwnerId).UserRole.Name.contains('HFS')&& OwnerRole.get(ca.OwnerId).UserRole.Name.contains('Zone')){// HFS Project Change - Add null check
ca.Flow_Struc__c = 'Flow';
}
if(OwnerRole.get(ca.OwnerId).UserRole!=null && OwnerRole.get(ca.OwnerId).UserRole.Name.contains('HFS')&& !OwnerRole.get(ca.OwnerId).UserRole.Name.contains('Zone')){// HFS Project Change - Add null check
ca.Flow_Struc__c = 'Structured';
}
}
}
}
}
- Rst123
- February 12, 2014
- Like
- 0
Help!! Format result in column
Hi,
I'm getting the result of total price of 2 opportunityline item in one row 25225.17 37837.75 format
where as i want the result in different row i.e total price of opportunityline item should come in front of respective lineitem
25225.17
37837.75
My code :-
public Class cOpportunity{
public Product2 opppr1 {get;set;}
public Opportunity opp {get;set;}
public Account acc1 {get;set;}
public Boolean selected{get;set;}
public String convertPrice {get;set;}
//public Decimal convertPrice {get;set;}
List<OpportunityLineItem> oppLineLst;
cOpportunity(Opportunity o){
convertPrice = ''; opp=o;
selected=false;
For(OpportunityLineItem ol :o.OpportunityLineItems){
Double conversionRate = [SELECT conversionrate,IsoCode FROM currencytype WHERE isocode =:ol.CurrencyIsoCode LIMIT 1].conversionRate;
// if(!convertPrice.contains(String.ValueOf(ol.TotalPrice * conversionRate)))
if(ol.CurrencyIsoCode != 'USD')
convertPrice += '\n\r'+ (ol.TotalPrice * (1/conversionRate)).setscale(2)+'\n\r';
else
convertPrice += '\n\r'+ (ol.TotalPrice).setscale(2) +'\n\r';
}
}
}
- Rst123
- November 21, 2013
- Like
- 0