• anonymousXYZ
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
While iteration through a list in for loop, I noticed value is changed for the list without updating it. In the below code list 'cUser' should store same value for any iteration but here it is changing when a 'for' local variable is updated with new value, and same change is reflecting in the List 'listContact'

Please help me to understand what I am doing wrong.

Scenario :
Insert a new contact with the below details(contact standard fields) and run the below mentioned code in 'Execute Anonymous Window'
fistname='fname'
lastname='LastNameTest'
 
String str='LastNameTest';
List <Contact> listContact = new List <Contact>();
List<Contact> cUser = [Select id, firstname,lastname from Contact where lastname = :str];
for(integer i=0;i<2;i++){
    system.debug('** i='+i+'  ** cUser **  ' + cUser);
	for(Contact conTemp : cUser){
        if(i==0){
            system.debug('** if- before **' + conTemp);
            conTemp.firstname = 'abc';
            listContact.add(conTemp);
            system.debug('** if - after **' + conTemp);
        }
        else if(i==1){ 
            system.debug('## else-if-before ##' + conTemp);
            conTemp.firstname = 'xyz';
            listContact.add(conTemp);
            system.debug('## else-if-after ##' + conTemp);
        } 
     }
	system.debug('listContact = '+listContact);
}
                            

Actual Output : 

User-added image

01:30:10:009 USER_DEBUG [5]|DEBUG|** i=0  ** cUser **  (Contact:{Id=0030I00001q6J8QQAU, FirstName=fName, LastName=LastNameTest})
01:30:10:009 USER_DEBUG [8]|DEBUG|** if- before **Contact:{Id=0030I00001q6J8QQAU, FirstName=fName, LastName=LastNameTest}
01:30:10:009 USER_DEBUG [11]|DEBUG|** if - after **Contact:{Id=0030I00001q6J8QQAU, FirstName=abc, LastName=LastNameTest}
01:30:10:009 USER_DEBUG [20]|DEBUG|listContact = (Contact:{Id=0030I00001q6J8QQAU, FirstName=abc, LastName=LastNameTest})
01:30:10:009 USER_DEBUG [5]|DEBUG|** i=1  ** cUser **  (Contact:{Id=0030I00001q6J8QQAU, FirstName=abc, LastName=LastNameTest})
01:30:10:009 USER_DEBUG [14]|DEBUG|## else-if-before ##Contact:{Id=0030I00001q6J8QQAU, FirstName=abc, LastName=LastNameTest}
01:30:10:010 USER_DEBUG [17]|DEBUG|## else-if-after ##Contact:{Id=0030I00001q6J8QQAU, FirstName=xyz, LastName=LastNameTest}
01:30:10:010 USER_DEBUG [20]|DEBUG|listContact = (Contact:{Id=0030I00001q6J8QQAU, FirstName=xyz, LastName=LastNameTest}, Contact:{Id=0030I00001q6J8QQAU, FirstName=xyz, LastName=LastNameTest})

Expected output::
01:30:10:009 USER_DEBUG [5]|DEBUG|** i=0  ** cUser **  (Contact:{Id=0030I00001q6J8QQAU, FirstName=fName, LastName=LastNameTest})
01:30:10:009 USER_DEBUG [8]|DEBUG|** if- before **Contact:{Id=0030I00001q6J8QQAU, FirstName=fName, LastName=LastNameTest}
01:30:10:009 USER_DEBUG [11]|DEBUG|** if - after **Contact:{Id=0030I00001q6J8QQAU, FirstName=abc, LastName=LastNameTest}
01:30:10:009 USER_DEBUG [20]|DEBUG|listContact = (Contact:{Id=0030I00001q6J8QQAU, FirstName=abc, LastName=LastNameTest})
01:30:10:009 USER_DEBUG [5]|DEBUG|** i=1  ** cUser **  (Contact:{Id=0030I00001q6J8QQAU, FirstName=fName, LastName=LastNameTest})
01:30:10:009 USER_DEBUG [14]|DEBUG|## else-if-before ##Contact:{Id=0030I00001q6J8QQAU, FirstName=fName, LastName=LastNameTest}
01:30:10:010 USER_DEBUG [17]|DEBUG|## else-if-after ##Contact:{Id=0030I00001q6J8QQAU, FirstName=xyz, LastName=LastNameTest}
01:30:10:010 USER_DEBUG [20]|DEBUG|listContact = (Contact:{Id=0030I00001q6J8QQAU, FirstName=abc, LastName=LastNameTest}, Contact:{Id=0030I00001q6J8QQAU, FirstName=xyz, LastName=LastNameTest})
While iteration through a list in for loop, I noticed value is changed for the list without updating it. In the below code list 'cUser' should store same value for any iteration but here it is changing when a 'for' local variable is updated with new value, and same change is reflecting in the List 'listContact'

Please help me to understand what I am doing wrong.

Scenario :
Insert a new contact with the below details(contact standard fields) and run the below mentioned code in 'Execute Anonymous Window'
fistname='fname'
lastname='LastNameTest'
 
String str='LastNameTest';
List <Contact> listContact = new List <Contact>();
List<Contact> cUser = [Select id, firstname,lastname from Contact where lastname = :str];
for(integer i=0;i<2;i++){
    system.debug('** i='+i+'  ** cUser **  ' + cUser);
	for(Contact conTemp : cUser){
        if(i==0){
            system.debug('** if- before **' + conTemp);
            conTemp.firstname = 'abc';
            listContact.add(conTemp);
            system.debug('** if - after **' + conTemp);
        }
        else if(i==1){ 
            system.debug('## else-if-before ##' + conTemp);
            conTemp.firstname = 'xyz';
            listContact.add(conTemp);
            system.debug('## else-if-after ##' + conTemp);
        } 
     }
	system.debug('listContact = '+listContact);
}
                            

Actual Output : 

User-added image

01:30:10:009 USER_DEBUG [5]|DEBUG|** i=0  ** cUser **  (Contact:{Id=0030I00001q6J8QQAU, FirstName=fName, LastName=LastNameTest})
01:30:10:009 USER_DEBUG [8]|DEBUG|** if- before **Contact:{Id=0030I00001q6J8QQAU, FirstName=fName, LastName=LastNameTest}
01:30:10:009 USER_DEBUG [11]|DEBUG|** if - after **Contact:{Id=0030I00001q6J8QQAU, FirstName=abc, LastName=LastNameTest}
01:30:10:009 USER_DEBUG [20]|DEBUG|listContact = (Contact:{Id=0030I00001q6J8QQAU, FirstName=abc, LastName=LastNameTest})
01:30:10:009 USER_DEBUG [5]|DEBUG|** i=1  ** cUser **  (Contact:{Id=0030I00001q6J8QQAU, FirstName=abc, LastName=LastNameTest})
01:30:10:009 USER_DEBUG [14]|DEBUG|## else-if-before ##Contact:{Id=0030I00001q6J8QQAU, FirstName=abc, LastName=LastNameTest}
01:30:10:010 USER_DEBUG [17]|DEBUG|## else-if-after ##Contact:{Id=0030I00001q6J8QQAU, FirstName=xyz, LastName=LastNameTest}
01:30:10:010 USER_DEBUG [20]|DEBUG|listContact = (Contact:{Id=0030I00001q6J8QQAU, FirstName=xyz, LastName=LastNameTest}, Contact:{Id=0030I00001q6J8QQAU, FirstName=xyz, LastName=LastNameTest})

Expected output::
01:30:10:009 USER_DEBUG [5]|DEBUG|** i=0  ** cUser **  (Contact:{Id=0030I00001q6J8QQAU, FirstName=fName, LastName=LastNameTest})
01:30:10:009 USER_DEBUG [8]|DEBUG|** if- before **Contact:{Id=0030I00001q6J8QQAU, FirstName=fName, LastName=LastNameTest}
01:30:10:009 USER_DEBUG [11]|DEBUG|** if - after **Contact:{Id=0030I00001q6J8QQAU, FirstName=abc, LastName=LastNameTest}
01:30:10:009 USER_DEBUG [20]|DEBUG|listContact = (Contact:{Id=0030I00001q6J8QQAU, FirstName=abc, LastName=LastNameTest})
01:30:10:009 USER_DEBUG [5]|DEBUG|** i=1  ** cUser **  (Contact:{Id=0030I00001q6J8QQAU, FirstName=fName, LastName=LastNameTest})
01:30:10:009 USER_DEBUG [14]|DEBUG|## else-if-before ##Contact:{Id=0030I00001q6J8QQAU, FirstName=fName, LastName=LastNameTest}
01:30:10:010 USER_DEBUG [17]|DEBUG|## else-if-after ##Contact:{Id=0030I00001q6J8QQAU, FirstName=xyz, LastName=LastNameTest}
01:30:10:010 USER_DEBUG [20]|DEBUG|listContact = (Contact:{Id=0030I00001q6J8QQAU, FirstName=abc, LastName=LastNameTest}, Contact:{Id=0030I00001q6J8QQAU, FirstName=xyz, LastName=LastNameTest})
I am using the outbound messaging scenario, wherin an outbound message is triggered on accomplishment of a 'workflow rule'. 
It is working fine and the opportunity records are sent to my web service and the acknowledgement is sent back to Salesforce.
My question is that wont there be any security concerns since no login parameters/ credentials were used while logging into the server that hosts my webservice. Moreover, while the acknowledgement was sent back to Salesforce, there too there is no such security application.
Please guide me on the following:
How does salesforce manages secutiry in outbound messaging?
Do I need to opt for some other way of communication which is more secure?
Am I missing something and there is an option to apply security parameters in outbound messaging as well?

Hi All,

 

I need some help to figure out a solution to this issue.  We have Annual Revenue field on the Account record.  I want to be able to calcualate the sum of Annual Revenue from all the child Accounts + the Annual Revenue of the Parent Account.  I want the sum value to be on the Parent Account record.  Also, we have some accounts that have more than 1 level of hierarchy.  

 

Account A

    > Account B

     > Account C

              >  Account D

 

If you have any sample codes to share, I'd appreciate it.  Thanks in advance.  

 

  • February 01, 2013
  • Like
  • 0