Skip to main content
Veeva Support US Holiday: Jul 4th - Limited staff, please plan accordingly

Community

Search

Welcome to Community

Class initialization are not allowed in SDK code

Answered

Comments

4 comments

  • Official comment
    Isak Thomas

    Hi Deepu,

    There seem to be some variables that are being declared incorrectly in your trigger. Here are some examples for setting up a record trigger:
    https://repo.veevavault.com/javadoc/vault-sdk-api/21.3.0/docs/api/com/veeva/vault/sdk/api/data/package-summary.html

  • Deepu Kumar

    Hi Isak Thomas,

    Thank you for the responce. Below sample code I am referring

    @RecordTriggerInfo(object = "test", events = {RecordEvent.AFTER_UPDATE})
    public class Notification implements RecordTrigger {


       public final LogService logService = ServiceLocator.locate(LogService.class);
        public void execute (RecordTriggerContext recordTriggerContext){

            for (RecordChange inputRecord : recordTriggerContext.getRecordChanges()) {
                try {
                    Record r = inputRecord.getNew();
                    Record o = inputRecord.getOld();
                    String event_type =o.getValue("object_type__v", ValueType.STRING);
                    String EventNumber =r.getValue("name__v", ValueType.STRING);
                    String eventId =o.getValue("id", ValueType.STRING);
                   
                   if(event_type.equals("xyz")){
                        String old_lead = o.getValue("lead__c", ValueType.STRING);
                        String new_lead = r.getValue("lead__c", ValueType.STRING);
                        logService.info("Event Triggered for test Object Record");

                        if (!old_lead.equals(new_lead)) {
                            Notification qe=new Notification();
                            qe.notificationSendAudit(new_lead, EventNumber, eventId);
                        }
                    }

                    else {
                        same to another object
                    }
                }catch (RollbackException re){
                    logService.info("Exception occurred while sending the notification: "+re.getMessage());
                }
            }
        }

    0
  • Isak Thomas

    Hi Deepu,

    You don't need to declare the LogService as public or final. It also needs to be declared and instantiated within the execute() method. So it should look like this:

    public void execute (RecordTriggerContext recordTriggerContext){
    LogService logService = ServiceLocator.locate(LogService.class);
            for (RecordChange inputRecord : recordTriggerContext.getRecordChanges()) {

    Another suggestion that I have is to have most, if not all, of your logic placed within User-Defined Service methods. This can help prevent hitting the memory limits within the transaction. Here is a good article that expands on why you should use User Defined Services:

    https://support.veeva.com/hc/en-us/articles/360056890973

    0
  • Deepu Kumar

    Hi Isak Thomas,

     

    Thank you so much for your quick help

    0

Please sign in to leave a comment.

Powered by Zendesk