• It just me!
  • NEWBIE
  • 15 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies

Hello.  I have this formula that works perfectly fine. Final_Bonus__c

 

IF( ((Lead_dollar_null__c = 0)||(Lead_dollar_null__c = NULL)),(Lead_commision__c*(( Object1__r.edits__c * age__c) - ( Object1__r.cost__c * bonus__c ) )) 
, Lead_dollar_null__c )

But I added 3 fields that are Pecent fields.  The goal is when I add a number on any or all of the fields that it adjust the calculation of Final_Bonus__c.  However I'm getting an error that I cant add a formula.  Error is "Formula cannot use another formula field that directly or indirectly refers to itself."

 

Any ideas on how I can resolve the this problem?

Thanks in advance

So my goal is to be able to have a primary record for one for my related object.  I'm currently getting an error.

Space__c is my main object
Lease__c is my related object

current_lease__c is the check box.

Here's my error: 
Error: Compile Error: Cannot save a trigger during a parse and save class call at line -1 column -1
trigger CurrentLease on Lease__c (Before Insert, Before Update, 
                                   After Insert, After Update, After Delete, After UnDelete) {

    Set <Id> filesId = new Set <Id> ();
    set <Id> objectsID = new Set <Id> ();

   for (Lease__c files : Trigger.new) {
       //Check if trigger.new Primary_file__c is TRUE
       System.debug('files.Current_Lease__c: '+files.Current_Lease__c);
       if (files.Current_Lease__c){
           //Add the Id to a list of ids
           filesId.add(files.Id);
           objectsID.add(files.Space__c);
       }     
   }
    System.debug('Object: ' + objectsID);
    //Query the ids from object where Primary_file__c is TRUE and is not new
    List <Lease__c> filesList = new List <Lease__c> (
        [select id, Current_Lease__c from Lease__c where Current_Lease__c = true and id not in :filesID and Space__c in :objectsID] );
    //System.debug('filesList: '+ filesList);
    System.debug('filesList.size(): ' + filesList.size());

    for (Lease__c files : Trigger.new) {
        if (filesList.size() > 0){
            files.Id.AddError('You cannot have more than one Current Lease');
        } 
    }
}

Any idea?

I have 2 custom Object.

A__c <- Main Object
B__c <- Related Object with many records.

Primaryrecord__c <- Checkbox in B__c object
Aname__c <- is the lookup in the A__c object to B__c. 

I'm current trying to create Primary Record that will produce and error when another primary record checkbox is selected.  I'm trying to copy the code below by replacing the objects and line commands but doesn't seem to work well.   Are there any Apex trigger that can help me with this?

this code is functioning well on my Accounts and Contacts object.  I just need it for 2 different objects

Code Below

Trigger PrimaryContact on Contact (Before Insert, Before Update, 
                                   After Insert, After Update, After Delete, After UnDelete) {
    
     List<Id> actIds = New List<Id>();
     List<Contact> comingCons = New List<Contact>();
     List<Id> conIds = New List<Id>();
     
     If(Trigger.IsBefore && (Trigger.IsInsert || Trigger.IsUpdate))
     {
         For(Contact Con : Trigger.New)
         {
             If(Con.Primary_Contact__c == TRUE)
             {
                actIds.add(Con.AccountId);
                conIds.add(Con.Id);
                comingCons.add(Con);
             }
             
         }
     }
     
     List<Account> allRelatedAccounts = [Select Id, (Select Id, Primary_Contact__c 
                                                     FROM Contacts WHERE Primary_Contact__c = TRUE AND Id !=: conIds)
                                                        FROM Account WHERE Id =: actIds];
     
     
     For(Contact EveryCon : comingCons)
     {
         For(Account EveryAccount : allRelatedAccounts){
             If(EveryCon.AccountId == EveryAccount.Id && EveryAccount.Contacts.size() > 0){
                 EveryCon.addError('There is already a primary contact for this account');
             }
         }
     }                                  
                                       
     
                                   
    List<Id> accountIds = New List<Id>();
    
    If(Trigger.IsInsert || Trigger.IsUpdate || Trigger.IsUnDelete){
        For(Contact Con : Trigger.New){
            If(Con.AccountId != NULL){
                accountIds.add(Con.AccountId);
            }
        }
    }
    If(Trigger.IsDelete){
        For(Contact Con : Trigger.Old){
            If(Con.AccountId != NULL){
                accountIds.add(Con.AccountId);
            }
        }
    }
    
    List<Account> actFinalListToUpdte = New List<Account>();
    
    
    For(Account act : [Select ID, Contact2__c,
                            (Select Id, FirstName, LastName,
                                    Primary_Contact__c FROM Contacts WHERE Primary_Contact__c = TRUE LIMIT 1)
                                FROM Account WHERE Id =: accountIds])
    {
        If(act.Contacts.size() > 0)
        {
            act.Contact2__c = act.Contacts[0].Id;
            actFinalListToUpdte.add(act);
        }
            
    }
    
    try{
        If(!actFinalListToUpdte.isEmpty()){
            update actFinalListToUpdte;
        }
    }Catch(Exception e){
        system.debug('Thrown Exception for PrimaryContact is: ' + e.getMessage());
    }
}
 

when I change things I get errors like...

- Error: Compile Error: Variable does not exist: AccountID at line 14 column 32
What should I change AccountID to?
- Didn't understand relationship 'B__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

Any guidance will help.  Thanks

 

Hi! Im trying resolve a search issue in opportunity to search records for a particular object custom object.  When I press the search I get this error.
User-added image

I looked at the APEX code and it looks fine using the FROM syntax.  
 
public void searchSpace2() {
        try {
            String spacesSearchQueryString = 'select Id, Name, Term_Months__c, Used__c, from Space2__c where RecordTypeId = :SpaceRecordType and {{condition}}';
            String spacesSearchCountQueryString = 'select count() from Space2__c where RecordTypeId = :SpaceRecordType and {{condition}}';
            String spacesSearchQueryConditionString = '';
            
            mapHoldingSelectedRecords.clear();
            
            if(spa.Term_Months__c != null) {
                spacesSearchQueryConditionString += 'Term_Months__c = ' + '\'' + spa.Term_Months__c + '\'' + ' and ';    
            }
            
            if(spa.Used__c != null) {
                spacesSearchQueryConditionString += 'Used__c = ' + '\'' + spa.Used__c + '\'' + ' and ';    
            }
            
            if(String.isBlank(spacesSearchQueryConditionString)) {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select the suitable filters to search for pSpaces.'));
                return;
            }
            
            spacesSearchQueryConditionString = spacesSearchQueryConditionString.removeEnd(' and ');
            spacesSearchQueryConditionString = spacesSearchQueryConditionString.trim();
            
            spacesSearchQueryString = spacesSearchQueryString.replace('{{condition}}', spacesSearchQueryConditionString + ' order by Name ASC limit ' + QUERY_LIMIT);
            spacesSearchCountQueryString = spacesSearchCountQueryString.replace('{{condition}}', spacesSearchQueryConditionString);
            
            System.debug('------------------- spacesSearchQueryString: ' + spacesSearchQueryString);
            
            setController = new ApexPages.StandardSetController(Database.getQueryLocator(spacesSearchQueryString));
            setController.setPageSize(PAGE_SIZE);
            noOfRecords = Database.countQuery(spacesSearchCountQueryString);
            totalPages = getTotalPages();
            
            populateWrapperList();
            
        } catch(Exception e) {
            System.debug('------------------- ERROR: ' + e.getStackTraceString());
            System.debug('------------------- ERROR MESSAGE: ' + e.getMessage());
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error while searching for pSpaces.' + e.getMessage()));
            return;
        }
    }

The recordType is "Space".  Thanks in advance.


 

I have 2 custom Object.

A__c <- Main Object
B__c <- Related Object with many records.

Primaryrecord__c <- Checkbox in B__c object
Aname__c <- is the lookup in the A__c object to B__c. 

I'm current trying to create Primary Record that will produce and error when another primary record checkbox is selected.  I'm trying to copy the code below by replacing the objects and line commands but doesn't seem to work well.   Are there any Apex trigger that can help me with this?

this code is functioning well on my Accounts and Contacts object.  I just need it for 2 different objects

Code Below

Trigger PrimaryContact on Contact (Before Insert, Before Update, 
                                   After Insert, After Update, After Delete, After UnDelete) {
    
     List<Id> actIds = New List<Id>();
     List<Contact> comingCons = New List<Contact>();
     List<Id> conIds = New List<Id>();
     
     If(Trigger.IsBefore && (Trigger.IsInsert || Trigger.IsUpdate))
     {
         For(Contact Con : Trigger.New)
         {
             If(Con.Primary_Contact__c == TRUE)
             {
                actIds.add(Con.AccountId);
                conIds.add(Con.Id);
                comingCons.add(Con);
             }
             
         }
     }
     
     List<Account> allRelatedAccounts = [Select Id, (Select Id, Primary_Contact__c 
                                                     FROM Contacts WHERE Primary_Contact__c = TRUE AND Id !=: conIds)
                                                        FROM Account WHERE Id =: actIds];
     
     
     For(Contact EveryCon : comingCons)
     {
         For(Account EveryAccount : allRelatedAccounts){
             If(EveryCon.AccountId == EveryAccount.Id && EveryAccount.Contacts.size() > 0){
                 EveryCon.addError('There is already a primary contact for this account');
             }
         }
     }                                  
                                       
     
                                   
    List<Id> accountIds = New List<Id>();
    
    If(Trigger.IsInsert || Trigger.IsUpdate || Trigger.IsUnDelete){
        For(Contact Con : Trigger.New){
            If(Con.AccountId != NULL){
                accountIds.add(Con.AccountId);
            }
        }
    }
    If(Trigger.IsDelete){
        For(Contact Con : Trigger.Old){
            If(Con.AccountId != NULL){
                accountIds.add(Con.AccountId);
            }
        }
    }
    
    List<Account> actFinalListToUpdte = New List<Account>();
    
    
    For(Account act : [Select ID, Contact2__c,
                            (Select Id, FirstName, LastName,
                                    Primary_Contact__c FROM Contacts WHERE Primary_Contact__c = TRUE LIMIT 1)
                                FROM Account WHERE Id =: accountIds])
    {
        If(act.Contacts.size() > 0)
        {
            act.Contact2__c = act.Contacts[0].Id;
            actFinalListToUpdte.add(act);
        }
            
    }
    
    try{
        If(!actFinalListToUpdte.isEmpty()){
            update actFinalListToUpdte;
        }
    }Catch(Exception e){
        system.debug('Thrown Exception for PrimaryContact is: ' + e.getMessage());
    }
}
 

when I change things I get errors like...

- Error: Compile Error: Variable does not exist: AccountID at line 14 column 32
What should I change AccountID to?
- Didn't understand relationship 'B__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name.

Any guidance will help.  Thanks

 

Hi! Im trying resolve a search issue in opportunity to search records for a particular object custom object.  When I press the search I get this error.
User-added image

I looked at the APEX code and it looks fine using the FROM syntax.  
 
public void searchSpace2() {
        try {
            String spacesSearchQueryString = 'select Id, Name, Term_Months__c, Used__c, from Space2__c where RecordTypeId = :SpaceRecordType and {{condition}}';
            String spacesSearchCountQueryString = 'select count() from Space2__c where RecordTypeId = :SpaceRecordType and {{condition}}';
            String spacesSearchQueryConditionString = '';
            
            mapHoldingSelectedRecords.clear();
            
            if(spa.Term_Months__c != null) {
                spacesSearchQueryConditionString += 'Term_Months__c = ' + '\'' + spa.Term_Months__c + '\'' + ' and ';    
            }
            
            if(spa.Used__c != null) {
                spacesSearchQueryConditionString += 'Used__c = ' + '\'' + spa.Used__c + '\'' + ' and ';    
            }
            
            if(String.isBlank(spacesSearchQueryConditionString)) {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select the suitable filters to search for pSpaces.'));
                return;
            }
            
            spacesSearchQueryConditionString = spacesSearchQueryConditionString.removeEnd(' and ');
            spacesSearchQueryConditionString = spacesSearchQueryConditionString.trim();
            
            spacesSearchQueryString = spacesSearchQueryString.replace('{{condition}}', spacesSearchQueryConditionString + ' order by Name ASC limit ' + QUERY_LIMIT);
            spacesSearchCountQueryString = spacesSearchCountQueryString.replace('{{condition}}', spacesSearchQueryConditionString);
            
            System.debug('------------------- spacesSearchQueryString: ' + spacesSearchQueryString);
            
            setController = new ApexPages.StandardSetController(Database.getQueryLocator(spacesSearchQueryString));
            setController.setPageSize(PAGE_SIZE);
            noOfRecords = Database.countQuery(spacesSearchCountQueryString);
            totalPages = getTotalPages();
            
            populateWrapperList();
            
        } catch(Exception e) {
            System.debug('------------------- ERROR: ' + e.getStackTraceString());
            System.debug('------------------- ERROR MESSAGE: ' + e.getMessage());
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error while searching for pSpaces.' + e.getMessage()));
            return;
        }
    }

The recordType is "Space".  Thanks in advance.


 
Suppose i have to build follwoing scenario

Two objects A & B have a master detail relationship, A being the master and B can contain many number of records

But only one record in B can be primary to A, say a Primary Flag field exist on B

When i check the Primary Flag of any new record in B, then the primary flag on old record should disappear