• System Administrator 393
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 2
    Replies
I have a written an apex class for a custom object called loan disbursement transactions. This custom object is a child object to the account. I have a currency field on the account record that calculates the sum of the loan disbursement transaction value, each of these values are coming from the child object, loan disbursement transaction. Usually there are only 2 such values. When I try to run this apex code, the total disbursements field on the account record does not update. Can someone please help me with what I am doing wrong? The apex code is below: 

public class UpdateLoantransactions{


  public static List<Loan_Disbursement_Transactions__c> listoftransactions(Account b){
  List<Loan_Disbursement_Transactions__c> transactions1 = [SELECT Name, Disbursement__c, Account__c, Loan_Disbursement_Value__c FROM Loan_Disbursement_Transactions__c WHERE Account__c =: b.Name];
 
  return transactions1;
 }
  
 public static decimal gettransactionvalue1(Account b2){
 decimal d = 0.00;
 
 if((listoftransactions(b2)).size()>0){
 d = (((listoftransactions(b2)).get(0)).Loan_Disbursement_Value__c);}
 
 return d;
 }
 
 public static decimal gettransactionvalue2(Account b3){
 decimal d1 = 0.00;
 
 if(((listoftransactions(b3)).get(1))!=null){
 d1 = (((listoftransactions(b3)).get(1)).Loan_Disbursement_Value__c);}
 return d1;
 }
 
 public static decimal gettotaldisbursements(Account b4){
 decimal d2 = 0.0;
 d2 = gettransactionvalue1(b4) + gettransactionvalue2(b4);
 b4.Total_Disbursement__c = d2;
  return b4.Total_Disbursement__c;
 }
 }

Thanks
I have customized objects Bills andContract. A contract has many bills. Here is the code to calculate revenue from bills based on their transaction dates and update a field on the contract. 

Here is the class:

public class UpdateRunRateonloanaccount{

public static decimal getbills(loan__Loan_Account__c a){

decimal d = 0.00;
decimal d1 = 0.00;
decimal d2 = 0.00;
decimal d3 = 0.00;
decimal d4 = 0.00;
decimal d5 = 0.00;

List<loan__Loan_account_Due_Details__c> bill1 = [SELECT Id, Account_Name__c, CurrencyIsoCode, loan__Loan_Account__c, loan__Transaction_Date__c,Revenue_Recurring_for_Period__c,Metrics_Good__c, Participation_Revenue_for_Period__c FROM loan__Loan_account_Due_Details__c WHERE loan__Loan_Account__c =: a.Id];

for(loan__Loan_account_Due_Details__c b : bill1){

if(b.loan__Transaction_Date__c > (Date.today()-30)){
 d = b.Participation_Revenue_for_Period__c;
}

if((b.loan__Transaction_Date__c < Date.today()-30) && (b.loan__Transaction_Date__c > Date.today()-60)){

d1 = b.Participation_Revenue_for_Period__c;
}

if((b.loan__Transaction_Date__c < Date.today()-60) && (b.loan__Transaction_Date__c > Date.today()-90)){

d2 = b.Participation_Revenue_for_Period__c;
}

if((b.loan__Transaction_Date__c < Date.today()-90) && (b.loan__Transaction_Date__c > Date.today()-120)){

d3 = b.Participation_Revenue_for_Period__c;
}

if((b.loan__Transaction_Date__c < Date.today()-120) && (b.loan__Transaction_Date__c > Date.today()-150)){

d4 = b.Participation_Revenue_for_Period__c;

}



if((b.loan__Transaction_Date__c < Date.today()-150) && (b.loan__Transaction_Date__c > Date.today()-180)){

d5 = b.Participation_Revenue_for_Period__c;

}
}

if(d == 0.00 && d1 > 0 && d2 > 0 && d3 > 0){
a.Sum_of_last_3_months_recurring_revenues__c = ((d1 + d2 + d3)*4);
}
else if (d > 0.00 && d1 > 0 && d2 > 0){
a.Sum_of_last_3_months_recurring_revenues__c = ((d + d1 + d2)*4);


else if (d == 0.00 && d1 == 0.00 && d2 > 0.00 && d3 > 0.00 && d4 > 0.00){
a.Sum_of_last_3_months_recurring_revenues__c = ((d2 + d3 + d4)*4);
}

else if (d == 0.00 && d1 == 0.00 && d2 == 0.00 && d3 > 0.00 && d4 > 0.00 && d5 > 0.00){
a.Sum_of_last_3_months_recurring_revenues__c = ((d3 + d4 + d5)*4);
}
return a.Sum_of_last_3_months_recurring_revenues__c;
}
}

Here is the trigger:

trigger UpdateSum on loan__Loan_Account__c (before insert,before update) {
    
        for (loan__Loan_Account__c c : Trigger.new) {
        
       if(c.loan__Loan_Amount__c != null){
    
        
        UpdateRunRateonloanaccount.getbills(c);
        
        }
      
  }
}

The field on the CLContract does not update wih the required value, I believe that there is something wrong with the trigger because the field doesnot update.

 
All the tests pass and I have 50% Code Covergae, the highlighted bold text is the one that I do not have code coverage for.

public class UpdateContactfields{

public static Account getAccount(loan__Loan_account_Due_Details__c a) {


 Account a1 = [SELECT Id, Name, CurrencyIsoCode FROM Account WHERE Name =: a.Account_Name__c];
 
 return a1;
 
 }
 
 public static List<Contact> ListofCons(loan__Loan_account_Due_Details__c a){
 
 List<Contact> c = [SELECT AccountId, Name, Email, Title, Contact_Status__c  FROM Contact WHERE AccountId =: getAccount(a).Id ];
 
 return c;
 
 }
 
 public static String setfield(loan__Loan_account_Due_Details__c a1){
 
 
 if((ListofCons(a1)).size()>0){
 for(Contact c2:(ListofCons(a1))){
 if(c2.Contact_Status__c == 'Signing Officer'){
 a1.Signing_Officer__c = c2.Name;
 }
}
}
return a1.Signing_Officer__c;


}
}



@isTest
private class UpdateContacts{

    @isTest static void UpdateContacts_Test() {
    
    Account acc = new Account(Name = 'DEF');
    insert acc;
    
    Account acc1 = new Account(Name = 'PRI');
    insert acc1;
    
    Contact c1 = New Contact();
    c1.LastName = 'ABC';
    c1.Title = 'CEO';
    c1.Contact_Status__c = 'Signing Officer';
    c1.AccountId = acc.Id;
    c1.Email = 'sh123@gmail.com';
    insert c1;
    
    
    Contact c2 = New Contact();
    c2.LastName = 'XYZ';
    c2.Title = 'CFO';
    c2.Contact_Status__c = 'Financial Operations';
    c2.AccountId = acc.Id;
    c2.Email = 'lo123@gmail.com';
    insert c2;
    
    List<Contact> cons1 = new List<Contact>();
    cons1.add(c1);
    cons1.add(c2);
    
    
    Id n1;
    loan__Office_Name__c[] a = [SELECT Name,loan__Office_Name_ID__c,CurrencyIsoCode, loan__Office_Short_Name__c FROM loan__Office_Name__c WHERE Name = 'TIMIA Capital Corporation YVR'Limit 1];
    if(a.size()>0){
    n1 = a[0].Id;
    }
    Id n2;
    loan__Loan_Product__c[] a1 = [SELECT Name, loan__Loan_Product_External_Id__c FROM loan__Loan_Product__c WHERE Name = 'Revenue Loan - HiGrowth STEP UP'Limit 1];
    if(a1.size()>0){
    n2 = a1[0].Id;
    }
    else n2 = null;
    
    loan__Loan_Account__c l1 = new loan__Loan_Account__c(loan__Account__c = acc.Id, loan__Loan_Amount__c = 1000000, loan__Due_Day__c = 5, loan__Interest_Rate__c = 21,loan__Branch__c = n1,loan__Loan_Product_Name__c = n2);
    Database.insert (l1, false);
    loan__Loan_Account__c l2 = new loan__Loan_Account__c(loan__Account__c = acc1.Id, loan__Loan_Amount__c = 1000000, loan__Due_Day__c = 5, loan__Interest_Rate__c = 21,loan__Branch__c = n1,loan__Loan_Product_Name__c = n2);
    Database.insert(l2,false);
    
    
    loan__Loan_account_Due_Details__c b1 = new loan__Loan_account_Due_Details__c(loan__Loan_Account__c = l1.Id);
    System.assertEquals(l1.Id, b1.loan__Loan_Account__c);
    
    loan__Loan_account_Due_Details__c b3 = new loan__Loan_account_Due_Details__c(loan__Loan_Account__c = l2.Id);
    
    
    Database.insert (b1, false);
    Database.insert(b3, false);
    
    
    try {
    loan__Loan_account_Due_Details__c b2 = [SELECT Name, loan__Loan_Account__c, Signing_Officer__c, CurrencyIsoCode, Account_Name__c FROM loan__Loan_account_Due_Details__c WHERE Name =: b1.Name];
    
    Account a2 = [SELECT Id, Name, CurrencyIsoCode FROM Account WHERE Name =: b2.Account_Name__c];
    System.assertEquals(a2,UpdateContactfields.getAccount(b2));
    
    System.assertEquals(acc.Id, UpdateContactfields.getAccount(b2).Id);
    
    System.assertEquals('DEF',UpdateContactfields.getAccount(b2).Name);
    
    System.assertEquals(cons1,(UpdateContactfields.ListofCons(b2)));
    
    System.assertEquals(2,(UpdateContactfields.ListofCons(b2)).size());
    
    System.assert((UpdateContactfields.ListofCons(b2)).contains(c1),true);
    
    System.assert(UpdateContactfields.ListofCons(b2).contains(c2),true);
    
    Contact con1 = (UpdateContactfields.ListofCons(b2))[0];
    System.assertEquals('ABC', (UpdateContactfields.ListofCons(b2))[0].Name);
    System.assert(con1.Contact_Status__c == 'Signing Officer', true);
    System.assert(b2.Signing_Officer__c == null, true);
    System.assertEquals('ABC',UpdateContactfields.setfield(b2));
    System.assertEquals('ABC', b2.Signing_Officer__c);
    
    
    Contact cons2 = (UpdateContactfields.ListofCons(b2))[1];
    System.assertEquals('XYZ', (UpdateContactfields.ListofCons(b2))[0].Name);
    System.assert(cons2.Contact_Status__c == 'Signing Officer', false);
    System.assert(b2.Signing_Officer__c == null, false);
    System.assertEquals('ABC',UpdateContactfields.setfield(b2));
    System.assertEquals('ABC', b2.Signing_Officer__c);
    
    Contact con3 = (UpdateContactfields.ListofCons(b2))[2];
    System.assertEquals(null, (UpdateContactfields.ListofCons(b2))[2]);
    
     
    loan__Loan_account_Due_Details__c b4 = [SELECT Name, loan__Loan_Account__c, Signing_Officer__c, CurrencyIsoCode, Account_Name__c FROM loan__Loan_account_Due_Details__c WHERE Name =: b3.Name];
    System.assertEquals(acc1,UpdateContactfields.getAccount(b4));
    System.assertEquals(0,(UpdateContactfields.ListofCons(b4)).size());
    System.assert(UpdateContactfields.ListofCons(b4).contains(c1), false);
    System.assert(UpdateContactfields.ListofCons(b4).contains(c2), false);
    System.assertEquals(null, UpdateContactfields.setfield(b2));
    System.assertEquals(null, b4.Signing_Officer__c);
    
    
   }
   catch(QueryException e){
   
    
   
   
}   
 
        
}
}
I have the a customized object called Application. It has a field called total Score and this field is a roll up summary and gets it values from the when 3 scoreacards are run. I am trying to use this field in my test class but I cannot figure out how to run the scorecards so that these fields gets a value. If I do not run the scorecards, then the total score field is automatically 0.00
Please help

Thanks,
Priyal
I am writing a test class that tests for a class that checks the values of two formula fields and updates other fields. I am tryng to use thse fields in the test class, however, there values seem to be null. It does not seem like these formula fields are being updated. The genesis__Total_Score__c  and Annualized_Recurring_Revenue_Run_Rate__c field are the formula fields and their actual values are null, however all the required fields needed for their formulas have values. 

User-added image

Any help would be great. 

Thanksss
I have a look up called Credit Rating and that is supposed to generate Ids such as AB4, CB5. I am writing an apex class that derives these IDS based on other nuerical fields. However, I am making a string and the string has to be assigned to the Id data type as the field Credit Rating is a look up field with data type Id. I tried to cast it like this but it keeps showing me this error
"System.StringException: Invalid id:  AD6()" , please help.
User-added image
 
I pushed an Apex Class and Trigger to production but my TestClass is in sandbox, when the tests are run in production before deployment, does it run all tests from production, sandbox or both?
I have an Apex Class Test in which I need to create a new Account Object and set its name, however when I use Account acc = new I have an Apex Class Test in which I need to create a new Account Object and set its name, however when I use Account acc = new Account(Name = 'ABC'), it shows me invalide field Name but Name is the API Name of the field in the Account Object, Can anyone please help me?
2016-03-11 18:44:28.430017 - DEBUG --> GFFeedAddOn::maybe_process_feed(): Starting to process feed (#1 - ) for entry #199 for sf-web-to-lead 
2016-03-11 18:44:28.430336 - DEBUG --> Opt-in condition met; adding entry 199 to Salesforce 
2016-03-11 18:44:28.430639 - DEBUG --> All Feed Meta: Array
(
    [email] => 2
    [salutation] => 
    [first_name] => 11.3
    [last_name] => 11.6
    [title] => 
    [company] => 7
    [phone] => 12
    [mobile] => 
    [fax] => 
    [street] => 
    [street2] => 
    [city] => 
    [state] => 
    [country] => 
    [zip] => 
    [URL] => 
    [twitter] => 
    [message] => 
    [lead_source] => 14
    [description] => 
    [industry] => 
    [rating] => 
    [revenue] => 
    [employees] => 
    [Campaign_ID] => 
    [member_status] => 
    [emailOptOut] => 
    [faxOptOut] => 
    [doNotCall] => 
    [retURL] => 
    [Priority] => 
    [recordType] => 3
    [00N61000004cn5A] => 13
    [00N61000004cpQt] => 15.1
)
 
2016-03-11 18:44:28.430905 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID salutation 
2016-03-11 18:44:28.431261 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID title 
2016-03-11 18:44:28.431565 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID mobile 
2016-03-11 18:44:28.431736 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID fax 
2016-03-11 18:44:28.431898 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID street 
2016-03-11 18:44:28.432058 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID street2 
2016-03-11 18:44:28.432219 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID city 
2016-03-11 18:44:28.432375 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID state 
2016-03-11 18:44:28.432531 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID country 
2016-03-11 18:44:28.432682 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID zip 
2016-03-11 18:44:28.432842 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID URL 
2016-03-11 18:44:28.433005 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID twitter 
2016-03-11 18:44:28.433156 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID message 
2016-03-11 18:44:28.433401 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID description 
2016-03-11 18:44:28.433547 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID industry 
2016-03-11 18:44:28.433649 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID rating 
2016-03-11 18:44:28.433763 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID revenue 
2016-03-11 18:44:28.433913 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID employees 
2016-03-11 18:44:28.434065 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID Campaign_ID 
2016-03-11 18:44:28.434217 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID member_status 
2016-03-11 18:44:28.434376 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID emailOptOut 
2016-03-11 18:44:28.434535 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID faxOptOut 
2016-03-11 18:44:28.434693 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID doNotCall 
2016-03-11 18:44:28.434844 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID retURL 
2016-03-11 18:44:28.435003 - DEBUG --> [get_merge_vars_from_entry]: Feed field not defined for field ID Priority 
2016-03-11 18:44:28.435451 - DEBUG --> Temp Merge Vars: Array
(
    [email] => name@email.com
    [first_name] => First Name
    [last_name] => Last Name
    [company] => My Company
    [phone] => (778) 205-6440
    [lead_source] => Lead from Contact Us (Website)
    [recordType] => 01261000000LOPy
    [00N61000004cn5A] => test
    [00N61000004cpQt] => 
)
 
2016-03-11 18:44:28.435981 - DEBUG --> DA::filter_web_to_lead_merge_vars() - Starting adding DA data to merge vars. 
2016-03-11 18:44:28.436223 - DEBUG --> DA::filter_api_merge_vars() - Added DA data to merge vars. Token:  and Url:  
2016-03-11 18:44:28.436774 - DEBUG --> This is the data sent to Salesforce (at https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8:
Array
(
    [body] => Array
        (
            [email] => name@email.com
            [first_name] => First Name
            [last_name] => Last Name
            [company] => My Company
            [phone] => (778) 205-6440
            [lead_source] => Lead from Contact Us (Website)
            [recordType] => 01261000000LOPy
            [00N61000004cn5A] => test
            [oid] => MYORGID (Removed for privacy)
            [debug] => 0
            [debug_email] => 0
            [retURL] => /contact-us/
        )

    [headers] => Array
        (
            [user-agent] => Gravity Forms Salesforce Add-on plugin - WordPress/4.4.2; http://www.timiacapital.com
        )

    [sslverify] => 
    [timeout] => 60
)
) 
2016-03-11 18:44:28.859867 - DEBUG --> The `is-processed` header isn't set. This means there were no errors adding the entry. 
2016-03-11 18:44:28.860122 - DEBUG --> Entry 199 was added to Salesforce. Here's the available data:
Array
(
    [headers] => Array
        (
            [date] => Fri, 11 Mar 2016 18:44:28 GMT
            [set-cookie] => BrowserId=iHLDj1x1SpGp8XJ9_zSxiA;Path=/;Domain=.salesforce.com;Expires=Tue, 10-May-2016 18:44:28 GMT
            [expires] => Thu, 01 Jan 1970 00:00:00 GMT
            [cache-control] => private,s-maxage=0
            [content-type] => text/html;charset=UTF-8
            [connection] => close
        )

    [body] => 
    [response] => Array
        (
            [code] => 200
            [message] => OK
        )

    [cookies] => Array
        (
            [0] => WP_Http_Cookie Object
                (
                    [name] => BrowserId
                    [value] => iHLDj1x1SpGp8XJ9_zSxiA
                    [expires] => 1462905868
                    [path] => /
                    [domain] => .salesforce.com
                )

        )

    [filename] => 
)
 
2016-03-11 18:44:28.860300 - DEBUG --> GFFeedAddOn::maybe_process_feed(): Marking entry #199 as fulfilled for sf-web-to-lead

I have a simple Wordpress Gravity Forms contact us form that was previously working fine with Salesforce Web-To-Lead.  Now, no records are being accepted into Salesforce.

Attached is the log, are there any obvious reasons why leads aren't being accepted into SF?


 
I have a written an apex class for a custom object called loan disbursement transactions. This custom object is a child object to the account. I have a currency field on the account record that calculates the sum of the loan disbursement transaction value, each of these values are coming from the child object, loan disbursement transaction. Usually there are only 2 such values. When I try to run this apex code, the total disbursements field on the account record does not update. Can someone please help me with what I am doing wrong? The apex code is below: 

public class UpdateLoantransactions{


  public static List<Loan_Disbursement_Transactions__c> listoftransactions(Account b){
  List<Loan_Disbursement_Transactions__c> transactions1 = [SELECT Name, Disbursement__c, Account__c, Loan_Disbursement_Value__c FROM Loan_Disbursement_Transactions__c WHERE Account__c =: b.Name];
 
  return transactions1;
 }
  
 public static decimal gettransactionvalue1(Account b2){
 decimal d = 0.00;
 
 if((listoftransactions(b2)).size()>0){
 d = (((listoftransactions(b2)).get(0)).Loan_Disbursement_Value__c);}
 
 return d;
 }
 
 public static decimal gettransactionvalue2(Account b3){
 decimal d1 = 0.00;
 
 if(((listoftransactions(b3)).get(1))!=null){
 d1 = (((listoftransactions(b3)).get(1)).Loan_Disbursement_Value__c);}
 return d1;
 }
 
 public static decimal gettotaldisbursements(Account b4){
 decimal d2 = 0.0;
 d2 = gettransactionvalue1(b4) + gettransactionvalue2(b4);
 b4.Total_Disbursement__c = d2;
  return b4.Total_Disbursement__c;
 }
 }

Thanks
I have an Apex Class Test in which I need to create a new Account Object and set its name, however when I use Account acc = new I have an Apex Class Test in which I need to create a new Account Object and set its name, however when I use Account acc = new Account(Name = 'ABC'), it shows me invalide field Name but Name is the API Name of the field in the Account Object, Can anyone please help me?