• Gururaj B
  • NEWBIE
  • 240 Points
  • Member since 2017
  • Accenture

  • Chatter
    Feed
  • 8
    Best Answers
  • 0
    Likes Received
  • 2
    Likes Given
  • 1
    Questions
  • 59
    Replies
Continuously getting a "Syntax Error" on this formula in Process Builder.  Not currently hitting any limits that I can see.  Formula editor states I'm missing an '=', but can't find where that would be.  Have a very similar formula that works.  

Bad formula:

  OR(
   AND([Contact].MailingState = 'ME'), 
   AND([Contact].MailingState = 'Maine'),
   AND([Contact].MailingState = 'IA'),
   AND([Contact].MailingState = 'Iowa'),
   AND([Contact].MailingState = 'IL'),
   AND([Contact].MailingState = 'Illinois'),
   AND([Contact].MailingState = 'MN'),
   AND([Contact].MailingState = 'Minnesota'),
   AND([Contact].MailingPostalCode = '55334'),
   AND([Contact].MailingPostalCode = '55352'),
   AND([Contact].MailingPostalCode = '55354'),
   AND([Contact].MailingPostalCode = '55704'),
   AND([Contact].MailingPostalCode = '55712'),
   AND([Contact].MailingPostalCode = '55749'),
   AND([Contact].MailingPostalCode = '55756'),
   AND([Contact].MailingPostalCode = '56055'),
   AND([Contact].MailingPostalCode = '56074'),
   AND([Contact].MailingPostalCode = '56082'),
   AND([Contact].MailingPostalCode = '56363'),
   AND(VALUE([Contact].MailingPostalCode) >= 55001,VALUE([Contact].MailingPostalCode) <= 55036),
   AND(VALUE([Contact].MailingPostalCode) >= 55038,VALUE([Contact].MailingPostalCode) <= 55309),
   AND(VALUE([Contact].MailingPostalCode) >= 55311,VALUE([Contact].MailingPostalCode) <= 55313),
   AND(VALUE([Contact].MailingPostalCode) >= 55315,VALUE([Contact].MailingPostalCode) <= 55323),
   AND(VALUE([Contact].MailingPostalCode) >= 55325,VALUE([Contact].MailingPostalCode) <= 55328),
   AND(VALUE([Contact].MailingPostalCode) >= 55330,VALUE([Contact].MailingPostalCode) <= 55331),
   AND(VALUE([Contact].MailingPostalCode) >= 55336,VALUE([Contact].MailingPostalCode) <= 55341),
   AND(VALUE([Contact].MailingPostalCode) >= 55343,VALUE([Contact].MailingPostalCode) <= 55349),
   AND(VALUE([Contact].MailingPostalCode) >= 55356,VALUE([Contact].MailingPostalCode) <= 55384),
   AND(VALUE([Contact].MailingPostalCode) >= 55386,VALUE([Contact].MailingPostalCode) <= 55388),
   AND(VALUE([Contact].MailingPostalCode) >= 55390,VALUE([Contact].MailingPostalCode) <= 55599),
   AND(VALUE([Contact].MailingPostalCode) >= 55901,VALUE([Contact].MailingPostalCode) <= 56017),
   AND(VALUE([Contact].MailingPostalCode) >= 56020,VALUE([Contact].MailingPostalCode) <= 56021),
   AND(VALUE([Contact].MailingPostalCode) >= 56023,VALUE([Contact].MailingPostalCode) <= 56029),
   AND(VALUE([Contact].MailingPostalCode) >= 56032,VALUE([Contact].MailingPostalCode) <= 56039),
   AND(VALUE([Contact].MailingPostalCode) >= 56042,VALUE([Contact].MailingPostalCode) <= 56052),
   AND(VALUE([Contact].MailingPostalCode) >= 56057,VALUE([Contact].MailingPostalCode) <= 56058),
   AND(VALUE([Contact].MailingPostalCode) >= 56063,VALUE([Contact].MailingPostalCode) <= 56072),
   AND(VALUE([Contact].MailingPostalCode) >= 56078,VALUE([Contact].MailingPostalCode) <= 56080),
   AND(VALUE([Contact].MailingPostalCode) >= 56089,VALUE([Contact].MailingPostalCode) <= 56098)
​  )

Good Formula:

  OR(
   AND([Contact].MailingState = 'ND'), 
   AND([Contact].MailingState = 'North Dakota'),
   AND([Contact].MailingState = 'UT'),
   AND([Contact].MailingState = 'Utah'),
   AND([Contact].MailingState = 'CO'),
   AND([Contact].MailingState = 'Colorado'),
   AND([Contact].MailingState = 'MN'),
   AND([Contact].MailingState = 'Minnesota'),
   AND([Contact].MailingPostalCode = '55037'),
   AND([Contact].MailingPostalCode = '55310'),
   AND([Contact].MailingPostalCode = '55314'),
   AND([Contact].MailingPostalCode = '55324'),
   AND([Contact].MailingPostalCode = '55329'),
   AND([Contact].MailingPostalCode = '55335'),
   AND([Contact].MailingPostalCode = '55342'),
   AND([Contact].MailingPostalCode = '55350'),
   AND([Contact].MailingPostalCode = '55353'),
   AND([Contact].MailingPostalCode = '55355'),
   AND([Contact].MailingPostalCode = '55385'),
   AND([Contact].MailingPostalCode = '55389'),
   AND([Contact].MailingPostalCode = '56019'),
   AND([Contact].MailingPostalCode = '56022'),
   AND([Contact].MailingPostalCode = '56041'),
   AND([Contact].MailingPostalCode = '56054'),
   AND([Contact].MailingPostalCode = '56056'),
   AND([Contact].MailingPostalCode = '56060'),
   AND([Contact].MailingPostalCode = '56062'),
   AND([Contact].MailingPostalCode = '56073'),
   AND([Contact].MailingPostalCode = '56075'),
   AND([Contact].MailingPostalCode = '56081'),
   AND(VALUE([Contact].MailingPostalCode) >= 55332,VALUE([Contact].MailingPostalCode) <= 55333),
   AND(VALUE([Contact].MailingPostalCode) >= 55601,VALUE([Contact].MailingPostalCode) <= 55703),
   AND(VALUE([Contact].MailingPostalCode) >= 55705,VALUE([Contact].MailingPostalCode) <= 55711),
   AND(VALUE([Contact].MailingPostalCode) >= 55713,VALUE([Contact].MailingPostalCode) <= 55748),
   AND(VALUE([Contact].MailingPostalCode) >= 55750,VALUE([Contact].MailingPostalCode) <= 55753),
   AND(VALUE([Contact].MailingPostalCode) >= 55757,VALUE([Contact].MailingPostalCode) <= 55816),
   AND(VALUE([Contact].MailingPostalCode) >= 56083,VALUE([Contact].MailingPostalCode) <= 56088),
   AND(VALUE([Contact].MailingPostalCode) >= 56101,VALUE([Contact].MailingPostalCode) <= 56362),
   AND(VALUE([Contact].MailingPostalCode) >= 56364,VALUE([Contact].MailingPostalCode) <= 58207)
  )
 
Hello i got a related list on my console using visualforce my question is how can i hide other columns 
User-added image
as you can see i was able to hide the button and the action column now im trying to hide other 3 so only IDCM is visible 
 
Hello, 
So i have a user interface that has a month picklist and a year picklist.  Each one is hardcoded with months and years and each one has an Id.  There are only 4 years in the years picklist and all 12 months in the month picklist.  My questions is, can these be validated for example, make sure that the end date and no greater than one year after the start date.  I have been trying to figure out a way to do this for over a day now and just cant seem to figure out any logic for this.  If anyone could please let me know if this is even possible i would greatly appreciate it.  Thank you.  This is using a custom apex page, and angular2 font end.
I have writted the following trigger along with the test below. I'm unable to figure out how to cover the for loop in my test class. Looking forward to your advise.
 
List<Account> accountUpdatedList = new List<Account>();
    Map<string,string> territoryWithParentTerritoryNameMap = new map<string,string>();
    for(Territory2 tr : [SELECT id, Name,Territory2.ParentTerritory2.Name FROM Territory2 WHERE Territory2.ParentTerritory2.Name != Null Limit 50000])
    {
        territoryWithParentTerritoryNameMap.put(tr.name,tr.ParentTerritory2.Name);
    }
        
    for (Account ac : Trigger.new) {
        ac.Sales_Rep_Region__c = ' ';
        Integer counter = 0;
        if (ac.Territories__c != null) {
            for (String t : ac.Territories__c.split(',')) {
                counter += 1;
            }
            ac.Team_count__c = counter - 3;
        }
    
    if(ac.Territories__c != Null && ac.Territory_Has_Changed__c != False) 
        {
            for(string str : ac.Territories__c.split(',')){
                if(str != '104B' && str != '109B' && str != '109A' && str != ac.RVP_Code__c && str != '104A'){ 
                    if(territoryWithParentTerritoryNameMap.containsKey(str)){
                    
                        string tempParentTerritoryName = territoryWithParentTerritoryNameMap.get(str);
                        if(ac.RVP_Code__c != tempParentTerritoryName){                                
                            if(!ac.Sales_Rep_Region__c.contains(str)){                                    
                                ac.Sales_Rep_Region__c += str + ',';
                                accountUpdatedList.add(ac);   
                                    
                            }
                            
                        }
                       
                    }
                    
                }
              
            }
        }
        
    }

Test:
@istest
private class AccountTerritoryCount_test {
    static testMethod void TestAccount(){
        Account acc = new Account(name='test', 
                              jde_account_number__c='1234',
                              Territories__c='1234,1234,1234,1234,1234,1224,1234,1234,1234,');
    	insert acc;
        
    }
    
    static testMethod void myAccountTest()
    {
        List<Account> accountUpdatedList = new List<Account>();
        Map<string,string> territoryWithParentTerritoryNameMap = new map<string,string>();
    	for(Territory2 tr : [SELECT id, Name,Territory2.ParentTerritory2.Name FROM Territory2 
                         WHERE Territory2.ParentTerritory2.Name != '109N' Limit 50000])
        {
        	territoryWithParentTerritoryNameMap.put(tr.name,tr.ParentTerritory2.Name);
        }
        
        Account ac = new Account();
        ac.name = 'Toronto';
        ac.JDE_Account_Number__c = '12345678';
        ac.Territories__c = '1011,1436';
        ac.RVP_Code__c = '109N';
        insert ac;
        
        Account ac2 = new Account();
        ac2.name = 'Toronto2';
        ac2.JDE_Account_Number__c = '12345679';
        ac2.Territories__c = '1011,1436';
        ac2.RVP_Code__c = '109N';
        insert ac2;
        
        ac = [SELECT Sales_Rep_Region__c,Territories__c from Account where Id =:ac.Id];
        
        system.assertEquals(ac.Sales_Rep_Region__c, null);
        
    }
    
}
Lines 
User-added image
Hi,

I've created this Visual Flow to delete records one at a time to prevent it from reaching the governor limits.

Visual Flow to delete records one at a time.

This Flow works fine with less then 50000 records. When I tried to use it with an object that has 700K+ records, the first element (Fast Lookup) reaches the governor limits right away.

How do I fix this?

Thanks in Advance!
I have to send Email Alerts to users where no Account Activity greater than 15 days. I have a Field of No activity since which calculates it. It gives the count which I have made based on formula. Now my requirement is I need to send Email Alerts to salesperson where No activity since greater than 15. My logic is i have  created a text field Named Activitystatus field and created a work flow rule based on that text field named Activitystatus  . In the rule I have given criteria that  when Activitystatus equals NoActivity, send an Email Alert to Users.Now, Using the trigger i want to make the Activity status as No Activity for those accounts  where No activity since greater than 15. When Activity status Equals NoActivity the Workflow Rule will fire Automatically.

I have  used this Logic but its not Working.

trigger NoActivityAccount on Account(before insert) {
    
    List<Account>  objvrList  =[select Id,Activity_status__c from Account where No_Activity_since__c > 15];
    boolean flagetoUpdate = false ; 
    for(Account ac :trigger.new){
        if(ac.name != null)
        {
           flagetoUpdate = true ;   
        }
        
    }
    
    if(flagetoUpdate){
        for(Account acc : objvrList) {
            acc.Activity_status__c ='No Activity' ; 
        }
        update objvrList ;
    }
    
}
 
  • January 23, 2018
  • Like
  • 0
Hello All,

I have 3 custom objects namely Parent__c, Child__c, GrandChild__c, I can get the id of the parent from visualforce page. I want to display the grand child records in the visualforce page. I appreciate if anyone could help me with this.

Thank you
Hi guys,

I'll give you a little background information of what I am trying to achieve and maybe some experienced developers here could help to explain the error of my ways.

Aim of the future class
I have a 'Contract' object and a 'Contract Participant' object that is related to the contract. 
When a field called 'Contract_To__c' (The contract end date) is changed on the contract, the future class is called by a trigger and then the contract participant end date on the contract participant is updated automatically to the same value to reflect the change if the contract end date was originally the same as the contract participant end date

What I am doing
I have a test class set up with test data. And then within the Test.StartTest() and StopTest() methods, I call the future method, passing in the parameter values after updating the contract end date. After the stopTest() method, I am logging the participant end date to see if the future class has updated this to reflect the contract end date. This does not happen.

Below is the code for my test class and the class for my future method.

Test class:
@isTest
public class TestClassZee {

    public static testMethod void test_ContractParticipant(){
        
       Date sys_lastYearStart = Date.newInstance(Date.Today().Year()-1,1,1);
       Date sys_nextYearEnd = Date.newInstance(Date.Today().Year()+1,12,31);
        
         //Dynamically obtain the first value from the global division picklist
           Schema.DescribeFieldResult fieldResult = Portfolio__c.Team__c.getDescribe();
           List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
           String firstValue = ple[0].getLabel(); 
        
        //Insert a workstream
        List<Portfolio__c> wsToInsert = UtilityClass.getWorkstreams(1, 'Agreement', firstValue);
        insert wsToInsert;
        
        //Insert a supplier
        List<Account> supplierToInsert = UtilityClass.getSuppliers(2);
        insert supplierToInsert;
        
        //Create a contract
        List<HTE_Contract__c> conToInsert = UtilityClass.getContracts(2, 'valid', supplierToInsert[0].Id, wsToInsert[0].Id);
        insert conToInsert;
        
        //Create an opportunity
        List<Opportunity> oppToInsert = UtilityClass.getOpportunities(2, supplierToInsert[0].Id, wsToInsert[0].Id,    'Discussion Required');
        insert oppToInsert;
        
        //Create a contract participant
        List<Contract_Participant__c> cpToInsert = UtilityClass.getParticipants(1, conToInsert[0].Id, supplierToInsert[0].Id, oppToInsert[0].Id, sys_lastYearStart, sys_nextYearEnd);
        insert cpToInsert;

        /*System.debug(LoggingLevel.INFO, 'Checking workstream id ' + wsToInsert[0].Id);
        System.debug(LoggingLevel.INFO, 'Checking account id ' + supplierToInsert[0].Id);
        System.debug(LoggingLevel.INFO, 'Checking opp id ' + oppToInsert[0].Id);
        System.debug(LoggingLevel.INFO, 'Checking contract id ' + conToInsert[0].Id);
        System.debug(LoggingLevel.INFO, 'Checking contract participant id ' + cpToInsert[0].Id);*/
        
        Test.startTest();
        //Change the to date
        Date oldDate = conToInsert[0].Contract_To__c;
        
        conToInsert[0].Contract_To__c = Date.valueof('2020-01-01');
        conToInsert[0].Latest_Modification__c = 'Changing contract To date';
        update conToInsert;
        
        Date newDate = conToInsert[0].Contract_To__c;
        
        System.assertEquals(Date.valueof('2020-01-01'), conToInsert[0].Contract_To__c);
        
        //Call the future class
        FutureCPDateUpdate.updateParticipantEndDates(conToInsert[0].Id, oldDate, newDate);
        
        Test.stopTest();
        
        System.debug(LoggingLevel.INFO, 'Logging cp end date ' + cpToInsert[0].Participant_To__c);
        
    }
}

Future Method/Class
public class FutureCPDateUpdate {
    
	@future(callout = true)
	public static void updateParticipantEndDates(Id contractId, Date oldDate, Date newDate) {

		List<Contract_Participant__c> cp = [SELECT Id, Participant_To__c, Participant_From__c FROM Contract_Participant__c WHERE HTE_Contract__c =:contractId ];
		
        for(Contract_Participant__c cp2 : cp) {
            if(cp2.Participant_To__c == oldDate) {
                cp2.Participant_To__c = newDate;     
            }
        }
        
        update cp;
	}
    
}
When I make this change myself without running the code, I have a trigger which calls the future method and it updates the participant end dates just fine. In the future method, it performs a SOQL query for a Contract Participant record. Could it be because It cannot query for test data? I don't see a way around this. I appreciate that I am new to this.

Sorry if this was too much information or if anything was not clearly explained, I am more than happy to explain things further.

Thank you for your time. 
What is the best managed package for Amazon S3 connector?
When I am trying to insert records to Salesforce using ARC(OAuth2) getting below error Error: This session could not be mutually authenticated for use with the REST API
{
"message": "This session could not be mutually authenticated for use with the REST API",
"errorCode": "MUTUAL_AUTHENTICATION_FAILED"
}

403 Forbidden

But this working fine before. I getting this error suddenly.

Can anyone help me with this?

Thanks in advance
However, I keep getting errors.
I am just trying to create a custom button that opens up a task window. Then the person fills things in and then clicks "save" and the task is created.
Here's what I have as Javascript...

{!REQUIRESCRIPT("/soap/ajax/41.0/connection.js")}

  var taskToCreate            = new sforce.SObject("Task");

   taskToCreate.OwnerId        = "{!$User.Id}";
   taskToCreate.Division__c    = "{!User.Division}";
   taskToCreate.Task_Type__c   = "Community Appointment from NHS";
   taskToCreate.Subject        = "Community Appointment from NHS";
   taskToCreate.WhoId          = "{!Lead.Id}";
   taskToCreate.Priority       = "Normal";
   taskToCreate.Status         = "Not Started";

  result = sforce.connection.create( [ taskToCreate ] );

   result[0].success == ("true"){ location.reload()};

Im just learning Javascript so I apologize for missing the obvious thing casuing me to get erros.
Thanks
Shawn
How can I mass move phone numbers from the work phone field to the mobile phone field on a contact?
Good day all,

I am trying to create a class and a trigger that will return the road miles between the Facility associated with the Account and the account.  Unfortunately, it is not working.  Any ideas on what I am doing wrong?

Class:
public class GeoCodeRoadMiles {
    public void RoadMiles(List<Account> Id) {
geopointe.API.DistanceService ds = new geopointe.API.DistanceService();
List<Account> accList = [SELECT id, distance__c, geopointe__Geocode__r.geopointe__Latitude__c, geopointe__Geocode__r.geopointe__Longitude__c FROM Account LIMIT 1];
List<Account> origins = [SELECT id, Facility__c  FROM Account];
List<Account> destinations = new List<Account>();

// Split up data into origins and destinations
    for(Integer i = 0; i < accList.size(); i++){
   if(Math.mod(i, 2) == 0){
       origins.add(accList.get(i));
   }else{
       destinations.add(accList.get(i));
   }
    }

// Add the latitude and longitudes for the origin destination pairs
for(Integer i = 0; i < origins.size(); i++){
    ds.add((Double)origins.get(i).geopointe__Geocode__r.geopointe__Latitude__c,
        (Double)origins.get(i).geopointe__Geocode__r.geopointe__Longitude__c,
        (Double)destinations.get(i).geopointe__Geocode__r.geopointe__Latitude__c,
        (Double)destinations.get(i).geopointe__Geocode__r.geopointe__Longitude__c);
}

// Get the distance results and update desired fields
for(Integer i = 0; i < origins.size(); i++){
    Double distance = ds.getDistanceAtIndex(i);
    String.valueof(origins.get(i).distance__c = distance);
    String.valueof(destinations.get(i).distance__c = distance);
}
update accList;
    }}

Trigger:
trigger RoadMiles on Account (after insert, after update, before insert, before update) {
    if(Trigger.isAfter){
        if(Trigger.isInsert){
        	GeoCodeRoadMiles RoadMiles = new GeoCodeRoadMiles();
        	RoadMiles.RoadMiles(Trigger.new);
    	}
    }
    if(System.IsBatch()  == false && System.isFuture()  == false){
        if(Trigger.isAfter){
            if(Trigger.isUpdate){
                GeoCodeRoadMiles RoadMiles = new GeoCodeRoadMiles();
                RoadMiles.RoadMiles(Trigger.new);
            }
        }
    }
}

Hello Community,

I've tried to not bother you awesome folks and solve it myself first (with Google's help). But even Google can't get me out of the issue where I'm stuck at. Could you shine some light and help me out? I hope this thread will also help others who work on a similar project. Thanks in advance, and below is the story.

I wrote a trigger for tagging Primary Contacts in each account. The desired final result should look like:
  1. It limits 2 primary contacts per account just for now. I also can adjust the limit later if the management changes their mind.
  2. I can run a report to list the accounts that have 0 primary contacts. So sales team can stay on top of the data maintenance based on that report. Currently, I wrote this feature by updating a customized field (in Account) after one or two contact(s) get tagged as the primary contact.
Here's the code:
trigger primaryContact on Contact (after insert, after update) {
      Set<Id> accountIds = new Set<Id>();
      List<Account> updatedAccounts = new List<Account>();
      for (Contact c : Trigger.new) {
        accountIds.add(c.AccountId);
      }
      Map<Id,Account> accountMap = new Map<Id,Account>([Select Id, Primary_Contact__c, (Select Id, Name from Contacts where IsPrimary__c = true) from Account where Id in :accountIds]);
      for (Contact c : Trigger.new) {
        if (c.IsPrimary__c && accountMap.get(c.AccountId) != null) {
            Account updAccount = accountMap.get(c.AccountId);
            updAccount.Primary_Contact__c = c.id;
            if (updAccount.Contacts != null && updAccount.Contacts.size()>2) {
              c.IsPrimary__c.addError(' ¯`_(ツ)_/¯  Sorry... maximum 2 Primary Contacts allowed per Account.');
            }
            
            updatedAccounts.add(updAccount);
        } 
      }
      
      update updatedAccounts;
}

The trigger works perfectly with the dummy data in my developer account. And all features work as intend. However, when I moved to the sandbox and get it ready for the production, the developer console threw some errors after the "Run All" test (screenshot below). And the Overall Code Coverage is only 61% - need at least 75% to push it to production.

color-coded error area in Developer Console

Another screenshot of those errors in details.
It seems that the new trigger doesn't play well with existing plugins.

Please help. Many thanks again!
Hello Friends, 
I have 3 Classes in attached Image

a) abc()  Normal,
b) Efg() is with sharing
c) xyz() is without sharing


What happened if we are calling other class methods in any class, will all methods run in the calling class mode or it will run accordingly to it’s own class behavior.


User-added image
Hello All,

User-added image
I want to query a custom field from a custom object from Opportunity. there is no direct connection between opportunity and custom object however Custom object is connected with Account. Can someone please help me how to query to get the value of custom field from Opportuniy.

Thanks.
Is it possible to populate a custom text field (polgid__c) on an opportunity  with a child record (PO_Log__r with a trigger? 

 
  • May 17, 2018
  • Like
  • 0
Hi Friends. I have created a lookup on Account with contact to know which contact is Associated with which Accounts. Now the requirement is when I change the contact record for a particular Account from the Lookup, the Account field values should be updated with new Record values from contact as there is same fields on account and contact such as Name,Email, Phone;etc

Waiting for your help, Thanks in advance
  • May 17, 2018
  • Like
  • 0

An internal server error has occurred
An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience. 

Thank you again for your patience and assistance. And thanks for using salesforce.com! 

Error ID: 418513770-63407 (1054729069)

0down votefavorite
I have 2 custom objects we will call ObjectOne__c and ObjectTwo__c, these 2 objects DO NOT have a direct relationship to each other. However, I have a business need that requires fields on ObjectTwo__c to be updated to match the fields on ObjectOne__c when ObjectOne__c is updated. Here is a sample of the Trigger that handles this process. My issues is I need to move the SOQL out of the loop to properly handle mass updates, but I can’t figure out how to do that and still get the trigger to properly update all the records in the trigger.
Here is a sample of the code in my trigger:
trigger COSyncTrigger on ObjectOne__c (after update) { 
//Create list to store the ObjectTwo__c records that will be Updated 
List < ObjectTwo__c> upObTwo = new List < ObjectTwo__c >(); 

//Look at records being Updated 
if(trigger.isUpdate){ for(ObjectOne__c ObjOne : trigger.new){ 

//Create a list of existing ObjectTwo__c records that match the ObjectOne__c record being updated 
List < ObjectTwo__c > checkupObjTwo = [Select Id from ObjectTwo__c Where (Account__c = :ObjOne.Account__c And Owner = : ObjOne.Owner And Client__c = : ObjOne. Client__c) ]; 

//If the Above List is NOT Empty Update the ObjectTwo__c records 
If(!checkupObjTwo.isEmpty()) { 

ObjectTwo__c upobjtwo = [Select Id from ObjectTwo__c Where (Account__c = : ObjOne.Account__c And Owner = : ObjOne.Owner And Client__c = : ObjOne. Client__c)]; 

upobjtwo.Client_Role__c = ObjOne. Client_Role__c; 
upobjtwo.Client_Status__c = ObjOne. Client_Status__c; 

//Add the ATM record to the list to be updated later 
upObTwo.add(upobjtwo); } 
} 

//If the List of records to update is NOT Empty update the ObjectTwo__c records 
if(upObTwo.size() > 0){ 
system.debug('Count of ObjectTwo__c records to update = '+ upObTwo.size()); 

update upObTwo; } 
}
I have done some research and understand I need to create a list outside my loop but I can't seem to get it to update ObjectTwo__c records to Match the ObjectOne__c records in the trigger. Please explain how I can accomplish this and provide an example if possible. Thank you in advance.
Hi All,

I am having some trouble getting this code snippet to work. I am relatively new to Apex and DML/SOQL so it could be something simple. My goal is, given a list of accounts, determine the number of contacts belonging to each account, and then update a field called Number_of_Contacts__c with that value. Here's what I came up with:
public class AccountProcessor {

    public static void countContacts(List<ID> recordIds){  //take a list of recordids
        
        List<Account> accountlist = 
        [Select name FROM Account WHERE ID IN :recordIDs];  //get a list of the corresponding accounts
        
        for(Account tempaccount: accountlist){  //for each account in this list...
            
            Integer contactCount = 0;
            contactCount = 
            [SELECT Count() from CONTACT WHERE contact.account.ID = :tempaccount.ID];
            //count the number of contacts associate with each account

            tempaccount.number_of_contacts__c = contactCount;
            update tempaccount;
            
        }
    }
}
I am trying to run this code using the following anonymous execution:
AccountProcessor.countContacts(001f400000KfIMbAAN);
I'm not sure if the AccountID should be in quotes are not, but it doesn't work either way. I keep getting the following error:

Line: 1, Column 31 Unexpected token '('.

Any ideas where I'm going wrong? Also, I know my code is violating several "Best Practices" but I'm just trying to figure things out at the moment. Thanks!





 
Continuously getting a "Syntax Error" on this formula in Process Builder.  Not currently hitting any limits that I can see.  Formula editor states I'm missing an '=', but can't find where that would be.  Have a very similar formula that works.  

Bad formula:

  OR(
   AND([Contact].MailingState = 'ME'), 
   AND([Contact].MailingState = 'Maine'),
   AND([Contact].MailingState = 'IA'),
   AND([Contact].MailingState = 'Iowa'),
   AND([Contact].MailingState = 'IL'),
   AND([Contact].MailingState = 'Illinois'),
   AND([Contact].MailingState = 'MN'),
   AND([Contact].MailingState = 'Minnesota'),
   AND([Contact].MailingPostalCode = '55334'),
   AND([Contact].MailingPostalCode = '55352'),
   AND([Contact].MailingPostalCode = '55354'),
   AND([Contact].MailingPostalCode = '55704'),
   AND([Contact].MailingPostalCode = '55712'),
   AND([Contact].MailingPostalCode = '55749'),
   AND([Contact].MailingPostalCode = '55756'),
   AND([Contact].MailingPostalCode = '56055'),
   AND([Contact].MailingPostalCode = '56074'),
   AND([Contact].MailingPostalCode = '56082'),
   AND([Contact].MailingPostalCode = '56363'),
   AND(VALUE([Contact].MailingPostalCode) >= 55001,VALUE([Contact].MailingPostalCode) <= 55036),
   AND(VALUE([Contact].MailingPostalCode) >= 55038,VALUE([Contact].MailingPostalCode) <= 55309),
   AND(VALUE([Contact].MailingPostalCode) >= 55311,VALUE([Contact].MailingPostalCode) <= 55313),
   AND(VALUE([Contact].MailingPostalCode) >= 55315,VALUE([Contact].MailingPostalCode) <= 55323),
   AND(VALUE([Contact].MailingPostalCode) >= 55325,VALUE([Contact].MailingPostalCode) <= 55328),
   AND(VALUE([Contact].MailingPostalCode) >= 55330,VALUE([Contact].MailingPostalCode) <= 55331),
   AND(VALUE([Contact].MailingPostalCode) >= 55336,VALUE([Contact].MailingPostalCode) <= 55341),
   AND(VALUE([Contact].MailingPostalCode) >= 55343,VALUE([Contact].MailingPostalCode) <= 55349),
   AND(VALUE([Contact].MailingPostalCode) >= 55356,VALUE([Contact].MailingPostalCode) <= 55384),
   AND(VALUE([Contact].MailingPostalCode) >= 55386,VALUE([Contact].MailingPostalCode) <= 55388),
   AND(VALUE([Contact].MailingPostalCode) >= 55390,VALUE([Contact].MailingPostalCode) <= 55599),
   AND(VALUE([Contact].MailingPostalCode) >= 55901,VALUE([Contact].MailingPostalCode) <= 56017),
   AND(VALUE([Contact].MailingPostalCode) >= 56020,VALUE([Contact].MailingPostalCode) <= 56021),
   AND(VALUE([Contact].MailingPostalCode) >= 56023,VALUE([Contact].MailingPostalCode) <= 56029),
   AND(VALUE([Contact].MailingPostalCode) >= 56032,VALUE([Contact].MailingPostalCode) <= 56039),
   AND(VALUE([Contact].MailingPostalCode) >= 56042,VALUE([Contact].MailingPostalCode) <= 56052),
   AND(VALUE([Contact].MailingPostalCode) >= 56057,VALUE([Contact].MailingPostalCode) <= 56058),
   AND(VALUE([Contact].MailingPostalCode) >= 56063,VALUE([Contact].MailingPostalCode) <= 56072),
   AND(VALUE([Contact].MailingPostalCode) >= 56078,VALUE([Contact].MailingPostalCode) <= 56080),
   AND(VALUE([Contact].MailingPostalCode) >= 56089,VALUE([Contact].MailingPostalCode) <= 56098)
​  )

Good Formula:

  OR(
   AND([Contact].MailingState = 'ND'), 
   AND([Contact].MailingState = 'North Dakota'),
   AND([Contact].MailingState = 'UT'),
   AND([Contact].MailingState = 'Utah'),
   AND([Contact].MailingState = 'CO'),
   AND([Contact].MailingState = 'Colorado'),
   AND([Contact].MailingState = 'MN'),
   AND([Contact].MailingState = 'Minnesota'),
   AND([Contact].MailingPostalCode = '55037'),
   AND([Contact].MailingPostalCode = '55310'),
   AND([Contact].MailingPostalCode = '55314'),
   AND([Contact].MailingPostalCode = '55324'),
   AND([Contact].MailingPostalCode = '55329'),
   AND([Contact].MailingPostalCode = '55335'),
   AND([Contact].MailingPostalCode = '55342'),
   AND([Contact].MailingPostalCode = '55350'),
   AND([Contact].MailingPostalCode = '55353'),
   AND([Contact].MailingPostalCode = '55355'),
   AND([Contact].MailingPostalCode = '55385'),
   AND([Contact].MailingPostalCode = '55389'),
   AND([Contact].MailingPostalCode = '56019'),
   AND([Contact].MailingPostalCode = '56022'),
   AND([Contact].MailingPostalCode = '56041'),
   AND([Contact].MailingPostalCode = '56054'),
   AND([Contact].MailingPostalCode = '56056'),
   AND([Contact].MailingPostalCode = '56060'),
   AND([Contact].MailingPostalCode = '56062'),
   AND([Contact].MailingPostalCode = '56073'),
   AND([Contact].MailingPostalCode = '56075'),
   AND([Contact].MailingPostalCode = '56081'),
   AND(VALUE([Contact].MailingPostalCode) >= 55332,VALUE([Contact].MailingPostalCode) <= 55333),
   AND(VALUE([Contact].MailingPostalCode) >= 55601,VALUE([Contact].MailingPostalCode) <= 55703),
   AND(VALUE([Contact].MailingPostalCode) >= 55705,VALUE([Contact].MailingPostalCode) <= 55711),
   AND(VALUE([Contact].MailingPostalCode) >= 55713,VALUE([Contact].MailingPostalCode) <= 55748),
   AND(VALUE([Contact].MailingPostalCode) >= 55750,VALUE([Contact].MailingPostalCode) <= 55753),
   AND(VALUE([Contact].MailingPostalCode) >= 55757,VALUE([Contact].MailingPostalCode) <= 55816),
   AND(VALUE([Contact].MailingPostalCode) >= 56083,VALUE([Contact].MailingPostalCode) <= 56088),
   AND(VALUE([Contact].MailingPostalCode) >= 56101,VALUE([Contact].MailingPostalCode) <= 56362),
   AND(VALUE([Contact].MailingPostalCode) >= 56364,VALUE([Contact].MailingPostalCode) <= 58207)
  )
 
Hi All,

I have a before update Trigger and it is sending two emails when changing a case owner. Kindly help me It should send only once.
 
trigger sendEmailOnOwnerChange on Case (before update)
{
    Map<Id, Case> map_OldCaseValues = new Map<Id, Case>();
    Map<Id, Case> map_NewCaseValues = new Map<Id, Case>();

    String currentUserId = UserInfo.getUserId();
    
    Boolean sendMail = false;
    
    Boolean emailToNewCaseOwner;
    Boolean isEmailToOldAndNewOwner = false;
    
    system.debug('outsideloop'+Trigger.New.Size());
    for(integer i =0; i<Trigger.New.Size(); i ++)
    {
        system.debug('insideloop'+Trigger.New.Size());
        if(Trigger.New[i].OwnerId != Trigger.oldMap.get(Trigger.new[i].id).OwnerId)
        {        
           /*Requirement 443*/
           Trigger.New[i].Number_of_times_Flash_Displayed__c = 0;
           if(Trigger.oldMap.get(Trigger.new[i].id).OwnerId!= currentUserId && Trigger.new[i].OwnerId == currentUserId )
           {
               map_NewCaseValues.put(Trigger.New[i].Id,Trigger.New[i]); 
               system.debug('====map1'+map_NewCaseValues);
               map_OldCaseValues.put(Trigger.oldMap.get(Trigger.new[i].id).Id,Trigger.oldMap.get(Trigger.new[i].id)); 
               emailToNewCaseOwner = false;
               system.debug('====boolean1'+emailToNewCaseOwner);
           }
           
        }
    }
    
    if(!map_NewCaseValues.isEmpty())
    {
        new sendEmailOnOwnerChangeController().notificationStatusForInsert(map_NewCaseValues,map_OldCaseValues,emailToNewCaseOwner,isEmailToOldAndNewOwner);                
    }
I put debuglog and verified it triggered two times
Thanks In Advance,
Deepak​
Scenario:
I want to work with custom made UUID's instead of the default case sensitive Id's.
The Contact object for example has a field: UUID__c which contains a 36 char long unique, case-insensitive text string, set as External ID.

I'm able to get data in REST by using a GET request to /sobjects/Contact/UUID__c/af0407b7-eb9f-22f2-1648-fe66ccb4a516 (for example).
See also: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/using_resources_retrieve_with_externalid.htm

Now I want to use the same technique on Visualforce pages using controllers.
According to documentation the default route is to put the record id in the URL.
/apex/myPage?id=001x000xxx3Jsxb (for example)
See also: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_std_actions.htm

My challenge:
I want to be able to use the External ID too.
somehow /apex/myPage?UUID__c=af0407b7-eb9f-22f2-1648-fe66ccb4a516 (for example) doesn't seem to work.

- Do I need to switch some settings in order to be able to use it?
- Do I need to create an extension to the standard Contact controller in order to catch the External ID?
- Do I need to write a custom controller and lose the standard controller actions (and write everything from the ground up)?


 
I have a trigger that executes on after insert and after create on the Opportunity that updates fields on the OpportunityLineItem Object. Code works but the test class opportunity does not appear to successfully add a product so the code can not go into a IF statement. I am sure this is something simple but dang if I can figure it out. Your help would be greatly appreciated:
 
TRIGGER

//Case Number 1381 - Provides information about request for Trigger
trigger UpdateOTRev on Opportunity (after insert, after update) {
    Set<id> triggerIds = new Set<id>();
    List<OpportunityLineItem> lstOLIUpdate = new List<OpportunityLineItem>();
    //See if Trigger has only been run once
    if(RecursiveTriggerHandler.isFirstTime){
        RecursiveTriggerHandler.isFirstTime = false;
         //Put all trigger opp ids into a set
         for(Opportunity Opps : Trigger.new){
            triggerIds.add(Opps.Id);
         }//END for (Opportunity Opps)
         //Get all the Opp and Products
         List<Opportunity> lstOpps = [SELECT id, CloseDate, (SELECT id, TotalPrice, One_Time_Revenue__c FROM OpportunityLineItems) FROM Opportunity 
                                      WHERE id in: triggerIds];
             //Loop through Opps
             for(Opportunity opp: lstOpps){
                 //Loop through Products in Opps
                 for(OpportunityLineItem oli : opp.OpportunityLineItems){
                     if(oli.One_Time_Revenue__c == true){
                        //Apply the logic of which fields to update
                        if(opp.CloseDate > Date.valueOf('2017-12-31') && opp.CloseDate < Date.valueOf('2018-04-01')){
                            oli.One_Time_Rev_Q1_2018__c = oli.TotalPrice;
                            oli.One_Time_Rev_Q2_2018__c = 0;
                            oli.One_Time_Rev_Q3_2018__c = 0;
                            oli.One_Time_Rev_Q4_2018__c = 0;
                            oli.One_Time_Rev_Q1_2019__c = 0;
                            oli.One_Time_Rev_Q2_2019__c = 0;
                            oli.One_Time_Rev_Q3_2019__c = 0;
                            oli.One_Time_Rev_Q4_2019__c = 0;
                            lstOLIUpdate.add(oli);              
                        }//END if 2018 Q1
                        if(opp.CloseDate > Date.valueOf('2018-03-31') && opp.CloseDate < Date.valueOf('2018-07-01')){
                            oli.One_Time_Rev_Q1_2018__c = 0;
                            oli.One_Time_Rev_Q2_2018__c = oli.TotalPrice;
                            oli.One_Time_Rev_Q3_2018__c = 0;
                            oli.One_Time_Rev_Q4_2018__c = 0;
                            oli.One_Time_Rev_Q1_2019__c = 0;
                            oli.One_Time_Rev_Q2_2019__c = 0;
                            oli.One_Time_Rev_Q3_2019__c = 0;
                            oli.One_Time_Rev_Q4_2019__c = 0;
                            lstOLIUpdate.add(oli);              
                        }//END if 2018 Q2
                        if(opp.CloseDate > Date.valueOf('2018-06-30') && opp.CloseDate < Date.valueOf('2018-10-01')){
                            oli.One_Time_Rev_Q1_2018__c = 0;
                            oli.One_Time_Rev_Q2_2018__c = 0;
                            oli.One_Time_Rev_Q3_2018__c = oli.TotalPrice;
                            oli.One_Time_Rev_Q4_2018__c = 0;
                            oli.One_Time_Rev_Q1_2019__c = 0;
                            oli.One_Time_Rev_Q2_2019__c = 0;
                            oli.One_Time_Rev_Q3_2019__c = 0;
                            oli.One_Time_Rev_Q4_2019__c = 0;
                            lstOLIUpdate.add(oli);              
                        }//END if 2018 Q3
                        if(opp.CloseDate > Date.valueOf('2018-09-30') && opp.CloseDate < Date.valueOf('2019-01-01')){
                            oli.One_Time_Rev_Q1_2018__c = 0;
                            oli.One_Time_Rev_Q2_2018__c = 0;
                            oli.One_Time_Rev_Q3_2018__c = 0;
                            oli.One_Time_Rev_Q4_2018__c = oli.TotalPrice;
                            oli.One_Time_Rev_Q1_2019__c = 0;
                            oli.One_Time_Rev_Q2_2019__c = 0;
                            oli.One_Time_Rev_Q3_2019__c = 0;
                            oli.One_Time_Rev_Q4_2019__c = 0;
                            lstOLIUpdate.add(oli);              
                        }//END if 2018 Q4
                        if(opp.CloseDate > Date.valueOf('2018-12-31') && opp.CloseDate < Date.valueOf('2019-04-01')){
                            oli.One_Time_Rev_Q1_2018__c = 0;
                            oli.One_Time_Rev_Q2_2018__c = 0;
                            oli.One_Time_Rev_Q3_2018__c = 0;
                            oli.One_Time_Rev_Q4_2018__c = 0;
                            oli.One_Time_Rev_Q1_2019__c = oli.TotalPrice;
                            oli.One_Time_Rev_Q2_2019__c = 0;
                            oli.One_Time_Rev_Q3_2019__c = 0;
                            oli.One_Time_Rev_Q4_2019__c = 0;
                            lstOLIUpdate.add(oli);              
                        }//END if 2018 Q1
                        if(opp.CloseDate > Date.valueOf('2019-03-31') && opp.CloseDate < Date.valueOf('2019-07-01')){
                            oli.One_Time_Rev_Q1_2018__c = 0;
                            oli.One_Time_Rev_Q2_2018__c = 0;
                            oli.One_Time_Rev_Q3_2018__c = 0;
                            oli.One_Time_Rev_Q4_2018__c = 0;
                            oli.One_Time_Rev_Q1_2019__c = 0;
                            oli.One_Time_Rev_Q2_2019__c = oli.TotalPrice;
                            oli.One_Time_Rev_Q3_2019__c = 0;
                            oli.One_Time_Rev_Q4_2019__c = 0;
                            lstOLIUpdate.add(oli);              
                        }//END if 2019 Q2
                        if(opp.CloseDate > Date.valueOf('2019-06-30') && opp.CloseDate < Date.valueOf('2019-10-01')){
                            oli.One_Time_Rev_Q1_2018__c = 0;
                            oli.One_Time_Rev_Q2_2018__c = 0;
                            oli.One_Time_Rev_Q3_2018__c = 0;
                            oli.One_Time_Rev_Q4_2018__c = 0;
                            oli.One_Time_Rev_Q1_2019__c = 0;
                            oli.One_Time_Rev_Q2_2019__c = 0;
                            oli.One_Time_Rev_Q3_2019__c = oli.TotalPrice;
                            oli.One_Time_Rev_Q4_2019__c = 0;
                            lstOLIUpdate.add(oli);              
                        }//END if 2019 Q3
                        if(opp.CloseDate > Date.valueOf('2019-09-30') && opp.CloseDate < Date.valueOf('2020-01-01')){
                            oli.One_Time_Rev_Q1_2018__c = 0;
                            oli.One_Time_Rev_Q2_2018__c = 0;
                            oli.One_Time_Rev_Q3_2018__c = 0;
                            oli.One_Time_Rev_Q4_2018__c = 0;
                            oli.One_Time_Rev_Q1_2019__c = 0;
                            oli.One_Time_Rev_Q2_2019__c = 0;
                            oli.One_Time_Rev_Q3_2019__c = 0;
                            oli.One_Time_Rev_Q4_2019__c = oli.TotalPrice;
                            lstOLIUpdate.add(oli);              
                        }//END if 2019 Q4
                        if(opp.CloseDate > Date.valueOf('2019-12-31')){
                            oli.One_Time_Rev_Q1_2018__c = 0;
                            oli.One_Time_Rev_Q2_2018__c = 0;
                            oli.One_Time_Rev_Q3_2018__c = 0;
                            oli.One_Time_Rev_Q4_2018__c = 0;
                            oli.One_Time_Rev_Q1_2019__c = 0;
                            oli.One_Time_Rev_Q2_2019__c = 0;
                            oli.One_Time_Rev_Q3_2019__c = 0;
                            oli.One_Time_Rev_Q4_2019__c = 0;
                            
                            lstOLIUpdate.add(oli);
                        }
                         
                     }//END if(oli.One_Time_Revenue__c == true)                     
                 }//END For(OpportunityLineItem)
             }//END for(Opportunity)
    //Update Products if there are any to update
    if(lstOLIUpdate.size()>0){
        update lstOLIUpdate;
    }
    }//END if(RecusiveTriggerHandler.isFirstTime)
}//END Class

TEST CLASS
@isTest
public class UpdateOTRevTest {
    
    public static testMethod void testOppOneTimeRevenue(){
        
        Product2 prod2= new Product2(Name = 'Test Product - OneTime',
                                     Product_Gross_Margin__c = 10,
                                     Delivery_Market__c = 'none' ,
                                     Delivery_Region__c = 'ABCD',
                                     Delivery_Site__c = 'none' ,
                                     Family = 'XTCD',
                                     Description = 'Test Product',
                                     IsActive = true,
                                     Project_Seat_Count__c = 'false',
                                     One_Time_Revenue__c = true);
        insert prod2;
        Id pricebookId = Test.getStandardPricebookId();
        PricebookEntry pbEntry = new PricebookEntry(Pricebook2Id = pricebookId,
                                                    product2Id = prod2.Id,
                                                    isActive = true,
                                                    UnitPrice = 1000);
        insert pbEntry;
       
        Opportunity opp = new Opportunity(Name = 'Test Account - Opportunity',
                                          StageName = '1 - Prospect',
                                          Type = 'New Logo', 
                                          CloseDate = System.Date.today(),
                                          LeadSource = 'BDD/AM/OPS Development',
                                          Referral_Channel__c = 'None',
                                          Auto_Generate_Quarterly_Forecast__c = 'Yes',
                                          Contract_Length_Months__c = 24,
                                          Pricebook2Id = pricebookId,
                                          Amount = 10000000);
        insert opp;
       
        OpportunityLineItem oli = new OpportunityLineItem(OpportunityId = opp.id,
                                                          PricebookEntryId = pbEntry.id,
                                                          Product2Id = prod2.id,
                                                          Quantity = 10, 
                                                          Unit_Price2__c = 20,
                                                          Adjusted_Gross_Margin_Percentage__c = 10,
                                                          Service_Channel__c = 'WIDGET',
                                                          Service_Type__c = 'Care',
                                                          One_Time_Revenue__c = true);
        insert oli;
        
        System.debug('Opportunity Product Total Price '+ oli.TotalPrice);
        System.debug('OpportunityLineItem Id ' +oli.Id);
        System.debug('Product 2 Id '+ oli.Product2Id);
        System.debug('Opportunity Line Item Name : '+ oli.Name);
        System.debug('One Time Revenue : '+oli.One_Time_Revenue__c);
        Date closeDate = System.today();
        opp.CloseDate = Date.newInstance(2018, 01, 25);
       
        update opp;
        System.debug('Opp Close Date : '+opp.CloseDate);
    }//END Method
}//END Class

//https://salesforce.stackexchange.com/questions/72883/how-to-create-opportunity-line-items-in-test-classes

Code coverage is 10 of 103 lines because it does not appear that the OpportunityLineItem ever gets associated with the Opportunity.
User-added image

I would greatly appreciate any help.

Thank you. ​