• Synthia Beauvais
  • NEWBIE
  • 74 Points
  • Member since 2016
  • Salesforce Administrator
  • Veritiv


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 22
    Questions
  • 36
    Replies
I am creating a Predefined Filed but I am getting Error: Incorrect number of parameters for function 'YEAR()'. Expected 1, received 0

How can I correct the below formula? 

 
AND(Primary_Sales_Rep__c.Name, YEAR(), "Pipeline Review")

 
The triggers below count the number of contacts and active contacts on an account. I am not getting any errors with the below triggers however, after doing some testing I found that recalculation is not taking place when a contact is deleted and field "Number of Contacts" is not updating properly. How can I correct this problem? 
 
trigger NumberOfContacts on Account (before insert, before update) {
if(trigger.isinsert)
    for(account a:trigger.new)
        a.Number_of_contacts__c = 0;
else {
    List<AggregateResult> agResult = [SELECT Count(ID) conCount, AccountId accId FROM Contact WHERE AccountId IN :trigger.new Group By AccountId];
    for(AggregateResult result : agResult){
        trigger.newmap.get((Id) result.get('accId')).Number_of_contacts__c = (Integer)result.get('conCount');
    }

    for(Account act : Trigger.new){
        act.Number_of_active_contacts__c = 0;
    }
    agResult = [SELECT Count(ID) conCount, AccountId accId FROM Contact WHERE AccountId IN :trigger.new AND Inactive__c = false Group By AccountId];
    for(AggregateResult result : agResult){
        trigger.newmap.get((Id) result.get('accId')).Number_of_active_contacts__c = (Integer)result.get('conCount');
    }
}
 
trigger NumberOfContactsOnAccount on Contact (after insert, after update, after delete, after undelete) {
List<Contact> contacts = new list<contact>();
Map<Id,account> accounts = new map<id,account>();
if(trigger.new!=null)
    contacts.addAll(trigger.new);
if(trigger.old!=null)
    contacts.addAll(trigger.old);
for(contact c:contacts)
    accounts.put(c.accountid,new account(id=c.accountid));
accounts.remove(null);
update accounts.values();
}

User-added image


Thanks in advance!
I am getting the following error for my contact count trigger below. I am not sure what this error means. It only affects 2 out of 300,000+ accounts in my org. 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger NumberOfContacts caused an unexpected exception, contact your administrator: NumberOfContacts: execution of BeforeUpdate caused by: System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop: External entry point


 
// On Account

trigger NumberOfContacts on Account (before insert, before update) {
    if(trigger.isinsert)
        for(account a:trigger.new)
            a.Number_of_contacts__c = 0;
    else
        for(account a:[select id,(select id from contacts) from account where id in :trigger.new])
            trigger.newmap.get(a.id).Number_of_contacts__c = a.contacts.size();
            
        for(account b:[select id,(select id from contacts where Inactive__c = False) from account where id in :trigger.new])
            trigger.newmap.get(b.id).Number_of_active_contacts__c = b.contacts.size();
}



 
Hi All!

I need assistance with the following scenario.

I created Global Action “Status Update” for the Account object. Once the status update is created, the status type and comments should appear in the chatter feed of the Account. The status type is only appearing in the feed and not the comments. When I use Quick Action "Log a Call", the comments appear. How can I achieve the same thing with the Status Update quick action? 


User-added image
User-added image

Thanks in advance!
How can I update the fields below on the Account object? I am not familiar with writing a Batch Trigger. Please see code below.

Number_of_Contacts__c​
Number_of_Active_Contacts__c

 
trigger NumberOfContacts on Account (before insert, before update) {
    if(trigger.isinsert)
        for(account a:trigger.new)
            a.Number_of_contacts__c = 0;
    else
        for(account a:[select id,(select id from contacts) from account where id in :trigger.new])
            trigger.newmap.get(a.id).Number_of_contacts__c = a.contacts.size();
            
        for(account b:[select id,(select id from contacts where Inactive__c = False) from account where id in :trigger.new])
            trigger.newmap.get(b.id).Number_of_active_contacts__c = b.contacts.size();
}

Thanks in advnce! 
I would like to modify the code below to count the number of active contacts on an account. How can I make this change? 

Inactive__c (Checkbox)

 
//Test Class

@isTest
public class testClass1{
    @isTest
    public static void unitTest1(){
        List<Account> lstAccount = new List<Account>();
        lstAccount.add(new Account(name='testAccount1'));
        lstAccount.add(new Account(name='testAccount2'));
        lstAccount.add(new Account(name='testAccount3'));
        insert lstAccount;
        List<Contact> lstContact = new List<Contact>();
        lstContact.add(new Contact(lastName='testLast1',accountId=lstAccount[1].id));                
        lstContact.add(new Contact(lastName='testLast2',accountId=lstAccount[1].id));
        lstContact.add(new Contact(lastName='testLast3',accountId=lstAccount[1].id));                
        insert lstContact;
        delete lstContact[1];
    }
}


//On Contact

trigger NumberOfContactsOnAccount on Contact (after insert, after update, after delete, after undelete) {
    List<Contact> contacts = new list<contact>();
    Map<Id,account> accounts = new map<id,account>();
    if(trigger.new!=null)
        contacts.addAll(trigger.new);
    if(trigger.old!=null)
        contacts.addAll(trigger.old);
    for(contact c:contacts)
        accounts.put(c.accountid,new account(id=c.accountid));
    accounts.remove(null);
    update accounts.values();
}


//On Account

trigger NumberOfContacts on Account (before insert, before update) {
    if(trigger.isinsert)
        for(account a:trigger.new)
            a.Number_of_contacts_2__c = 0;
    else
        for(account a:[select id,(select id from contacts) from account where id in :trigger.new])
            trigger.newmap.get(a.id).Number_of_contacts_2__c = a.contacts.size();
}


 
I am trying to get a count of the number of contacts on an account, I am getting Error: Compile Error: Incompatible types in ternary operator: Integer, String at line 72 column 42. 
 
trigger NumberofContacts on Contact (after insert, after update, after delete, after undelete) {
    Map<Id, List<Contact>> mapAcctIdContactList = new Map<Id, List<Contact>>();
    Map<Id, List<Contact>> mapAcctIdDelContactList = new Map<Id, List<Contact>>();
    Set<Id> AcctIds = new Set<Id>();    
    List<Account> listAcct = new List<Account>();
    
    if(trigger.isInsert) {
        for(Contact Con : trigger.New) {
            if(String.isNotBlank(Con.AccountId)) {
                if(!mapAcctIdContactList.containsKey(Con.AccountId)) {
                    mapAcctIdContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdContactList.get(Con.AccountId).add(Con); 
                AcctIds.add(Con.AccountId);
            }   
        }  
    }
    
    if(trigger.isUpdate) {
        for(Contact Con : trigger.New) {
            if(String.isNotBlank(Con.AccountId) && Con.AccountId != trigger.oldMap.get(Con.Id).AccountId) {
                if(!mapAcctIdContactList.containsKey(Con.AccountId)){
                    mapAcctIdContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdContactList.get(Con.AccountId).add(Con); 
                AcctIds.add(Con.AccountId);
            } else if(String.isBlank(Con.AccountId) && String.isNotBlank(trigger.oldMap.get(Con.Id).AccountId)) {
                if(!mapAcctIdDelContactList.containsKey(Con.AccountId)){
                    mapAcctIdDelContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdDelContactList.get(Con.AccountId).add(Con);   
                AcctIds.add(trigger.oldMap.get(Con.Id).AccountId);
            }
        }  
    }
    
    if(trigger.isUndelete) {
        for(Contact Con : trigger.new) {
            if(String.isNotBlank(Con.AccountId)){
                if(!mapAcctIdContactList.containsKey(Con.AccountId)){
                    mapAcctIdContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdContactList.get(Con.AccountId).add(Con);     
                AcctIds.add(Con.AccountId);
            }
        }  
    }      

    if(trigger.isDelete) {
        for(Contact Con : trigger.Old) {
            if(String.isNotBlank(Con.AccountId)){
                if(!mapAcctIdDelContactList.containsKey(Con.AccountId)){
                    mapAcctIdDelContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdDelContactList.get(Con.AccountId).add(Con);    
                AcctIds.add(Con.AccountId); 
            }
        }  
    }   
    
    if(AcctIds.size() > 0) {
        listAcct = [SELECT Id, Number_of_Contacts__c FROM Account WHERE Id IN : AcctIds];
        
        for(Account acct : listAcct) {
            Integer noOfConts = 0;
            if(mapAcctIdContactList.containsKey(acct.Id)) {
                noOfConts += mapAcctIdContactList.get(acct.Id).size();
            }
            if(mapAcctIdDelContactList.containsKey(acct.Id)) {
                noOfConts -= mapAcctIdDelContactList.get(acct.Id).size();
            }
            acct.Number_of_Contacts__c = acct.Number_of_Contacts__c == null ? noOfConts : (acct.Number_of_Contacts__c + noOfConts);
        }
        
        update listAcct;    
    }
}

Thanks in advance!
Upon Account creation, State is defaulting to Mexico if I only enter a Zip Code. When I click edit on the record and immediately click Save, the Country is updated accordingly. What could be causing this?

User-added image

User-added image
 
/* UNITED STATES

CONTAINS( "Alabama: Alaska: Arizona: Arkansas: California: Colorado: Connecticut: Delaware: District of Columbia: Florida: Georgia: Hawaii: Idaho: Illinois: Indiana: Iowa: Kansas: Kentucky: Louisiana: Maine: Maryland: Massachusetts: Michigan: Minnesota: Mississippi: Missouri: Montana: Nebraska: Nevada: New Hampshire: New Jersey: New Mexico: New York: North Carolina: North Dakota: Ohio: Oklahoma: Oregon: Pennsylvania: Puerto Rico: Rhode Island: South Carolina: South Dakota: Tennessee: Texas: Utah: Vermont: Virgin Islands: Virginia: Washington: West Virginia: Wisconsin: Wyoming: AL: AK: AZ: AR: CA: CO: CT: DE: DC: FL: GA: HI: ID: IL: IN: IA: KS: KY: LA: ME: MD: MA: MI: MN: MS: MO: MT: NE: NV: NH: NJ: NM: NY: NC: ND: OH: OK: OR: PA: PR: RI: SC: SD: TN: TX: UT: VT: VI: VA: WA: WV: WI: WY", BillingState)

/*CANADA

CONTAINS("Alberta: British Columbia: Manitoba: New Brunswick: Newfoundland and Labrador: Northwest Territories: Nova Scotia: Nunavut: Ontario: Prince Edward Island: Quebec: Saskatchewan: Yukon: AB: BC: MB: NB: NL: NT: NS: NU: ON: PC: PE: QC: SK: YT", BillingState)

/*MEXICO

CONTAINS("Aguascalientes: Baja California: Baja California Sur: Chihuahua: Colima: Campeche: Coahuila: Chiapas: Federal District: Durango: Guerrero: Guanajuato: Hidalgo: Jalisco: México State: Michoacán: Morelos: Nayarit: Nuevo León: Oaxaca: Puebla: Querétaro: Quintana Roo: Sinaloa: San Luis Potosí: Sonora: Tabasco: Tlaxcala: Tamaulipas: Veracruz: Yucatán: Zacatecas", BillingState)

 
I am trying to create the following scenation but I am getting Error: Syntax error. Missing ')'

If the billing state is AK:AZ:CA:HI:NV:NM:OR:UT:WA the billing country should be "United States". 
IF(CONTAINS(BillingState)(“AK:AZ:CA:HI:NV:NM:OR:UT:WA”, BillingCountry), “United States”))

 
I am getting Error: Compiled formula is too big to execute (6,166 characters). Maximum size is 5,000 characters for the formula below. How can I correct this? 
 
IF( RecordTypeId='012700000009OvZAAU',
IF( Data_Quality_Score__c =5,"All Contact Details Captured", "Missing: "& 
IF( ISBLANK( Name), "Account Name, ","")&""&
IF( ISPICKVAL(Account_Vertical__c,""), "Account Vertical,","")&""&
IF( ISBLANK( BillingStreet), "Street, ","")&""&
IF( ISBLANK( BillingCity), "City, ","")&""&
IF( ISBLANK( BillingState),  "State, ","")&""&
IF( ISBLANK( BillingPostalCode),  "Postal Code, ","")&""&
IF( ISBLANK( BillingCountry), "Country, ","")&""&
IF( ISBLANK( NumberOfEmployees ),  "Number Of Employees, ","")&""&
IF( ISBLANK( DunsNumber), "Duns Number, ","")&""&
IF( ISPICKVAL( Preferred_Language__c,""), " Preferred Language,","")&""&
IF( ISPICKVAL( Segment_2__c,""), "Segment,","")),

IF(RecordTypeId='012700000009OvoAAE' ,
IF( Data_Quality_Score__c =5,"All Contact Details Captured", "Missing: "&
IF( ISBLANK( Name), "Account Name, ","")&""&
IF( ISPICKVAL(Account_Vertical__c,""), "Account Vertical,","")&""&
IF( ISBLANK( BillingStreet), "Street, ","")&""&
IF( ISBLANK( BillingCity), "City, ","")&""&
IF( ISBLANK( BillingState),  "State, ","")&""&
IF( ISBLANK( BillingPostalCode),  "Postal Code, ","")&""&
IF( ISBLANK( BillingCountry), "Country, ","")&""&
IF( ISBLANK( NumberOfEmployees ),  "Number Of Employees, ","")&""&
IF( ISBLANK( DunsNumber), "Duns Number, ","")&""&
IF( ISPICKVAL( Preferred_Language__c,""), " Preferred Language,","")&""&
IF( ISPICKVAL( Segment_2__c,""), "Segment,","")&""&
IF( ISBLANK( NaicsCode ), "NAICS Code, ","")&""&
IF( ISBLANK( Servicing_Division__c), "Servicing Division, ","")),""))

 
How can I reference 2 Record Type ID's in a formula? I have created a Data Quality Score field and a Description field. ​


If the Record Type is "Prospectscore these fields. (Data Quality Score field)
IF(Account.RecordTypeId=(000000000000000000)
IF( ISBLANK( Name),0,0.5)+
IF( ISPICKVAL(Account_Vertical__c,""),0,0.5)+
IF( ISBLANK( MailingStreet ),0, 0.5)+
IF( ISBLANK( MailingCity ),0,0.5)+
IF( ISBLANK( MailingState ),0,0.5)+
IF( ISBLANK( MailingPostalCode ),0,0.5)+
IF( ISBLANK( MailingCountry ),0,0.5)+
IF( ISBLANK( NumberOfEmployees ),0,0.375)+
IF( ISBLANK( DunsNumber),0,0.375)+
IF( ISBLANK(Preferred_Language__c,""),0,0.375)+
IF( ISPICKVAL(Segment_2__c,""),0,0.375)
If the Record Type is "Prospectdescribe these fields. (Description field)
IF(Account.RecordTypeId=(000000000000000000),&
IF( Data_Quality_Score__c =5,"All Contact Details Captured", "Missing: "&
IF( LEN( Name) = 0, "Account Name, ","")&""&
IF( ISPICKVAL(Account_Vertical__c,""), "Account Vertical,","")&""&
IF( LEN( MailingStreet ) = 0, "Street, ","")&""&
IF( LEN( MailingCity ) = 0, "City, ","")&""&
IF( LEN( MailingState ) = 0, "State, ","")&""&
IF( LEN( MailingPostalCode ) = 0, "Postal Code, ","")&""&
IF( LEN( MailingCountry ) = 0, "Country, ","")&""&
IF( LEN( NumberOfEmployees ) = 0, "Number Of Employees, ","")&""&
IF( LEN( DunsNumber) = 0, "    Duns Number, ","")&""&
IF( ISPICKVAL(Preferred_Language__c,""), " Preferred Language,","")&""&
IF( ISPICKVAL(Segment_2__c,""), "Segment,",""))

---------------------------------------------------------------------------------------------------------------------------------------------

If the Record Type is "Customerscore these fields. (Data Quality Score field)
IF(Account.RecordTypeId=(000000000000000000),&
IF( ISBLANK( Name),0,0.384615385)+
IF( ISPICKVAL(Account_Vertical__c,""),0,0.384615385)+
IF( ISBLANK( MailingStreet ),0, 0.384615385)+
IF( ISBLANK( MailingCity ),0,0.384615385)+
IF( ISBLANK( MailingState ),0,0.384615385)+
IF( ISBLANK( MailingPostalCode ),0,0.384615385)+
IF( ISBLANK( MailingCountry ),0,0.384615385)+
IF( ISBLANK( NumberOfEmployees ),0,0.384615385)+
IF( ISBLANK( DunsNumber),0,0.384615385)+
IF( ISBLANK(Preferred_Language__c,""),0,0.384615385)+
IF( ISPICKVAL(Segment_2__c,""),0,0.384615385)+
IF( ISBLANK( NaicsCode ),0,0.384615385)+
IF( ISBLANK( Servicing_Division__c),0,0.384615385))
If the Record Type is "Customerdescribe these fields. (Description Field)
 
IF(Account.RecordTypeId=(000000000000000000),&
IF( LEN( Name) = 0, "Account Name, ","")&""&
IF( ISPICKVAL(Account_Vertical__c,""), "Account Vertical,","")&""&
IF( LEN( MailingStreet ) = 0, "Street, ","")&""&
IF( LEN( MailingCity ) = 0, "City, ","")&""&
IF( LEN( MailingState ) = 0, "State, ","")&""&
IF( LEN( MailingPostalCode ) = 0, "Postal Code, ","")&""&
IF( LEN( MailingCountry ) = 0, "Country, ","")&""&
IF( LEN( NumberOfEmployees ) = 0, "Number Of Employees, ","")&""&
IF( LEN( DunsNumber) = 0, "    Duns Number, ","")&""&
IF( ISPICKVAL(Preferred_Language__c,""), " Preferred Language,","")&""&
IF( ISPICKVAL(Segment_2__c,""), "Segment,","")&""&
IF( LEN( NaicsCode ) = 0, "NAICS Code, ","")&""&
IF( LEN( Servicing_Division__c) = 0, "Servicing Division, ",""))

Thanks in advance!
 
I am trying to create a data quality score on the Contact object for the fields listed in the chart below. I am not quite sure how to calculate the weight. I have started the formula but I am not getting the correct "Actual Value".
 
IF( 
OR( 
ISBLANK(Phone), 
OR( 
CONTAINS(Phone, '000-0000') , 
CONTAINS(Phone, '111-1111') , 
CONTAINS(Phone, '222-2222') , 
CONTAINS(Phone, '333-3333') , 
CONTAINS(Phone, '444-4444') , 
CONTAINS(Phone, '555-5555') , 
CONTAINS(Phone, '666-6666') , 
CONTAINS(Phone, '777-7777') , 
CONTAINS(Phone, '888-8888') , 
CONTAINS(Phone, '123-4567') , 
CONTAINS(Phone, '456-7890')
) 
), 0, 1 
) 

+ 
IF( ISBLANK( MailingStreet ), 0, 1)+ 
IF( ISBLANK( MailingCity ), 0, 1)+ 
IF( ISBLANK( MailingState ), 0, 1)+ 
IF( ISBLANK( MailingCountry ), 0, 1)+ 
IF( ISBLANK( MailingPostalCode ), 0, 1) +
IF( ISBLANK(FirstName ) ,0,1) + 
IF( ISBLANK( LastName ) , 0, 1)+ 
IF( ISBLANK( Email ) , 0, 1)
/9



User-added image

MAX SCORE: 5
MIN SCORE: 0


Thanks in advance! 


 
I am getting "Error: Multiple items found. Select from drop-down or click icon to refine search." for the below URL hacks. The field that is getting this error is Account Name (Custom Field). I am unable to locate the fields ID. I've downloaded the WSDL and looked at the page source and I am still not able to locate the field ID.

Is there anywhere else I can locate the ID for a custom field? 

Opportunity Object
/0WO/e?RecordType=000000000000000000& 
Account={!Opportunity.Account}& 
CF000000000000000000={!Opportunity.Name}& 
CF000000000000000000={!Opportunity.Primary_Sales_Rep_Name__c}& 
000000000000000000={!Opportunity.Opportunity_Segment__c}& 
000000000000000000={!Opportunity.Prod_Category__c}
Account Object
/0WO/e?RecordType=000000000000000&
Account={!Account.Name}&
CF0000000000000000={!Account.Primary_Sales_Rep_Name__c}


This is what's present for the URL. 

_ui/common/config/field/StandardFieldAttributes/d?id=Name&type=Account&retURL=%2Fp%2Fsetup%2Flayout%2FLayoutFieldList%3Ftype%3DAccount%26retURL%3D%252Fui%252Fsetup%252FSetup%253Fsetupid%253DAccount%26setupid%3DAccountFields&setupid=AccountFields
Thanks in advance!
When creating a Work Order field Prod_Category__c which is a Multi Select Picklist should populate. The field does not populate when there is more than 1 product chosen. How can I get the multiple items to pre-populate? 
 
/0WO/e?RecordType=000000000000000000& 
Account={!Opportunity.Account}& 
000000000000000000={!Opportunity.Name}& 
000000000000000000={!Opportunity.Primary_Sales_Rep_Name__c}& 
000000000000000000={!Opportunity.Opportunity_Segment__c}& 
000000000000000000={!Opportunity.Prod_Category__c}

 
I am getting these 4 errors when trying to close opportunities. I am not sure how to correct this. 

Account: System.LimitException: Apex CPU time limit exceeded
Opportunity: execution of AfterUpdate caused by: System.LimitException: Apex CPU time limit exceeded Trigger.Opportunity: line 66, column 1

Opportunity: execution of BeforeUpdate caused by: System.LimitException: Apex CPU time limit exceeded Class.OpportunityTriggerUtil.carryOverSalesTeamOnOwnerChange: line 149, column 1 Trigger.Opportunity: line 108, column 1

Opportunity: execution of BeforeUpdate caused by: System.LimitException: Apex CPU time limit exceeded Class.OpportunityTriggerUtil.carryOverSalesTeamOnOwnerChange: line 150, column 1 Trigger.Opportunity: line 108, column 1
 
trigger Opportunity on Opportunity (before insert, after insert, before update, after update) {

	Set<String> specialistProductCategories = new Set<String>();
	Boolean addSpecialistsToSalesTeam = false;
	for(RoleNameMapping__c rnm : OpportunityTriggerUtil.roleNameMapping)
	{
		specialistProductCategories.add(rnm.Product_Category__c);
	}

	Id testingCaraId = [select Id from Profile where Name = 'Testing - Cara'].Id;
	System.debug(testingCaraId);
	System.debug(UserInfo.getProfileId());
	if ( UserInfo.getProfileId() !=  testingCaraId )
	{
		if(Trigger.isInsert)
		{
			if(Trigger.IsBefore)
			{
				OpportunityTriggerUtil.updateAccountDEUField(Trigger.new);
				
				/* 10/12 - Taken out to remove Account Vertical field and functionality on Opportunity to remove an inconsistent error. */
				/*
				List<Account> populatedAccounts = OpportunityTriggerUtil.populateAccountVerticalField(trigger.new);
                if(! populatedAccounts.isEmpty()){
                    OpportunityTriggerUtil.updateAccounts(populatedAccounts, trigger.new);
                }
                */
			}
			else
			{
				for(Opportunity o : Trigger.new)
				{
					if( o.Prod_Category__c != null )
					{
						for(String category : o.Prod_Category__c.split(';'))
						{
							if(specialistProductCategories.contains(category))
							{
								addSpecialistsToSalesTeam = true;
								break;
							}
						}
					}
				}
				if(addSpecialistsToSalesTeam )
				{
					OpportunityTriggerUtil.updateExistingOpportunitiesSalesTeam(Trigger.new);
				}
				
			}
		}
		else if(Trigger.isUpdate && trigger.isAfter)
		{
			/*Only update opportunity sales team if new product categories that
			map to specialists are added*/

			Set<String> oldProductCategories = new Set<String>();
			Set<String> newProductCategories = new Set<String>();


			for(Opportunity o : Trigger.old)
			{
				if(o.Prod_Category__c != null )
				{
					for(String category : o.Prod_Category__c.split(';'))
					{
						oldProductCategories.add(category);
					}
				}
			}

			for(Opportunity o : Trigger.new)
			{
				if(o.Prod_Category__c != null  )
				{
					for(String category : o.Prod_Category__c.split(';'))
					{
						if(specialistProductCategories.contains(category) && !oldProductCategories.contains(category))
						{
							newProductCategories.add(category);
						}
					}
				}
			}
			Boolean ownerHasChanged = false;
			for(Opportunity o : Trigger.new)
			{
				if(trigger.oldMap.get(o.Id).OwnerId != o.ownerId )
					ownerHasChanged = true;
			}


			if(ownerHasChanged || !newProductCategories.isEmpty())
				OpportunityTriggerUtil.updateExistingOpportunitiesSalesTeam(Trigger.new);
		}
	}

	if( trigger.isBefore && trigger.isUpdate )
	{
		/* 10/12 - Taken out to remove Account Vertical field and functionality on Opportunity to remove an inconsistent error. */
		/*
		List<Account> populatedAccounts = OpportunityTriggerUtil.populateAccountVerticalField(trigger.new);
		if(! populatedAccounts.isEmpty()){
		    OpportunityTriggerUtil.updateAccounts(populatedAccounts, trigger.new);
		}
		*/
		
		OpportunityTriggerUtil.carryOverSalesTeamOnOwnerChange( trigger.newMap, trigger.oldMap );

		OpportunityTriggerUtil.updateRepFieldsOnAccountFieldChange( trigger.newMap, trigger.oldMap );
	}
	else if( trigger.isAfter && trigger.isInsert )
	{
		OpportunityTriggerUtil.insertSalesTeamForPSRAndIRep( trigger.newMap );

		List<Opportunity> openOpportunities = ChatterServices.filterOpenOpportunities( trigger.new );

		ChatterServices.subscribePSRandOwnerToSObject( openOpportunities, new Map<ID,Opportunity>());
	} 
	else if( trigger.isAfter && trigger.isUpdate )
	{
		OpportunityTriggerUtil.createTeamMembersAfterTriggerFires( trigger.newMap );
		OpportunityTriggerUtil.updateSalesTeamForPSRAndIRep( trigger.newMap, trigger.oldMap );

		List<Opportunity> openOpportunities = ChatterServices.filterOpenOpportunities( trigger.new );
		ChatterServices.subscribePSRandOwnerToSObject(openOpportunities, trigger.oldMap);
	}
	
	if( trigger.isAfter && trigger.isUpdate  )
	{
		List<Opportunity> filteredOpportunities = OpportunityTriggerUtil.filterBasedOnFieldUpdates( trigger.new, trigger.oldMap);
		if( !filteredOpportunities.isEmpty() )
		{
			List<Account> accountsToBeUpdated = OpportunityTriggerUtil.updateAccountFields( filteredOpportunities );
			OpportunityTriggerUtil.updateAccounts(accountsToBeUpdated, trigger.new);
		}
	}
}


 
If there is a description in text field X3PL_Customer_Owned_Items_Description__c
picklist X3PL_Customer_Owned_Items__c must contain "Informational Only" or "Review Required"​

I am getting Error: Syntax error. Extra ','
 
AND(
NOT(ISPICKVAL(X3PL_Customer_Owned_Items__c, 'Informational Only')),
NOT(ISPICKVAL(X3PL_Customer_Owned_Items__c, 'Review Required')),
NOT(ISBLANK(X3PL_Customer_Owned_Items_Description__c))
),
AND(      
NOT(ISPICKVAL(X3PL_Veritiv_Provided__c, 'Informational Only')),
NOT(ISPICKVAL(X3PL_Veritiv_Provided__c, 'Review Required')), 
NOT(ISPICKVAL(X3PL_Veritiv_Provided_Description__c))
))

Thanks in advance! 
 
I have 50 checkbox fields that I need to change to picklist with the same value and record type. Is it possible to change these in bulk? Is there a tool for this? Or will I have make these changes 1 by 1

Thanks in advance! 
How difficult would it be to create a Visualforce page that will show activity history and Chatter post on an Opporutnity? 
  1. Work Order is created from the Account Object
  2. When work order is saved, LookUp Field: Primary_Sales_Rep_Name__c should populate with the name from field Primary_Sales_Rep_Name__c from the Account Object
  3. Getting Error on Line 5: Incompatible element type Schema.SObjectField for collection of Id
trigger UpdatePSR on WorkOrder (before insert, before update){
 Set<id> accIds = new Set<id>();
 for(WorkOrder Account: trigger.new){
  if(WorkOrder.Primary_Sales_Rep_Name__c!= null){
   accIds.add(WorkOrder.Primary_Sales_Rep_Name__c);
  }
 }
if(accIds.size() > 0){
  Map<Id,Account> mapOfAccounts = new Map<Id,Account>([Select Primary_Sales_Rep_Name__c from Account where id in :accIds]);
   if(mapOfAccounts.containsKey(Account.Primary_Sales_Rep_Name__c)){
    Account.Primary_Sales_Rep_Name__c = mapOfAccounts.get(Account.Primary_Sales_Rep_Name__c).Primary_Sales_Rep_Name__c;
   }
  }
 }
Thanks in advance! 

 
When creating a Work Order from the Opportunity object, the flow process correctly updating 2 fileds automatically. 

User-added image

When creating a Work Order from the Account object I get the following email however there is nothing that need to be updated. 

Flow Details
Flow Name: Work_Order_Field_Update
Type: Workflow
Version: 1
Status: Active
Flow Interview Details
Interview Label: Work_Order_Field_Update-1_WorkOrder
Current User: Synthia Beauvais (00518000000iFjU)
Start time: 4/6/2016 10:57 AM
Duration: 0 seconds
How the Interview Started
Synthia Beauvais (00518000000iFjU) started the flow interview.
Some of this flow's variables were set when the interview started.
myVariable_old = 0WO180000008PV4GAM
myVariable_current = 0WO180000008PV4GAM
ASSIGNMENT: myVariable_waitStartTimeAssignment
{!myVariable_waitStartTimeVariable} Equals {!Flow.CurrentDateTime}
Result
{!myVariable_waitStartTimeVariable} = "4/6/2016 10:57 AM"
DECISION: myDecision
Executed this outcome: myRule_1
Outcome conditions: and
1. {!formula_myRule_1} (true) Equals true
Logic: All conditions must be true (AND)

How can I correct this?

Thanks in advance! 
The triggers below count the number of contacts and active contacts on an account. I am not getting any errors with the below triggers however, after doing some testing I found that recalculation is not taking place when a contact is deleted and field "Number of Contacts" is not updating properly. How can I correct this problem? 
 
trigger NumberOfContacts on Account (before insert, before update) {
if(trigger.isinsert)
    for(account a:trigger.new)
        a.Number_of_contacts__c = 0;
else {
    List<AggregateResult> agResult = [SELECT Count(ID) conCount, AccountId accId FROM Contact WHERE AccountId IN :trigger.new Group By AccountId];
    for(AggregateResult result : agResult){
        trigger.newmap.get((Id) result.get('accId')).Number_of_contacts__c = (Integer)result.get('conCount');
    }

    for(Account act : Trigger.new){
        act.Number_of_active_contacts__c = 0;
    }
    agResult = [SELECT Count(ID) conCount, AccountId accId FROM Contact WHERE AccountId IN :trigger.new AND Inactive__c = false Group By AccountId];
    for(AggregateResult result : agResult){
        trigger.newmap.get((Id) result.get('accId')).Number_of_active_contacts__c = (Integer)result.get('conCount');
    }
}
 
trigger NumberOfContactsOnAccount on Contact (after insert, after update, after delete, after undelete) {
List<Contact> contacts = new list<contact>();
Map<Id,account> accounts = new map<id,account>();
if(trigger.new!=null)
    contacts.addAll(trigger.new);
if(trigger.old!=null)
    contacts.addAll(trigger.old);
for(contact c:contacts)
    accounts.put(c.accountid,new account(id=c.accountid));
accounts.remove(null);
update accounts.values();
}

User-added image


Thanks in advance!
I am getting the following error for my contact count trigger below. I am not sure what this error means. It only affects 2 out of 300,000+ accounts in my org. 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger NumberOfContacts caused an unexpected exception, contact your administrator: NumberOfContacts: execution of BeforeUpdate caused by: System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop: External entry point


 
// On Account

trigger NumberOfContacts on Account (before insert, before update) {
    if(trigger.isinsert)
        for(account a:trigger.new)
            a.Number_of_contacts__c = 0;
    else
        for(account a:[select id,(select id from contacts) from account where id in :trigger.new])
            trigger.newmap.get(a.id).Number_of_contacts__c = a.contacts.size();
            
        for(account b:[select id,(select id from contacts where Inactive__c = False) from account where id in :trigger.new])
            trigger.newmap.get(b.id).Number_of_active_contacts__c = b.contacts.size();
}



 
How can I update the fields below on the Account object? I am not familiar with writing a Batch Trigger. Please see code below.

Number_of_Contacts__c​
Number_of_Active_Contacts__c

 
trigger NumberOfContacts on Account (before insert, before update) {
    if(trigger.isinsert)
        for(account a:trigger.new)
            a.Number_of_contacts__c = 0;
    else
        for(account a:[select id,(select id from contacts) from account where id in :trigger.new])
            trigger.newmap.get(a.id).Number_of_contacts__c = a.contacts.size();
            
        for(account b:[select id,(select id from contacts where Inactive__c = False) from account where id in :trigger.new])
            trigger.newmap.get(b.id).Number_of_active_contacts__c = b.contacts.size();
}

Thanks in advnce! 
I would like to modify the code below to count the number of active contacts on an account. How can I make this change? 

Inactive__c (Checkbox)

 
//Test Class

@isTest
public class testClass1{
    @isTest
    public static void unitTest1(){
        List<Account> lstAccount = new List<Account>();
        lstAccount.add(new Account(name='testAccount1'));
        lstAccount.add(new Account(name='testAccount2'));
        lstAccount.add(new Account(name='testAccount3'));
        insert lstAccount;
        List<Contact> lstContact = new List<Contact>();
        lstContact.add(new Contact(lastName='testLast1',accountId=lstAccount[1].id));                
        lstContact.add(new Contact(lastName='testLast2',accountId=lstAccount[1].id));
        lstContact.add(new Contact(lastName='testLast3',accountId=lstAccount[1].id));                
        insert lstContact;
        delete lstContact[1];
    }
}


//On Contact

trigger NumberOfContactsOnAccount on Contact (after insert, after update, after delete, after undelete) {
    List<Contact> contacts = new list<contact>();
    Map<Id,account> accounts = new map<id,account>();
    if(trigger.new!=null)
        contacts.addAll(trigger.new);
    if(trigger.old!=null)
        contacts.addAll(trigger.old);
    for(contact c:contacts)
        accounts.put(c.accountid,new account(id=c.accountid));
    accounts.remove(null);
    update accounts.values();
}


//On Account

trigger NumberOfContacts on Account (before insert, before update) {
    if(trigger.isinsert)
        for(account a:trigger.new)
            a.Number_of_contacts_2__c = 0;
    else
        for(account a:[select id,(select id from contacts) from account where id in :trigger.new])
            trigger.newmap.get(a.id).Number_of_contacts_2__c = a.contacts.size();
}


 
Hello, 
I am trying to explore different possiblity from Schema class. I beleive this class is a good resource for all programmers.
I am trying to display text fields of a custom object. The script below gives me all the fields 


public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Map <String, Schema.SObjectField> fieldMap = schemaMap.get('Account').getDescribe().fields.getMap();
system.debug(fieldMap);


How can i get the field property so that i can filter all text fields?
I am trying to get a count of the number of contacts on an account, I am getting Error: Compile Error: Incompatible types in ternary operator: Integer, String at line 72 column 42. 
 
trigger NumberofContacts on Contact (after insert, after update, after delete, after undelete) {
    Map<Id, List<Contact>> mapAcctIdContactList = new Map<Id, List<Contact>>();
    Map<Id, List<Contact>> mapAcctIdDelContactList = new Map<Id, List<Contact>>();
    Set<Id> AcctIds = new Set<Id>();    
    List<Account> listAcct = new List<Account>();
    
    if(trigger.isInsert) {
        for(Contact Con : trigger.New) {
            if(String.isNotBlank(Con.AccountId)) {
                if(!mapAcctIdContactList.containsKey(Con.AccountId)) {
                    mapAcctIdContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdContactList.get(Con.AccountId).add(Con); 
                AcctIds.add(Con.AccountId);
            }   
        }  
    }
    
    if(trigger.isUpdate) {
        for(Contact Con : trigger.New) {
            if(String.isNotBlank(Con.AccountId) && Con.AccountId != trigger.oldMap.get(Con.Id).AccountId) {
                if(!mapAcctIdContactList.containsKey(Con.AccountId)){
                    mapAcctIdContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdContactList.get(Con.AccountId).add(Con); 
                AcctIds.add(Con.AccountId);
            } else if(String.isBlank(Con.AccountId) && String.isNotBlank(trigger.oldMap.get(Con.Id).AccountId)) {
                if(!mapAcctIdDelContactList.containsKey(Con.AccountId)){
                    mapAcctIdDelContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdDelContactList.get(Con.AccountId).add(Con);   
                AcctIds.add(trigger.oldMap.get(Con.Id).AccountId);
            }
        }  
    }
    
    if(trigger.isUndelete) {
        for(Contact Con : trigger.new) {
            if(String.isNotBlank(Con.AccountId)){
                if(!mapAcctIdContactList.containsKey(Con.AccountId)){
                    mapAcctIdContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdContactList.get(Con.AccountId).add(Con);     
                AcctIds.add(Con.AccountId);
            }
        }  
    }      

    if(trigger.isDelete) {
        for(Contact Con : trigger.Old) {
            if(String.isNotBlank(Con.AccountId)){
                if(!mapAcctIdDelContactList.containsKey(Con.AccountId)){
                    mapAcctIdDelContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdDelContactList.get(Con.AccountId).add(Con);    
                AcctIds.add(Con.AccountId); 
            }
        }  
    }   
    
    if(AcctIds.size() > 0) {
        listAcct = [SELECT Id, Number_of_Contacts__c FROM Account WHERE Id IN : AcctIds];
        
        for(Account acct : listAcct) {
            Integer noOfConts = 0;
            if(mapAcctIdContactList.containsKey(acct.Id)) {
                noOfConts += mapAcctIdContactList.get(acct.Id).size();
            }
            if(mapAcctIdDelContactList.containsKey(acct.Id)) {
                noOfConts -= mapAcctIdDelContactList.get(acct.Id).size();
            }
            acct.Number_of_Contacts__c = acct.Number_of_Contacts__c == null ? noOfConts : (acct.Number_of_Contacts__c + noOfConts);
        }
        
        update listAcct;    
    }
}

Thanks in advance!
I am getting Error: Compiled formula is too big to execute (6,166 characters). Maximum size is 5,000 characters for the formula below. How can I correct this? 
 
IF( RecordTypeId='012700000009OvZAAU',
IF( Data_Quality_Score__c =5,"All Contact Details Captured", "Missing: "& 
IF( ISBLANK( Name), "Account Name, ","")&""&
IF( ISPICKVAL(Account_Vertical__c,""), "Account Vertical,","")&""&
IF( ISBLANK( BillingStreet), "Street, ","")&""&
IF( ISBLANK( BillingCity), "City, ","")&""&
IF( ISBLANK( BillingState),  "State, ","")&""&
IF( ISBLANK( BillingPostalCode),  "Postal Code, ","")&""&
IF( ISBLANK( BillingCountry), "Country, ","")&""&
IF( ISBLANK( NumberOfEmployees ),  "Number Of Employees, ","")&""&
IF( ISBLANK( DunsNumber), "Duns Number, ","")&""&
IF( ISPICKVAL( Preferred_Language__c,""), " Preferred Language,","")&""&
IF( ISPICKVAL( Segment_2__c,""), "Segment,","")),

IF(RecordTypeId='012700000009OvoAAE' ,
IF( Data_Quality_Score__c =5,"All Contact Details Captured", "Missing: "&
IF( ISBLANK( Name), "Account Name, ","")&""&
IF( ISPICKVAL(Account_Vertical__c,""), "Account Vertical,","")&""&
IF( ISBLANK( BillingStreet), "Street, ","")&""&
IF( ISBLANK( BillingCity), "City, ","")&""&
IF( ISBLANK( BillingState),  "State, ","")&""&
IF( ISBLANK( BillingPostalCode),  "Postal Code, ","")&""&
IF( ISBLANK( BillingCountry), "Country, ","")&""&
IF( ISBLANK( NumberOfEmployees ),  "Number Of Employees, ","")&""&
IF( ISBLANK( DunsNumber), "Duns Number, ","")&""&
IF( ISPICKVAL( Preferred_Language__c,""), " Preferred Language,","")&""&
IF( ISPICKVAL( Segment_2__c,""), "Segment,","")&""&
IF( ISBLANK( NaicsCode ), "NAICS Code, ","")&""&
IF( ISBLANK( Servicing_Division__c), "Servicing Division, ","")),""))

 
Hello, 
I am trying to explore different possiblity from Schema class. I beleive this class is a good resource for all programmers.
I am trying to display text fields of a custom object. The script below gives me all the fields 


public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Map <String, Schema.SObjectField> fieldMap = schemaMap.get('Account').getDescribe().fields.getMap();
system.debug(fieldMap);


How can i get the field property so that i can filter all text fields?