You need to sign in to do that
Don't have an account?
cher
Concatenating strings via apex trigger
Hi
I have child object "Relationship" related to Account. There is field on the Account "Relationship__c", in this field i want to auto populate concatenated values of distinct createdbyIds for each relationship record.
For instace, if the createdbyids for relationship records pertaining to an account "A" are A1, B1, C1. Then the Relationship field on the Account should be populated with A1;B1;C1.
Let me know if this is possible by apex triiger.
I have child object "Relationship" related to Account. There is field on the Account "Relationship__c", in this field i want to auto populate concatenated values of distinct createdbyIds for each relationship record.
For instace, if the createdbyids for relationship records pertaining to an account "A" are A1, B1, C1. Then the Relationship field on the Account should be populated with A1;B1;C1.
Let me know if this is possible by apex triiger.
If this helps,please mark it as best answer to help others :)
Hi Vinit,
Thanks for your response.
The trigger is on the relationship object, when a relationship record is inserted/deleted/updated the change should be reflected on the "Relationship__c" field on the Account Object.
Based on the idea you gave, i have modified the code but the problem is createdbyids are being overwritten in the "Relationship__c" field on the Account object. when ever a new relaitonship record is created i want the createdbyids to be appended. For instance if a relationship record was created by A, then the value in the relationship field should be A.
Now, if a new relationship record, is created for the same account by a B, then the value in the relaitonship field should be A : B.
Let me know if this is possible to achive. I am posting my code below :
trigger Test on Relationship__c (after delete, after insert, after update) {
Account AccountList=[Select Id,Relationships__c from Account];
List<Relationship__c> LevelOfRelationship=new List<Relationship__c>([Select CreatedById
from Relationship__c
where System_SAM__c IN: AccountList]);
List<String> levstring=new List<String>();
for(Relationship__c k: Trigger.old){
for(integer i=0;i<LevelOfRelationship.size();i++){
levstring.add(k.CreatedById);
if(LevelOfRelationship[i]!=null) {
s = String.join(levstring,';');
AccountList.Relationships__c=s;
}
}
update AccountList;
}
If this helps,please mark it as best answer to help others :)