+ Start a Discussion
Norm CopelandNorm Copeland 

hard code username in trigger?

Hi, I've written a trigger and test class that will send out an email using the app SDocs (https://appexchange.salesforce.com/listingDetail?listingId=a0N30000003HeuPEAS).

It works perfectly when I code the trigger to use the running user (per Sdocs' examples) but we only have a limited number of sdocs licenses and so I'd like to set it to run using my username. According to the sdocs documentation (http://me2systemsllc.com/doc_category/s-docs-rest-api/) this is possible however SDocs only gives an example that grabs the username of the record owner. I'd like this trigger to always use the username one particular user. Here's what I have: 
 
trigger sendAdvocateAcceptanceNoticeReception on Program_Application__c (before update) {
	for (Program_Application__c l : Trigger.new){
		if (l.Send_Advocate_Notice_Reception__c){
			SDOC.SDBatch.CreateSDoc('norm_copeland@ntm.org.sandbox','id='+l.id+'&Object=Program_Application__c&doclist=a1d630000004DgQ&oneclick=1&sendEmail=1');
			l.Send_Advocate_Notice_Reception__c=false;
		}
	}
}


If you're at all familiar with SDocs I'd appreciate the help. Thank you! 
@Karanraj@Karanraj
You can't run a trigger code in a particular user context mode. Instead of trigger approach, try with the REST API functionality to connect the SDocs. While authenticating to the SDocs always use the licensed user credential  to login into SDocs and perform your operation.