• Srinivasa Chary Taduri
  • NEWBIE
  • 115 Points
  • Member since 2012

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 34
    Replies
trigger PracticeFrmOpp on SSO__c (before insert,before update) {
    Set<Id> accIds = new Set<Id>();
    
    for(SSO__c sso :trigger.new) {
        accIds.add(sso.Opportunity_Name__c);
    }   
    Map<Id,opportunity> mappractice = new Map<Id,opportunity>([select id, Practiceu__c from opportunity
                                                                where id in :accIds]);
    for(SSO__c sso:trigger.new) {
        if(mappractice != null && mappractice .containsKey(sso.Opportunity_Name__c)) {
            opportunity OppRecord = mappractice .get(sso.Opportunity_Name__c);
            sso.Practice_test__c= OppRecord .Practiceu__c ;
        }
    }
}
Hi, I am updating parent accountnumber in child object contact. But i want to update the field contact - accountnumber field only when accountnumber in contact is null. if we provide any new value in accountnumber of contact field, then new value should be updated not parent account-accountnumber.
Below is class which will update accountnumber of Account in contact even we are providing other value in Contact object.
I mean if we are providing any value in contact-accountnumber field, then new should be updated, it should not override with parent account-accountnumber. Please help.


public class accountnamepopualtion
{
public static void popualteacc(List<Contact> coonlist)
{
set<Id> accountids= new set<Id>();
Map<id,string> accmap= new Map<id,string>();
for(contact con:coonlist)
{
 
accountids.add(con.accountid);
}
for(Account acc:[select id,accountnumber from account where id in:accountids])
{
accmap.put(acc.id,acc.accountnumber );
 
}
for(contact con:coonlist)
{
if(accmap.containskey(con.accountid) && con.Account_Number__c==null)
{
con.Account_Number__c=accmap.get(con.accountid);
}
}
}
}


trigger contactTrigger on contact(before insert, before update, after insert, after update )
{
 if (Trigger.isBefore)
      {
            if (Trigger.isInsert  )
            {
              accountnamepopualtion.setAccountName(trigger.new);
             }

}
}

Thanks in advance
Hello,

Can someone help point out where the NullPointerException occurs? This class is invocable from a process that gets the Opportunity Line Item ID for created and updated records where Product End Date = null. 
 
public with sharing class invocable_productEndDate 
{
  
  /*Params to be passed from different process builder processes from varying objects. 
  None required, because each process will execute slightly different logic and use different params.*/
  public class productVariables 
  {
    @InvocableVariable
    public Id opptyLineItemId;
  }

  @InvocableMethod
  public static void productEndDate(List<productVariables>  Vars)
  {
    List<Id> oppLineItemIds = new List<Id>();
    List<OpportunityLineItem> oppLineItems = new List<OpportunityLineItem>();
    Map<Id, OpportunityLineItem> oliIdandOLI = new Map<Id, OpportunityLineItem>();
    Map<Id, Date> oliAndProductEndDate = new Map<Id, Date>();
    Set<Id> updateOLIIds = new Set<Id>();
    List<OpportunityLineItem> olisToUpdate = new List<OpportunityLineItem>();


    /*Loop through variable objects passed from process builder and assign Ids to lists. Because of SOQL
    governors, don't want to query inside loop, so list assignment works around that*/
    for (productVariables var : Vars)
    {
      if (var.opptyLineItemId != null)
      {
        oppLineItemIds.add(var.opptyLineItemId);
        system.debug('oppLineItemIds = ' + oppLineItemIds);
      }
    }

    oppLineItems = [SELECT Id, ServiceDate, Product_End_Date__c, PricebookEntry.Product2.FY16_Revenue_Type__c
          FROM OpportunityLineItem 
          WHERE Id IN : oppLineItemIds
          AND PricebookEntry.Product2.FY16_Revenue_Type__c = 'Recurring'];

    system.debug('oppLineItems = ' + oppLineItems);

    /*Product Term Months may be null, because Product End Date is not required on Salesforce ui when adding a product. Assume 12 months from ServiceDate and calculate months between.
    Default Product Date based on these assumptions - updates will re-calculate accordingly.*/
    for (OpportunityLineItem oli : oppLineItems)
    {
      oliIdandOLI.put(oli.Id, oli);
      Date tempProductEndDate = oli.ServiceDate.addYears(1).addDays(-1);
      oliAndProductEndDate.put(oli.Id, tempProductEndDate);
    }

    /*Line Item field values to update go in maps in this block*/
    if (!oliIdandOLI.isEmpty())
    {
      for (Id oliID : oliIdandOLI.keySet())
      {
        if (!oliAndProductEndDate.isEmpty())
        {
          oliIdandOLI.get(oliId).Product_End_Date__c = oliAndProductEndDate.get(oliId);
        }
      }
    }

    /*Don't want duplicates in list of line items to update, so loop through ordered set of Ids and add to update list only if the record is not already there.*/
    for (Id oliId : oliIdandOLI.keySet())
    {
      if (!updateOLIIds.contains(oliId))
      {
        olisToUpdate.add(oliIdandOLI.get(oliId));
        system.debug('olisToUpdate =  ' + olisToUpdate);
      }
      else
      {
        updateOLIIds.add(oliId);
        system.debug('updateOLIIds = ' + updateOLIIds);
      }
    }



Thank you,

Maggie
Please help me for below questions.

1 of 5.    
How can an existing picklist field with 750 values be shared across objects? 
     
A.        Create a new Global Value Set in the Setup menu under Picklist Value Sets
B.        Ensure the field is an unrestricted picklist, then Promote to a Global Value Set
C.        Ensure the field is a restricted picklist, then Promote to a Global Value Set
D.        Reduce the number of values to 500, then Promote to a Global Value Set


2 of 5.    
Universal Containers tracks the Priority of new Positions using a custom field. The value of 'Medium' is currently selected as the default value. The field definition is modified to include this default value formula: IF($UserRole.Name = ""VP Engineering"", ""Critical"", """").
 
Which value will be displayed in the field when a new Position record is created by a user with the role ""VP Sales""?
     
A.        High
B.        Medium
C.        Critical
D.        No value


3 of 5.    
Which two steps should an administrator take to quickly and easily activate a session-based Permission Set? 
     Choose 2 answers
     
A.        Enable the Session Activation Required option for the Permission Set
B.        Use the Activate Session-Based Permission Set action in Process Builder
C.        Use the Activate Session-Based Permission Set action in a flow
D.        Enable the Session Based Activation option for the Permission Set


4 of 5.    
What is a new feature of the Data Import Wizard? 
     
A.        Work with multiple delimiter values to split data
B.        Match picklist values to look-up and master-detail fields
C.        Import duplicate rows with Smart-Matching
D.        Use a search function to map fields more easily


5 of 5.    
Universal Containers' production org is currently on the Summer '17 release. A Permission Set named "Integration User" already exists in the org with the "API Enabled" administrative permission enabled. A change set is deployed to this org that includes a Permission Set with the same name that has the "Author Apex" administrative permission enabled but does not have the "API Enabled" permission enabled.
 
Which behavior will the Permission Set have after deployment? 
     
A.        API Enabled
B.        The deployment contents are merged with the current org data
C.        Author Apex
D.        An error occurs

Hi

 

Lead Source Last Updated is the picklist field, Issue is field history is showing that it has been changed from null to Trade Show, but there is no Trade Show value in this field.

 

Please help me on this as soon as possible.

 

Thanks and Regards,

Srinivas

 

Hi Eperts,

Please share me with example and provide bit more information.. pls don't share the link

Thanks,
Chanti

Hello, 

New to writing trigger so I'm unsure why I'm getting the Id is not specified error. Goal is if an existing user record's Channel OR LOB field  is updated then, it should look for existing User History record and update the Role_End_Date__c and create a new history record with for that same user with the Role_Start_Date__c as today. 
 
public class UserHistory_CreateUpdateFromUser  {

	public static void findUser(List<User> newUsers, Map<Id,User> oldUsers, Boolean isInsert){

		List<User> newUserList = new List<User>(); 
		List<User> lOBChannelList = new List<User>();
		List<User> isActiveList = new List<User>(); 
		List<User> uManagerLOBChannelList = new List<User>();
        List<User> uManagerList = new List<User>(); 
		Map<Id,List<User>> reasonForUpdatingUser = new Map<Id,List<User>>(); 
			
       	for(User u : newUsers){
            //New user && Channel != Non Sales  
            if(u.Channel__c != 'Non Sales'){
                if(isInsert){ 
       				newUserList.add(u); 
       				System.debug('newUserList: '+ newUserList); 
       			}
                //Existing user && Channel || LOB is changed 
       			else if(!isInsert && (u.Channel__c != oldUsers.get(u.Id).Channel__c || u.LOB_Focus__c != oldUsers.get(u.Id).LOB_Focus__c)) {
       				lOBChannelList.add(u); 
       				System.debug('lOBChannelList: '+ lOBChannelList); 
       			}
       			//Existing user && deactived 
       			else if(!isInsert && u.IsActive != oldUsers.get(u.Id).IsActive){
       				isActiveList.add(u); 
       				System.debug('isActiveList: '+ isActiveList);
                }
                //Existing user && Manager is changed && Channel || LOB is changed 
       			else if(!isInsert && u.ManagerId != oldUsers.get(u.Id).ManagerId &&
                        (u.Channel__c != oldUsers.get(u.Id).Channel__c || u.LOB_Focus__c != oldUsers.get(u.Id).LOB_Focus__c)){
       				uManagerLOBChannelList.add(u); 
       				System.debug('uManagerLOBChannelList: '+ uManagerLOBChannelList);
       			}
       			//Existing user && Manager is changed 
                else if(!isInsert && u.ManagerId != oldUsers.get(u.Id).ManagerId){
                    uManagerList.add(u); 
                    System.debug('uManagerList: '+ uManagerList);
                }
            }     
       	}

       	if(newUserList.size()>0){
       		newUser(newUserList);
       	}	

       	if(lOBChannelList.size()>0){
       		lOBChannelUpdate(lOBChannelList); 
       	}

       	if(isActiveList.size()>0){
       		userisActiveUpdate(isActiveList); 
       	}

       	if(uManagerList.size()>0){
       		managerUpdateOnly(uManagerList); 
       	}

       	if(uManagerLOBChannelList.size()>0){
       		managerLOBChannelUpdate(uManagerLOBChannelList); 
       	}
       
	}

	public static void lOBChannelUpdate(List<User> lOBChannelList){
		//Find existing User History record and update end date fields 
		//Create new user history record and update fields based on user changes 

		List<Id> userIds = new List<Id>(); 
		List<User_History__c> existingUHtoUpdate = new List<User_History__c>(); 
		List<User_History__c> newUHtoInsert = new List<User_History__c>(); 

		for(User u : lOBChannelList){
			userIds.add(u.Id); 
		}
		System.debug('userIds: '+ userIds);
		System.debug('lOBChannelList: '+ lOBChannelList);

		if(userIds.size()>0){
			List<User_History__c> eUH = [SELECT Id, User__C, Role_End_Date__c, Manager_End_Date__c FROM User_History__c
											WHERE User__c =:userIds]; 
            System.debug('eUH' + eUH); 

			for(User_History__c uH : eUH){

                User_History__c existingUH = new User_History__c(); 
                
                if(uH.Role_End_Date__c == NULL){
					existingUH.Role_End_Date__c = Date.today(); 
					existingUH.Id = uH.Id;
                }
                else if(uH.Manager_End_Date__c == NULL){
					existingUH.Manager_End_Date__c = Date.today(); 
					existingUH.Id = uH.Id;
                }
                else if(uH.Role_End_Date__c == NULL && uH.Manager_End_Date__c == NULL){
                    existingUH.Role_End_Date__c = Date.today(); 
                    existingUH.Manager_End_Date__c = Date.today(); 
                    existingUH.Id = uH.Id;
                }
				existingUHtoUpdate.add(existingUH); 
			}
			System.debug('existingUHtoUpdate: '+ existingUHtoUpdate);

			for(User u1 : lOBChannelList){
                
				User_History__c newUH = new User_History__c(
				User__c = u1.Id, 
				Channel__c = u1.Channel__c,  
				LOB_Focus__c = u1.LOB_Focus__c,  
				Role_Start_Date__c = Date.today(), 
				Manager_Start_Date__c = Date.today()
			); 
				newUHtoInsert.add(newUH); 
				
			}	
			System.debug('newUHtoInsert: '+ newUHtoInsert);
		}

		if(!existingUHtoUpdate.isempty()){
			Database.update(existingUHtoUpdate); 
		}
		System.debug('Databaseupdate existingUHtoUpdate: ' + existingUHtoUpdate); 

		if(!newUHtoInsert.isempty()){
			Database.insert(newUHtoInsert);
		}

	}
I've checked on the debug log that it is finding the Id of the existing User History record when I do the query and added it on the list 'eUH' and looped through that list. 

 
  • October 17, 2017
  • Like
  • 1
Hi Everyone, I am very new to salesforce and am currently working on a sample application for Human Resource. 

I have stored the Employee Level and corresponding salary in a custom setting. So when i create a new employee, i should be able to select the employee level, which should auto populate the salary field using the custom setting field. Can anyone help me on how to do that?
trigger PracticeFrmOpp on SSO__c (before insert,before update) {
    Set<Id> accIds = new Set<Id>();
    
    for(SSO__c sso :trigger.new) {
        accIds.add(sso.Opportunity_Name__c);
    }   
    Map<Id,opportunity> mappractice = new Map<Id,opportunity>([select id, Practiceu__c from opportunity
                                                                where id in :accIds]);
    for(SSO__c sso:trigger.new) {
        if(mappractice != null && mappractice .containsKey(sso.Opportunity_Name__c)) {
            opportunity OppRecord = mappractice .get(sso.Opportunity_Name__c);
            sso.Practice_test__c= OppRecord .Practiceu__c ;
        }
    }
}
Hi, I am updating parent accountnumber in child object contact. But i want to update the field contact - accountnumber field only when accountnumber in contact is null. if we provide any new value in accountnumber of contact field, then new value should be updated not parent account-accountnumber.
Below is class which will update accountnumber of Account in contact even we are providing other value in Contact object.
I mean if we are providing any value in contact-accountnumber field, then new should be updated, it should not override with parent account-accountnumber. Please help.


public class accountnamepopualtion
{
public static void popualteacc(List<Contact> coonlist)
{
set<Id> accountids= new set<Id>();
Map<id,string> accmap= new Map<id,string>();
for(contact con:coonlist)
{
 
accountids.add(con.accountid);
}
for(Account acc:[select id,accountnumber from account where id in:accountids])
{
accmap.put(acc.id,acc.accountnumber );
 
}
for(contact con:coonlist)
{
if(accmap.containskey(con.accountid) && con.Account_Number__c==null)
{
con.Account_Number__c=accmap.get(con.accountid);
}
}
}
}


trigger contactTrigger on contact(before insert, before update, after insert, after update )
{
 if (Trigger.isBefore)
      {
            if (Trigger.isInsert  )
            {
              accountnamepopualtion.setAccountName(trigger.new);
             }

}
}

Thanks in advance
Hi Team,
I want To write This Trigger test class any one help me to how to write....
Approach:Write Custom Code in salesforce to stop deleting any event forcefully Through this event will not get deleted in salesforce even in outlook

- If someone need to really delete the event they need to click on extra checkbox and save then delete in salesforce
 pls tell me is it correct trigger to this Apporch

Note: Pls Test Class Should Be Bulkify........
 
trigger avoidDeletionEvent on Event (before delete) {
for(event e:trigger.old)
{
    if(e.Override_Deletion__c==false)
        e.addError('You do not have permission to delete this event');
   }
}


 
  • August 08, 2017
  • Like
  • 0
 Actually the condition is that i have department field picklist in Account, whenever i change the department(picklist) from account  it should be reflect to the department field in contact. I have to write a trigger to update the records in contact.  
Hi,
I have 2 triggers written named Account_Share and Delete_Share.
I am pushing data from external site into salesforce.
So,in Salesforce in Account object,one standard field named ownerID(Lookup User )  and one custom field named owner1__c (Lookup User ) should get updated whenever changes are done in the site.
But this is not happening.Even though changes are made in the site,same is not getting updated in salesforce, rather it  throws an error as follows:

Account {"Party_Sea_ID__c":3618,"Customer_Number__c":"C0354","Name":"LUXURY BRAND HOLDINGS INC.","DBA_Name__c":"LUXURY BRAND HOLDINGS","Customer_Group_Id__c":"a0028000015lr6gAAA","OwnerId":"00528000005HQRPAA4","owner1__c":"00528000005HQRPAA4","Terms_Id__c":"a042800000oV27IAAS","Default_Currency__c":"US DOLLARS","Industry":"Jewelry","Website":"www.luxurybrandholdings.com<http://www.luxurybrandholdings.com><http://www.luxurybrandholdings.com>","No_of_Doors__c":14,"NumberOfEmployees":0,"Store_Size__c":0,"Contact_Person__c":"0","Rolex_Dealer__c":"Y","Status__c":1,"Sales_Code__c":"ASSET AND MEMO","RecordTypeId":"01228000000QbiR","Asset_Credit_Limit__c":1000000.0,"Memo_Credit_Limit__c":1500000.0,"Outstanding_A_R_Balance__c":0.0,"Outstanding_Memo_Balance__c":0.0,"BillingStreet":"9 ROSS SIMONS DRIVE - 2920 , , ","BillingPostalCode":"2920"} Delete_Share: execution of BeforeUpdate caused by: System.DmlException: Delete failed. First exception on row 0 with id 00r28000020W8ELAA0; first error: DELETE_FAILED, cannot delete owner or rule share rows, id=00r28000020W8EL: [] Trigger.Delete_Share: line 89, column 1

-----------------------------------------------------------------------------------------------
Account_Share Trigger:
trigger Account_Share on Account (after insert,after update) {

 List<AccountShare> jobShares = new List<AccountShare>();
    
 for(Account a : trigger.new){

if (a.owner1__c != null) {
 
   

   AccountShare accountRecord = new AccountShare();
   accountRecord.AccountId= a.Id;
    
   
   System.Debug('************* Salesforce Account ID ******* '+a.Id);
   accountRecord.UserOrGroupId = a.owner1__c;
   System.Debug('************* Salesforce Custom Owner: Account Executive ******* '+ a.owner1__c);
    
  
   accountRecord.AccountAccessLevel= 'edit';
   System.debug('Account Acess: '+  accountRecord.AccountAccessLevel);
   
   accountRecord.OpportunityAccessLevel='Read';
   System.debug('Oppurtunity Acess: '+  accountRecord.OpportunityAccessLevel);
   
   System.debug('Acc_share_trigger Account Record: '+ accountRecord);
    
   jobShares.add(accountRecord);
 }  

 /** Insert all of the newly created Share records and capture save result **/
 Database.SaveResult[] jobShareInsertResult = Database.insert(jobShares,false);
 System.debug('Insert all of the newly created Share records: '+ jobShareInsertResult);


}
}
-------------------------------------------------------------------------------------------
Delete Share Trigger 
trigger Delete_Share on Account (before update) {


set<Id> AccountIDs = new Set<Id>();
for(Account a: trigger.new){
AccountIDs.add(a.id);
}
List<AccountShare> jobShares = new List<AccountShare>();

map<String,AccountShare> accountShareMap = new Map<String,AccountShare>();

for(AccountShare accShare : [select AccountId, UserOrGroupId from AccountShare where AccountId in :AccountIds])
{
 accountShareMap.put(String.valueOf(accShare.UserOrGroupId),accShare);

}



for(Account a : trigger.new){
Account oldAccount = Trigger.OldMap.get(a.id);
if ((a.owner1__c != oldAccount.owner1__c) && (a.ownerId != oldAccount.owner1__c)){
 
   AccountShare accountRecord = accountShareMap.get(string.valueOf(oldAccount.owner1__c)); 
    if (accountRecord  != null)
    jobShares.add(accountRecord);
  }
 }

if(jobShares.isEmpty() == false ){

 delete jobShares;
 }
 }


 
Hi everyone,

I have an issue with receiving duplicate emails over time. For instance, whenever an individual visits our website and navigates to "Contact Us" form and submit it (https://www.screencast.com/t/y91L1gFdK). Soon after someone submits the form, I'm getting a notification that a new prospect is interested in our business. Which is cool, that's the way I wanted it to work. What's unexpected is, after a week or so, again I'm receiving a notification with same First Name, Last Name, Email Address. That creates a duplication of the same contact with same First&Last Name and Email address. Where is the actual problem from, on the Pardot side or website side? I appreciate all your suggestions, once again thank you all!

Thanks,
Sri
Hello,

Can someone help point out where the NullPointerException occurs? This class is invocable from a process that gets the Opportunity Line Item ID for created and updated records where Product End Date = null. 
 
public with sharing class invocable_productEndDate 
{
  
  /*Params to be passed from different process builder processes from varying objects. 
  None required, because each process will execute slightly different logic and use different params.*/
  public class productVariables 
  {
    @InvocableVariable
    public Id opptyLineItemId;
  }

  @InvocableMethod
  public static void productEndDate(List<productVariables>  Vars)
  {
    List<Id> oppLineItemIds = new List<Id>();
    List<OpportunityLineItem> oppLineItems = new List<OpportunityLineItem>();
    Map<Id, OpportunityLineItem> oliIdandOLI = new Map<Id, OpportunityLineItem>();
    Map<Id, Date> oliAndProductEndDate = new Map<Id, Date>();
    Set<Id> updateOLIIds = new Set<Id>();
    List<OpportunityLineItem> olisToUpdate = new List<OpportunityLineItem>();


    /*Loop through variable objects passed from process builder and assign Ids to lists. Because of SOQL
    governors, don't want to query inside loop, so list assignment works around that*/
    for (productVariables var : Vars)
    {
      if (var.opptyLineItemId != null)
      {
        oppLineItemIds.add(var.opptyLineItemId);
        system.debug('oppLineItemIds = ' + oppLineItemIds);
      }
    }

    oppLineItems = [SELECT Id, ServiceDate, Product_End_Date__c, PricebookEntry.Product2.FY16_Revenue_Type__c
          FROM OpportunityLineItem 
          WHERE Id IN : oppLineItemIds
          AND PricebookEntry.Product2.FY16_Revenue_Type__c = 'Recurring'];

    system.debug('oppLineItems = ' + oppLineItems);

    /*Product Term Months may be null, because Product End Date is not required on Salesforce ui when adding a product. Assume 12 months from ServiceDate and calculate months between.
    Default Product Date based on these assumptions - updates will re-calculate accordingly.*/
    for (OpportunityLineItem oli : oppLineItems)
    {
      oliIdandOLI.put(oli.Id, oli);
      Date tempProductEndDate = oli.ServiceDate.addYears(1).addDays(-1);
      oliAndProductEndDate.put(oli.Id, tempProductEndDate);
    }

    /*Line Item field values to update go in maps in this block*/
    if (!oliIdandOLI.isEmpty())
    {
      for (Id oliID : oliIdandOLI.keySet())
      {
        if (!oliAndProductEndDate.isEmpty())
        {
          oliIdandOLI.get(oliId).Product_End_Date__c = oliAndProductEndDate.get(oliId);
        }
      }
    }

    /*Don't want duplicates in list of line items to update, so loop through ordered set of Ids and add to update list only if the record is not already there.*/
    for (Id oliId : oliIdandOLI.keySet())
    {
      if (!updateOLIIds.contains(oliId))
      {
        olisToUpdate.add(oliIdandOLI.get(oliId));
        system.debug('olisToUpdate =  ' + olisToUpdate);
      }
      else
      {
        updateOLIIds.add(oliId);
        system.debug('updateOLIIds = ' + updateOLIIds);
      }
    }



Thank you,

Maggie

Im stuff trying to use the field.addError() method to post validation errors on my VF page.

The standard absolute method call works fine e.g.. customObj.fieldName.addError('myString');

BUT I need to use this with fields I dynamic reference on a generic SObject.

I've tried genericObj.get('fieldname').addError('myString'); but this validates to a method does not exists error

 

Can anyone help me, please?

 

Best Regards

Ronni 

  • July 23, 2012
  • Like
  • 0