• Art Smorodin 7
  • NEWBIE
  • 50 Points
  • Member since 2016

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
Hello Developers,
Need your thoughts/help..
I have a trigger on child object which updates check box on contact as True on creation of child. (This happens in below trigger)
But it doesn't allow me to delete the child for that contact anymore.
Trigger CrossObjectContactUpdate on Merchandise__C(after delete, after insert, after update){


    List<Merchandise__c> Merch = New List<Merchandise__C>();
    List<Contact> Con = New List<Contact>();
    Set<ID> ConID = New Set<ID>();
        
    for(Merchandise__c M: Trigger.New)
    {
       ConId.add(M.Individual_Customer__C);
    }
    Boolean T = True;
    
    Contact Con1 = [Select X_CrossObj__c From Contact Where ID IN: ConID];
    for(Merchandise__C MC: Trigger.New)
    {    
        Con1.X_CrossObj__c = T;
    }
    update Con1;
    
}

This trigger is created to just update the record of parent. So my other triggers can fire. So, having checkbox checked or not checked don't really matter. Its all about update.
Thank You!

Well, one more Q) Can we update parent record (just update) when child is created, deleted, updated etc.. with process builder? IF yes, then I can take that path instead of trigger above.
Thank you guys for help!
 
I'm trying to create a trigger that will Sum Contacts at the Account Level when the Contact Type = Owner.  I want to take that number increate it by 1 and add an 's' to the front of it and populate it on an Account Level Field called TAFS_General_Manager_tag__c.  

The problem I'm having is comparing the string field to the integer in my trigger.  How can I create an integer to use in the trigger?  My trigger is listed below.  So the end result I want to place in the TAFS_General_Manager_tag__c will be 's' + (sum of contacts with a type of Owner +1)



trigger ContactSumTrigger on Contact (after delete, after insert, after undelete, 
after update) {

    Contact[] cons;
    if (Trigger.isDelete) 
        cons = Trigger.old;
    else
        cons = Trigger.new;

    // get list of accounts
    Set<ID> acctIds = new Set<ID>();
    for (Contact con : cons) {
            acctIds.add(con.AccountId);
    }
    
    Map<ID, Contact> contactsForAccounts = new Map<ID, Contact>([select Id
                                                            ,AccountId
                                                            from Contact
                                                            where AccountId in :acctIds and TAFS_Contact_Type__c = 'Owner']);

    Map<ID, Account> acctsToUpdate = new Map<ID, Account>([select Id
                                                                 ,TAFS_General_Manager_tag__c
                                                                  from Account
                                                                  where Id in :acctIds]);
                                                                 
    for (Account acct : acctsToUpdate.values()) {
        Set<ID> conIds = new Set<ID>();
        for (Contact con : contactsForAccounts.values()) {
            if (con.AccountId == acct.Id)
                conIds.add(con.Id);
        }
        if (acct.TAFS_General_Manager_tag__c != conIds.size())
            acct.TAFS_General_Manager_tag__c = 's' + conIds.size();
    }

    update acctsToUpdate.values();

}
Hi, 
trying to solve a challange. Have a Napili community template with several pages. One of the pages has a lightning component that is basically a pop-up window (using modals from the lightning design system). Now, I want the component only show up once per session, how to ahcieve that?
 
Idea is you log to community, it takes you to the home page; you navigate to page #2 and component runs dislaying the pop-up, you clos it out using a button on that component; you go to a different page, and after navigating back to page #2 the component should not run. 

Can't figure it out. Any suggestins? 
Thanks in advance,
Art.
Hi All, 

as youmay know the new Napili template "User Profile" component is now a standrd (out of the box) lightning component that we can use. I have a question regarding field visibility of that component. 

So on the user profile component, if I am the user, I can see all my standrad fields (email, address, First Name, Last name) and all my custom fields I Iadded. If I look at my own page I can see all those populated. But if, within the same Community, I open up a User Profile page of another user, the view is different. The layout is the same but some of the fields are hidden. Email and street address for example are both hidden. 

My question is: how do I make some of my custom fields hidden as well, without creating a whole new Component. The Idea is that I can put some addition info on the user profile without worring that other community users will be able to see that data. 

P.S. the two users I am using to test this belong to the same Account and have the same Role and Profile. 

Thank you in advance. 
-Art.
Hello everyone, 

I am new to VisualForce but have some experiense doing Triggers and Classes. Trying to devlop a VF page which will show Contacts and Leads under a single view, frouped by Stage ( Stage__c is a common field on both Objects). Tbale should also have some data related to Tasks ( if a Contact has 5 overdue tasks, table shoud show that count). 

I have VF page, Controlled and a class partially developped.  As I add ned fields and calculations I test the page. It was working fine but now I see that "Apex CPU time limit exceeded " error. 
Can you guys look at my code and suggest some modifications. Please be advised that my code is a bit of a mess, since I was taking parts of codes from all over the place and tried to fmodify it to meet my needs. 

VF Page:
<apex:page controller="DisplaySectionsController" sidebar="false" readOnly="true">  
  <apex:sectionHeader title="My Sample Display Page" subtitle="Group by States" 
    description="This page shows how you can dynamically group results by field value."/>
 <apex:pageBlock title="My Tasks">
  	<table  border="1">
    <tr>
        <td width="50%"></td>
        <td>Count</td>
    </tr>
    <tr>
        <td id="pastdue">New contact requests</td>
        <td><apex:outputText value="" id="theValue"/></td>
    </tr>
        <tr>
        <td id="pastdue">Past due</td>
        <td><apex:outputLink value="/00O36000006wJ0w" id="theLink"><apex:outputText value="{!pastDue}" /></apex:outputLink></td>
    </tr>
        <tr>
        <td id="bold">Due today</td>
        <td><apex:outputText value="{!dueTod}"/></td>
    </tr>
        <tr>
        <td id="bold">Due tomorrow</td>
        <td><apex:outputText value="{!dueTmr}"/></td>
    </tr>
        <tr>
        <td>Due next 7 days</td>
        <td><apex:outputText value="{!duen7d}"/></td> 
    </tr>
        <tr>
        <td>Other scheduled</td>
        <td></td>
    </tr>
	</table>
</apex:pageBlock><br/>
  <apex:repeat value="{!states}" var="state">

    <apex:pageBlock title="People is Stage: {!state}" > 
     	  <table border = "1" width = "100%">
     	  <tr>
     	  	<td>Name</td>
     	  	<td>Status</td>
     	  	<td>Overdue Tasks</td>
     	  	<td>Scheduled Tasks</td>
     	  	<td>Most recent prospect Activity (days)</td>
     	  	<td>Most recent interaction (days)</td>
     	  	<td>Next interaction (days)</td>
     	  	<td>Prospect Rating</td>
     	  	<td>Other key contacts</td>
     	  	<td>Other non-key contacts</td>
     	  	<td>Contact description</td>
     	  	<td>Most recent expression</td>
     	  	<td>Most recent interaction</td>
     	  	<td>Next Task</td>
     	  </tr>
          <apex:repeat value="{!RowList}" var="item"><apex:outputPanel rendered="{!IF(state=item.Stage,true,false)}">
  		  <tr align ="center">
     	  	<td>{!item.Name}</td>
     	  	<td>Status</td>
     	  	<td>{!item.overTsk}</td>
     	  	<td>{!item.schedTsk}</td>
     	  	<td>{!item.MRPAd}</td>
     	  	<td><apex:outputText value="{!item.stars}" escape="false"/></td>

     	  </tr>	
            </apex:outputPanel></apex:repeat>                
           </table>
    </apex:pageBlock>

  </apex:repeat>

</apex:page>

Contoller: 
public with sharing class DisplaySectionsController {
	public List<Contact> contacts {get;set;}  
  	public List<Lead> leads {get;set;}  
  	public String[] states {get;set;}
  	List<Task> myTasks2;
  	Map<String, List<Id>> listMyTasks = new Map<String, List<Id>>();
  	private  Integer pastDue; 
	private  Integer dueTod ;
	private  Integer dueTmr;
	private  Integer duen7d;
	//public List<TableRow> RowList {get; set;}
	TskQueryClass TQC = new TskQueryClass(); 
	Public class TableRow{
    	
	public String Name {get; set;}
	public Integer overTsk {get; set;}
	public Integer schedTsk {get; set;}
	public Integer MRPAd {get; set;}
	public Integer MRIntd {get; set;}
	public Integer NxtIntd {get; set;}
	public Integer Rating {get; set;}
	public String conDesc {get; set;}
	public String MRExp {get; set;}
	public String MRint {get; set;}
	public String NxtTsk {get; set;}
	public String Stage {get; set;}
	public String stars {get; set;}
	}
	
  public  DisplaySectionsController() {

    // for demo purposes limit the states  
    contacts = [Select ID, Name, Stage__c, Account.Name,scoring_prospect_level_stars__c From Contact 
      Where Stage__c IN ('SAL', 'MQL','Buyer', 'Relevant', 'Connected','Qualifying','Actionable Response','Response','Prospecting','Target','Name') AND OwnerId = :userinfo.getuserId() AND CreatedDate >= 2016-01-01T00:00:00.000Z];
	leads = [Select ID, Name, Stage__c, Company From Lead 
      Where Stage__c IN ('SAL', 'MQL','Buyer', 'Relevant', 'Connected','Qualifying','Actionable Response','Response','Prospecting','Target','Name') AND OwnerId = :userinfo.getuserId() AND CreatedDate >= 2016-01-01T00:00:00.000Z];
	
    // dynamically create set of unique states from query
    Set<String> stateSet = new Set<String>();
    String[] stateSet2 = new String[]{'SAL', 'MQL','Buyer', 'Relevant', 'Connected','Qualifying','Actionable Response','Response','Prospecting','Target','Name'} ;
    for (Contact a : contacts)
      stateSet.add(a.Stage__c);
	for (Lead l : leads)
      stateSet.add(l.Stage__c);
    // convert the set into a string array  
    states = new String[stateSet.size()];
    Integer i = 0;
    for (String state : stateSet) { 
      states[i] = state;
      i++;
    }
    //------------------------------------------------------------------------------------------------------------------------
    
	myTasks2 = TQC.returnmyTasks();
		for(Task a : myTasks2){
    		List<String> temp = listMyTasks.get(a.xTask_Status__c);
    		if(temp == null) {
        		listMyTasks.put(a.xTask_Status__c, new List<Id>{a.Id});
    		} 
    		else {
        		temp.add(a.Id);
   			}
		}
  }//end DisplaySectionsController()
  public Integer getpastDue(){
    	List<id> temp = listMyTasks.get('Pastdue');
        if (temp != NULL) pastDue = temp.size();
        else pastDue = 0;
        return pastDue;
    }
    
    public Integer getdueTod(){
    	List<id> temp = listMyTasks.get('DueToday');
        if (temp != NULL) dueTod = temp.size();
        else dueTod = 0;
        return dueTod;
    }
    
    public Integer getdueTmr(){
    	List<id> temp = listMyTasks.get('DueTmr');
        if (temp != NULL) dueTmr = temp.size();
        else dueTmr  = 0;
        return dueTmr;
    }
    
    public Integer getduen7d(){
    	List<id> temp = listMyTasks.get('Scheduled');
        if (temp != NULL)  duen7d = temp.size();
        else duen7d  = 0;
        return duen7d;
    }
	//---------------------------------------------------------------------------------------------------------------------------------
	
	    public List<TableRow> getRowList(){
    	String MRPAtype = VFReporting_page__c.getInstance().Most_recent_prospect_activity_type__c;
    	String MRPAsub = VFReporting_page__c.getInstance().Most_recent_prospect_activity_subject__c;
    	Date startDate = system.today();
        List<Task> MRPA;
        Integer MRPAdsice;
		List<TableRow> RowList = new List<TableRow>();
		TableRow tr;
		Integer i = 0;
		String[] val =  new String[]{'Name','Target','Prospecting','Response', 'Actionable Response','Qualifying','Connected', 'Relevant', 'Buyer', 'MQL', 'SAL', 'SQL', 'Customer'};
		Map<Id, Task> testMap = new Map<Id, Task>([Select Id, whoId, xTask_Status__c from Task where OwnerId = :userinfo.getuserId() AND Status IN ('Not Started', 'In Progress') ]); 
			for (Contact con :contacts){
				tr = new TableRow();
				tr.Name = con.Account.Name + ': '+ con.Name;
				tr.Stage = con.Stage__c;
				tr.stars = con.scoring_prospect_level_stars__c;
				tr.overTsk = TQC.abc(con.id, testMap.values());
				tr.schedTsk = TQC.bbc(con.id, testMap.values());
				RowList.add(tr); 
			}
			for (Lead led : leads){
				tr = new TableRow();
				tr.Name =led.Company + ': '+ led.Name;
				tr.Stage = led.Stage__c; 
				tr.overTsk = TQC.abc(led.id, testMap.values());
				tr.schedTsk = TQC.bbc(led.id, testMap.values());
				RowList.add(tr);
			}
		return RowList;
		
    }
}

Class:  
public with sharing class TskQueryClass {
  
    Public Static List<Task> myTaskList= New List<Task>();
    Public Static Integer t6, t7;
		

    
    public List<Task> returnmyTasks(){
    	myTaskList =[Select id, ActivityDate, WhoId,xTask_Status__c  from Task where OwnerId = :userinfo.getuserId() AND Status IN ('Not Started', 'In Progress') AND Subject IN ('New lead', 'Contact Request')];
    	return myTaskList;
    }
    
    public Integer abc(id ID, List<Task> Tazk){
    	List<id> op = new List<Id>();
    	for (Task t : Tazk){
    		if(t.whoId == ID && t.xTask_Status__c == 'Pastdue') op.add(t.whoId);
    	}
    	t6=op.size();
    	op.clear();
    	return t6;
    }
    public Integer bbc(id ID, List<Task> Tazk){
    	List<id> op2 = new List<Id>();
    	for (Task t : Tazk){
    		if(t.whoId == ID && t.xTask_Status__c == 'Scheduled') op2.add(t.whoId);
    	}
    	t7=op2.size();
    	op2.clear();
    	return t7;
    }
}

Thank you in advance!
I am very new to apex development but I have created a class for whenever scrum team is created,
the trigger looks up via account, gathers the account id, queries salesforce to get all contact id related to account id, and shares team record. The class is like so
ScrumTeamSharing
trigger ScrumTeamSharing on agf__ADM_Scrum_Team__c(before insert) {
	if (trigger.isInsert) {
//teamid=a6PA0000000J1AdMAK
//agf__ADM_Scrum_Team__c.Account_ID__c = associated account;
//agf__ADM_Scrum_Team__c.Id = team id;
		List <agf__ADM_Scrum_Team__Share> rShare = new List <agf__ADM_Scrum_Team__Share>();
		agf__ADM_Scrum_Team__Share TeamShare;

		for(agf__ADM_Scrum_Team__c ADM : Trigger.new){
			TeamShare = new agf__ADM_Scrum_Team__Share();
			String IdTeam = ADM.Id;
			String assAcc = ADM.Account_ID__c;

			List<Account> alist = [SELECT Id, Name FROM Account WHERE Id=:assAcc];

			System.debug('a' + alist);

			List<Contact> clist = [SELECT Id, Name FROM Contact WHERE Contact.AccountId IN :alist];

			System.debug('c' + clist);
			
			// Set ID of record being shared
			TeamShare.ParentId = ADM.Id;

			// Set ID of user or group being granted access

			// Set Access Level
			TeamShare.AccessLevel = 'Read';

			//Parse contact Id into the sharing list
			Integer i = clist.size();
			while(i > 0) {
				TeamShare.UserOrGroupId = clist[i].Id;//add to the team reports
				i--;
					}
				}

					// Insert the sharing record and capture the save result. 
		      // The false parameter allows for partial processing if multiple records passed 
		      // into the operation.
		      Database.SaveResult sr = Database.insert(TeamShare,false);

		      // Process the save results.
		      if(sr.isSuccess()){
		         // Indicates success
		         System.debug('Save Success');
		      }
		      else {
		         // Get first save result error.
		         Database.Error err = sr.getErrors()[0];
		         
		         // Check if the error is related to trival access level.
		         // Access level must be more permissive than the object's default.
		         // These sharing records are not required and thus an insert exception is acceptable. 
		         if(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION  &&  
		                  err.getMessage().contains('AccessLevel')){
		            // Indicates success.
		            System.debug('Success on mapping error');
		         }
		         else{
		            // Indicates failure.
		            System.debug('Failed to map error');
		         }
		    }	
		}
	}
My test class is as follows
ScrumTeamSharingTest
@isTest 
private class ScrumTeamSharingTest {
	
	@isTest static void testTeamSharing() {
		//create contact for test
		List<Contact> users = new List<Contact>();
		agf__ADM_Scrum_Team__c t = new agf__ADM_Scrum_Team__c();
		Account a = new Account(Name='Test Account');
		t.Name='testTeam';
		t.Account_ID__c=a.Id;
		insert a;
		insert t;
		System.debug('Inserted team & acct: ' + t.Name + ' ' + a.Name);
		for (Integer j=0; j<5;j++) { //j number of contacts per account
			users.add(new Contact(firstname ='Test'+j,
								  lastname  ='Test'+j,
								  AccountId =a.Id));
		}
		insert users;
		}
}
And when it runs the error which I am recieving is like so
Error
ScrumTeamSharingTest: (0/1) Passed

 METHOD RESULT 
testTeamSharing : Fail

 STACK TRACE 
Class.ScrumTeamSharingTest.testTeamSharing: line 11, column 1

 MESSAGE 
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, DedupeReminder: execution of AfterInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []

Trigger.DedupeReminder: line 7, column 1: []
Hello Developers,
Need your thoughts/help..
I have a trigger on child object which updates check box on contact as True on creation of child. (This happens in below trigger)
But it doesn't allow me to delete the child for that contact anymore.
Trigger CrossObjectContactUpdate on Merchandise__C(after delete, after insert, after update){


    List<Merchandise__c> Merch = New List<Merchandise__C>();
    List<Contact> Con = New List<Contact>();
    Set<ID> ConID = New Set<ID>();
        
    for(Merchandise__c M: Trigger.New)
    {
       ConId.add(M.Individual_Customer__C);
    }
    Boolean T = True;
    
    Contact Con1 = [Select X_CrossObj__c From Contact Where ID IN: ConID];
    for(Merchandise__C MC: Trigger.New)
    {    
        Con1.X_CrossObj__c = T;
    }
    update Con1;
    
}

This trigger is created to just update the record of parent. So my other triggers can fire. So, having checkbox checked or not checked don't really matter. Its all about update.
Thank You!

Well, one more Q) Can we update parent record (just update) when child is created, deleted, updated etc.. with process builder? IF yes, then I can take that path instead of trigger above.
Thank you guys for help!
 
I'm trying to create a trigger that will Sum Contacts at the Account Level when the Contact Type = Owner.  I want to take that number increate it by 1 and add an 's' to the front of it and populate it on an Account Level Field called TAFS_General_Manager_tag__c.  

The problem I'm having is comparing the string field to the integer in my trigger.  How can I create an integer to use in the trigger?  My trigger is listed below.  So the end result I want to place in the TAFS_General_Manager_tag__c will be 's' + (sum of contacts with a type of Owner +1)



trigger ContactSumTrigger on Contact (after delete, after insert, after undelete, 
after update) {

    Contact[] cons;
    if (Trigger.isDelete) 
        cons = Trigger.old;
    else
        cons = Trigger.new;

    // get list of accounts
    Set<ID> acctIds = new Set<ID>();
    for (Contact con : cons) {
            acctIds.add(con.AccountId);
    }
    
    Map<ID, Contact> contactsForAccounts = new Map<ID, Contact>([select Id
                                                            ,AccountId
                                                            from Contact
                                                            where AccountId in :acctIds and TAFS_Contact_Type__c = 'Owner']);

    Map<ID, Account> acctsToUpdate = new Map<ID, Account>([select Id
                                                                 ,TAFS_General_Manager_tag__c
                                                                  from Account
                                                                  where Id in :acctIds]);
                                                                 
    for (Account acct : acctsToUpdate.values()) {
        Set<ID> conIds = new Set<ID>();
        for (Contact con : contactsForAccounts.values()) {
            if (con.AccountId == acct.Id)
                conIds.add(con.Id);
        }
        if (acct.TAFS_General_Manager_tag__c != conIds.size())
            acct.TAFS_General_Manager_tag__c = 's' + conIds.size();
    }

    update acctsToUpdate.values();

}