• Olga Kim 5
  • NEWBIE
  • 30 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 6
    Replies
Hello, Salesforce Professionals 

I need to create a validation rule that will prevent creating records with the same proprietary_number__c field on billing__c object.

I wrote this formula: 

and(
proprietary_number__c = VLOOKUP
($ObjectType.billing__c.Fields.proprietary_number__c , $ObjectType.billing__c.Fields.Name , proprietary_number__c ),

not(
Id=VLOOKUP
($ObjectType.billing__c.Fields.Id , $ObjectType.billing__c.Fields.Name , proprietary_number__c )))   

But it doesn't work. I still can create a record with a duplicate proprietary_number__c  field. 

Please, help me. I can't understand what I am missing in this formula. 

Thank you in advance.
 
Is it possible to create a PDF Page that contains values from three related objects?

If it is, how would I do that? 

Thank you, in advance!
Is it possible to exempt one Profile from the validation rule?


Thank you in advance.
Dear Salesforce Professional

I am a beginner in Programming.
Please help me resolve this problem.

I have a requirement to create a child record (on Billing Line object) if parent records (on Billing object) exist I need to attach the child record (Billing Line) to the parent (Billing) but if Parent record doesn't exist I need to create parent and child records.

This trigger is supposed to fire when I check a checkbox on a TEST object.

For some reason, my code can't find parent records and can't create one.

I get this error message
"TriggerTestBillingLineCreate: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [AcctSeed__Customer__c]: [AcctSeed__Customer__c] Class.testBillingLineCreate.createBillingLine: line 48, column 1 Trigger.TriggerTestBillingLineCreate: line 5, column 1"

Basically, it is saying the required field is missing when I am trying to create a parent record. I don't understand why it is missing if I populate it there and in some cases why it needs to create a parent record if a parent exists in a database. It just needs to find it and link a child record to the parent.

I attached my code below. I appreciate any advice. Thank you for your help!


public class testBillingLineCreate {
    public static void createBillingLine (list<TEST__c> TestList, map<id, TEST__c> oldMap)
    {
     list<AcctSeed__Billing_Line__c> billingLineList=new List<AcctSeed__Billing_Line__c>();      
     list<AcctSeed__Billing__c> billingList= new list<AcctSeed__Billing__c>();
        
         for(TEST__c objtest:TestList)
        {
        if(objtest.Billed__c==true && oldMap.get(objtest.Id).Billed__c==false)

        {
          for(AcctSeed__Billing__c billings:[select id, name, AcctSeed__Customer__c, advAcctSeed__Matter__c from AcctSeed__Billing__c where AcctSeed__Status__c='Approved']){

          if(billings.AcctSeed__Customer__c==objtest.Account__c && billings.advAcctSeed__Matter__c==objtest.Matter__c){

            AcctSeed__Billing_Line__c bill=new AcctSeed__Billing_Line__c();
           bill.AcctSeed__Billing__c=billings.Id;
            bill.AcctSeed__Project__c=objtest.Project__c;
            bill.AcctSeed__Hours_Units__c=objtest.time__c;                  
            bill.AcctSeed__Rate__c=objtest.Rate__c; 

            billingLineList.add(bill);
        }




         else {
              AcctSeed__Billing__c billings2=new AcctSeed__Billing__c();
              billings2.AcctSeed__Customer__c= objtest.Account__c;
               billings2.advAcctSeed__Matter__c=objtest.matter__c;
            billings2.AcctSeed__Status__c='Approved';
             billings2.AcctSeed__Date__c=date.today();
             billingList.add(billings2);

               AcctSeed__Billing_Line__c bill1=new AcctSeed__Billing_Line__c();
           bill1.AcctSeed__Billing__c=billings2.Id;
            bill1.AcctSeed__Project__c=objtest.Project__c;
            bill1.AcctSeed__Hours_Units__c=objtest.time__c;                  
            bill1.AcctSeed__Rate__c=objtest.Rate__c; 

            billingLineList.add(bill1);

            }
    }

        }
        insert billingList;
        insert billingLineList;
        }}}
Hi I am new in Apex. Please help me resolve this problem.

I have a requirement to create a child record (on Billing Line object) if parent records (on Billing object) exist I need to attach the child record to the parent but if Parent record doesn't exist I need to create a parent and a child records. 

This trigger is supposed to fire when I check a checkbox on a TEST object. 

For some reason, my code can't find parent records and can't create one.   

public class testBillingLineCreate {
    public static void createBillingLine (list<TEST__c> TestList, map<id, TEST__c> oldMap)
    {
     list<AcctSeed__Billing_Line__c> billingLineList=new List<AcctSeed__Billing_Line__c>();      
     list<AcctSeed__Billing__c> billingList= new list<AcctSeed__Billing__c>();
        
           for(TEST__c objtest:TestList)
        {
        if(objtest.Billed__c==true && oldMap.get(objtest.Id).Billed__c==false)
            
        {
            for(AcctSeed__Billing__c billings:[select id, name, AcctSeed__Customer__r.id, advAcctSeed__Matter__r.id from AcctSeed__Billing__c where AcctSeed__Status__c='Approved']){
            
                if(billings.AcctSeed__Customer__r.id==objtest.Account__r.id && billings.advAcctSeed__Matter__r.id==objtest.Matter__r.id){
                
            AcctSeed__Billing_Line__c bill=new AcctSeed__Billing_Line__c();
           bill.AcctSeed__Billing__r.id=billings.Id;
            bill.AcctSeed__Project__c=objtest.Project__c;
            bill.AcctSeed__Hours_Units__c=objtest.time__c;                  
            bill.AcctSeed__Rate__c=objtest.Rate__c; 
          
            billingLineList.add(bill);
        }
            
        
        
        
         else {
              AcctSeed__Billing__c billings2=new AcctSeed__Billing__c();
              billings2.AcctSeed__Customer__c= objtest.Account__c;
               billings2.advAcctSeed__Matter__c=objtest.matter__c;
            billingList.add(billings2);
            
               AcctSeed__Billing_Line__c bill1=new AcctSeed__Billing_Line__c();
           bill1.AcctSeed__Billing__c=billings2.Id;
            bill1.AcctSeed__Project__c=objtest.Project__c;
            bill1.AcctSeed__Hours_Units__c=objtest.time__c;                  
            bill1.AcctSeed__Rate__c=objtest.Rate__c; 
          
            billingLineList.add(bill1);
            
            }
    }
           
        }
        insert billingList;
        insert billingLineList;
        }}}
I need to create a record on a BILLING object every time when a bill checked the box on another TEST object is checked. 

My problem is that there is a required field on the BILLING record called rate__c. 
The rate__c field has to be populated by a field from PROJECT which is a parent object of TEST.  (There is a lookup relationship between TEST and PROJECT. And lookup relationship between PROJECT and BILLING)

I wrote a code that works only when I prepopulated a rate__c field on the BILLING record. 

I also wrote a code that retrieves a rate field from project object, but for some reason, I get an error message that required field - rate__c is missing.  

 Please, help me to resolve this issue
  
public class testBillingLineCreate {
    public static void createBillingLine (list<TEST__c> TestList, map<id, TEST__c> oldMap)
    {
       list<AcctSeed__Billing_Line__c> billingLineList=new List<AcctSeed__Billing_Line__c>();      
     
       
        for(TEST__c objtest:TestList)
        {
        if(objtest.Billed__c==true && oldMap.get(objtest.Id).Billed__c==false)
            
        {
            AcctSeed__Billing_Line__c bill=new AcctSeed__Billing_Line__c();
            bill.AcctSeed__Billing__c=objtest.Billing__c;
            bill.AcctSeed__Project__c=objtest.Project__c;
            bill.AcctSeed__Hours_Units__c=objtest.time__c;                  
                      
  
            
            bill.AcctSeed__Rate__c= objtest.Project__r.Billing_Rate__c;
          
            billingLineList.add(bill);
        }
            
        }
        
        insert billingLineList;
    }
    }
I have a requirement to create a batch class for Tenant__c object for the Property management app. 
The condition is when our Tenant doesn't pay rent by the beginning of the month, we send him/her an email with a reminder.  

There is a field called "Status" on Tenant object if the status is not "Paid" then send email.

I wrote a batch class but I am not sure where do I put condition to send emails? In Execute or Finish?

Please Help!


global class TenantLatePaymentTask implements Database.Batchable<SObject> {
         global Database.QueryLocator start(Database.BatchableContext BC) {
            return Database.getQueryLocator([
        SELECT Name, Id, Email_Address__c,description__c from Tenant__c
        Where Status__c='Non-Active']); }

global void execute(Database.BatchableContext BC, List<Tenant__c> tenants) {

list<Tenant__c> TenList=new list<Tenant__c>();
   
    for (Tenant__c tenant : tenants) {
tenant.description__c='Last Payment is missing. Please Follow up with the Tenant';
TenList.add(tenant);          
        
}
    list<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();

    for (Tenant__c Ten :TenList ) {
    if (Ten.Email_Address__c != null && Ten.Status__c!='Paid') {
      
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();    
     
      List<String> sendTo = new List<String>();
      sendTo.add(Ten.Email_Address__c);
      mail.setToAddresses(sendTo);
    
     
      mail.setReplyTo('dreamhouse@gmail.com');
      mail.setSenderDisplayName('Dreamhouse real estate Co');
    
     
      List<String> ccTo = new List<String>();
      ccTo.add('business@bankofnigeria.com');
      mail.setCcAddresses(ccTo);

      
      mail.setSubject('Last Rent Payment is Missing');
      String body = 'Dear ' + Ten.First_Name__c + ', ';
      body += 'Please, submit your last rent payment';
      mail.setHtmlBody(body);
    
      
      mails.add(mail);
    }
  }
  
  Messaging.sendEmail(mails);
    if(TenList!=null && TenList.size()>0){
        database.update(TenList);
}
}global void finish(Database.BatchableContext BC) {
 
}

 
Hi
I have a requirement: My Salesforce org should send data to a web service whenever the status (field) of the tenant (object) changes from active to non-active.
The message that I post should contain the ID of the Tenant that not active anymore. I can't figure out how to add the ID of this tenant.

Please help me resolve this puzzle.


This is my code:
global class FOBCallouts1{
@Future (Callout=true)
public static void tenantUpdate(list<tenant__c> TenList, map <id,tenant__c> oldMap)
{ // list<tenant__c> TenList=new list<tenant__c>();
// map <id,tenant__c> oldMap=new map<id, tenant__c>(); for(tenant__c objten:TenList)
{ if(objten.status__c=='Non-active' && oldMap.get(objten.Id).status__c =='Active'){ Http http = new Http();
HttpRequest request = new HttpRequest(); request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');
request.setMethod('POST');
Tenant__c tenant=[SELECT Id FROM Tenant__c]; 
String JsonString=JSON.serialize(objten.id);
String body = 'Please deactivate FOB for following tenants(ID)'; request.setBody(body+JsonString); System.debug(request.getBody()); } } } }
 
I have a requirement to create a custom field called Average_Utility__c  on a parent object - Property__c that will show average sum of the child object records - Utility__c. 
  
I tried to create a trigger and a class that uses aggregate AVG function to fetch the records of amount_paid field from Utility__c.

But my problem is I don't know how to make it to recalculate Average_Utility__c  amount every time when new utility record is created. 

This is my code:         
public class AvgUtility {
public static void avgUtility (list<property__c> propList)   
        
        { 
      //   list <property__c> propList=new List<property__c>();
          
       
       
        list<property__c> PropertyList=[select id,name, Average_Utility__c from property__c]; 
                    
        for(property__c prop :PropertyList)
            
        {
            if (prop.Average_Utility__c==null || prop.Average_Utility__c!=null)
            { 
      AggregateResult[] groupedResults  = [SELECT Property__r.ID, AVG(Amount_Paid__c)  FROM Utility__c GROUP BY Property__r.ID];

         for (AggregateResult ar : groupedResults){
                prop.id =(id)ar.get ('Property__c');
                 prop.Average_Utility__c=(decimal)ar.get(('expr0'));
                propList.add(prop);
            }
         }            
         }
        insert propList;
        }
}


Trigger Class
trigger AvgUtilityTrigger on Utility__c (after insert) {
    
    for (Utility__c ut:trigger.new)
    {
        AvgUtility.avgUtility();
    }
        
   }

I will appreciate any advice!  
Is it possible to create a PDF Page that contains values from three related objects?

If it is, how would I do that? 

Thank you, in advance!
Dear Salesforce Professional

I am a beginner in Programming.
Please help me resolve this problem.

I have a requirement to create a child record (on Billing Line object) if parent records (on Billing object) exist I need to attach the child record (Billing Line) to the parent (Billing) but if Parent record doesn't exist I need to create parent and child records.

This trigger is supposed to fire when I check a checkbox on a TEST object.

For some reason, my code can't find parent records and can't create one.

I get this error message
"TriggerTestBillingLineCreate: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [AcctSeed__Customer__c]: [AcctSeed__Customer__c] Class.testBillingLineCreate.createBillingLine: line 48, column 1 Trigger.TriggerTestBillingLineCreate: line 5, column 1"

Basically, it is saying the required field is missing when I am trying to create a parent record. I don't understand why it is missing if I populate it there and in some cases why it needs to create a parent record if a parent exists in a database. It just needs to find it and link a child record to the parent.

I attached my code below. I appreciate any advice. Thank you for your help!


public class testBillingLineCreate {
    public static void createBillingLine (list<TEST__c> TestList, map<id, TEST__c> oldMap)
    {
     list<AcctSeed__Billing_Line__c> billingLineList=new List<AcctSeed__Billing_Line__c>();      
     list<AcctSeed__Billing__c> billingList= new list<AcctSeed__Billing__c>();
        
         for(TEST__c objtest:TestList)
        {
        if(objtest.Billed__c==true && oldMap.get(objtest.Id).Billed__c==false)

        {
          for(AcctSeed__Billing__c billings:[select id, name, AcctSeed__Customer__c, advAcctSeed__Matter__c from AcctSeed__Billing__c where AcctSeed__Status__c='Approved']){

          if(billings.AcctSeed__Customer__c==objtest.Account__c && billings.advAcctSeed__Matter__c==objtest.Matter__c){

            AcctSeed__Billing_Line__c bill=new AcctSeed__Billing_Line__c();
           bill.AcctSeed__Billing__c=billings.Id;
            bill.AcctSeed__Project__c=objtest.Project__c;
            bill.AcctSeed__Hours_Units__c=objtest.time__c;                  
            bill.AcctSeed__Rate__c=objtest.Rate__c; 

            billingLineList.add(bill);
        }




         else {
              AcctSeed__Billing__c billings2=new AcctSeed__Billing__c();
              billings2.AcctSeed__Customer__c= objtest.Account__c;
               billings2.advAcctSeed__Matter__c=objtest.matter__c;
            billings2.AcctSeed__Status__c='Approved';
             billings2.AcctSeed__Date__c=date.today();
             billingList.add(billings2);

               AcctSeed__Billing_Line__c bill1=new AcctSeed__Billing_Line__c();
           bill1.AcctSeed__Billing__c=billings2.Id;
            bill1.AcctSeed__Project__c=objtest.Project__c;
            bill1.AcctSeed__Hours_Units__c=objtest.time__c;                  
            bill1.AcctSeed__Rate__c=objtest.Rate__c; 

            billingLineList.add(bill1);

            }
    }

        }
        insert billingList;
        insert billingLineList;
        }}}
I need to create a record on a BILLING object every time when a bill checked the box on another TEST object is checked. 

My problem is that there is a required field on the BILLING record called rate__c. 
The rate__c field has to be populated by a field from PROJECT which is a parent object of TEST.  (There is a lookup relationship between TEST and PROJECT. And lookup relationship between PROJECT and BILLING)

I wrote a code that works only when I prepopulated a rate__c field on the BILLING record. 

I also wrote a code that retrieves a rate field from project object, but for some reason, I get an error message that required field - rate__c is missing.  

 Please, help me to resolve this issue
  
public class testBillingLineCreate {
    public static void createBillingLine (list<TEST__c> TestList, map<id, TEST__c> oldMap)
    {
       list<AcctSeed__Billing_Line__c> billingLineList=new List<AcctSeed__Billing_Line__c>();      
     
       
        for(TEST__c objtest:TestList)
        {
        if(objtest.Billed__c==true && oldMap.get(objtest.Id).Billed__c==false)
            
        {
            AcctSeed__Billing_Line__c bill=new AcctSeed__Billing_Line__c();
            bill.AcctSeed__Billing__c=objtest.Billing__c;
            bill.AcctSeed__Project__c=objtest.Project__c;
            bill.AcctSeed__Hours_Units__c=objtest.time__c;                  
                      
  
            
            bill.AcctSeed__Rate__c= objtest.Project__r.Billing_Rate__c;
          
            billingLineList.add(bill);
        }
            
        }
        
        insert billingLineList;
    }
    }
I have a requirement to create a batch class for Tenant__c object for the Property management app. 
The condition is when our Tenant doesn't pay rent by the beginning of the month, we send him/her an email with a reminder.  

There is a field called "Status" on Tenant object if the status is not "Paid" then send email.

I wrote a batch class but I am not sure where do I put condition to send emails? In Execute or Finish?

Please Help!


global class TenantLatePaymentTask implements Database.Batchable<SObject> {
         global Database.QueryLocator start(Database.BatchableContext BC) {
            return Database.getQueryLocator([
        SELECT Name, Id, Email_Address__c,description__c from Tenant__c
        Where Status__c='Non-Active']); }

global void execute(Database.BatchableContext BC, List<Tenant__c> tenants) {

list<Tenant__c> TenList=new list<Tenant__c>();
   
    for (Tenant__c tenant : tenants) {
tenant.description__c='Last Payment is missing. Please Follow up with the Tenant';
TenList.add(tenant);          
        
}
    list<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();

    for (Tenant__c Ten :TenList ) {
    if (Ten.Email_Address__c != null && Ten.Status__c!='Paid') {
      
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();    
     
      List<String> sendTo = new List<String>();
      sendTo.add(Ten.Email_Address__c);
      mail.setToAddresses(sendTo);
    
     
      mail.setReplyTo('dreamhouse@gmail.com');
      mail.setSenderDisplayName('Dreamhouse real estate Co');
    
     
      List<String> ccTo = new List<String>();
      ccTo.add('business@bankofnigeria.com');
      mail.setCcAddresses(ccTo);

      
      mail.setSubject('Last Rent Payment is Missing');
      String body = 'Dear ' + Ten.First_Name__c + ', ';
      body += 'Please, submit your last rent payment';
      mail.setHtmlBody(body);
    
      
      mails.add(mail);
    }
  }
  
  Messaging.sendEmail(mails);
    if(TenList!=null && TenList.size()>0){
        database.update(TenList);
}
}global void finish(Database.BatchableContext BC) {
 
}

 
I have a requirement to create a custom field called Average_Utility__c  on a parent object - Property__c that will show average sum of the child object records - Utility__c. 
  
I tried to create a trigger and a class that uses aggregate AVG function to fetch the records of amount_paid field from Utility__c.

But my problem is I don't know how to make it to recalculate Average_Utility__c  amount every time when new utility record is created. 

This is my code:         
public class AvgUtility {
public static void avgUtility (list<property__c> propList)   
        
        { 
      //   list <property__c> propList=new List<property__c>();
          
       
       
        list<property__c> PropertyList=[select id,name, Average_Utility__c from property__c]; 
                    
        for(property__c prop :PropertyList)
            
        {
            if (prop.Average_Utility__c==null || prop.Average_Utility__c!=null)
            { 
      AggregateResult[] groupedResults  = [SELECT Property__r.ID, AVG(Amount_Paid__c)  FROM Utility__c GROUP BY Property__r.ID];

         for (AggregateResult ar : groupedResults){
                prop.id =(id)ar.get ('Property__c');
                 prop.Average_Utility__c=(decimal)ar.get(('expr0'));
                propList.add(prop);
            }
         }            
         }
        insert propList;
        }
}


Trigger Class
trigger AvgUtilityTrigger on Utility__c (after insert) {
    
    for (Utility__c ut:trigger.new)
    {
        AvgUtility.avgUtility();
    }
        
   }

I will appreciate any advice!