function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
UrvikUrvik 

Apex Trigger Connection User

Hi,
How do I fire trigger only when a record is created by Connection User in salesforce to salesforce integration. i.e. We have SF2SF integration and a trigger updates certain lookup fields but I want to fire that trigger only when a record is created by connection user. I tried CreatedById = '[Id of the connection user] ' but that did not work. Please assist.

Thanks
UT
sandeep sankhlasandeep sankhla
Hi rick,

is there any way to identify the user if that is connection user ? if yes then let the trigger fire but you proceed the trigger only for connection users...

Thanks,
Sandeep
UrvikUrvik
yes when a record gets created using SF2SF, the created by field shows "Connection User" and I have an id of this user as well but when I put condition in my trigger "CreatedById = ['ID'], it doesnt work.
sandeep sankhlasandeep sankhla
Hi rick,

can you paste your code here..

you can simply check if user is 'connection user' then only it should proceed further else not...
 
UrvikUrvik
Here is the trigger I am working on. It should fire only when the record is created by connection user.
----
trigger UpdateLookup on Manager__c (before insert, before update) {
try {
set<string> rtset = new set<string>();
for (Manager__c inq : trigger.new) {
rtset.add(inq.Record_Type__c);
}
Map<string,id> nameidmap = new Map<string,id>();
for(RecordType rt :[Select id,DeveloperName from RecordType Where DeveloperName in :rtset]){
for(string str :rtset ){
if(rt.DeveloperName==str){
nameidmap.put(str,rt.id);
}
}
}
for (Manager__c inq : trigger.new) {
if(inq.CreatedById=='005A0000001E5rmIAC'){
inq.RecordTypeId= nameidmap.get(inq.Record_Type__c);
}
 }
} catch(Exception e) { 
 }
}
sandeep sankhlasandeep sankhla
Hi rick,

You can create a formula field on Manager object , which will check if createdBy.username is 'Connection user' then it will return true else false..

use formula like this: if( CreatedBy.Username == 'c', true, false)

now when your trigger fires that time you can simply check if this formula field is true then you can collect that record else not..and then you can perform your opertaion on all manager objects where this field is true..

Please implement this and let me know if this solves your issue..

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer