0

I want to automate the docusign button when the field status is "pending" in object Product.

Please note i will put the logic in class and make it right , i just wanted to check if this will work first.it isn't at the moment, please help.

trigger IDP_productEnvelope on product__c (after insert , after update) {
    list<dsfs__DocuSign_Envelope__c> lstdsfsenv = new list<dsfs__DocuSign_Envelope__c>();

        list<dsfs__DocuSign_Envelope_Recipient__c> lstdsfsrec = new list<dsfs__DocuSign_Envelope_Recipient__c>();

        list<dsfs__DocuSign_Envelope_Document__c> lstdsfsdoc = new list<dsfs__DocuSign_Envelope_Document__c>();

    for (product__c product : Trigger.new) {


        if (trigger.isupdate){
        if(Product.Status__c!=null){
            if (Trigger.oldMap.get(product.Id).Status__c!=Trigger.newMap.get(product.Id).Status__c && product.Status__c.equals('Pending')) {

                dsfs__DocuSign_Envelope__c dsfsenv = new dsfs__DocuSign_Envelope__c();
                 dsfsEnv.dsfs__DocuSign_Email_Subject__c = 'This is a Test Check subject';
                lstdsfsenv.add(dsfsenv);

                dsfs__DocuSign_Envelope_Recipient__c dsfsrec = new dsfs__DocuSign_Envelope_Recipient__c();
                dsfsrec.dsfs__DocuSign_EnvelopeID__c = dsfsenv.id;
                lstdsfsrec.add(dsfsrec);


            }
        }
    }

     if (trigger.isinsert){
        if(Product.Status__c!=null){
            if (Product.Status__c.equals('Pending')) {

                dsfs__DocuSign_Envelope__c dsfsenv = new dsfs__DocuSign_Envelope__c();
                 dsfsEnv.dsfs__DocuSign_Email_Subject__c = 'This is a Test Check subject';
                lstdsfsenv.add(dsfsenv);

                dsfs__DocuSign_Envelope_Recipient__c dsfsrec = new dsfs__DocuSign_Envelope_Recipient__c();
                dsfsrec.dsfs__DocuSign_EnvelopeID__c = dsfsenv.id;
                lstdsfsrec.add(dsfsrec);
            }
        }
    }
    }    
    insert lstdsfsenv;
  insert lstdsfsrec;
}

I intend to add docusign document object as well but as of now it is not compiling as it shows required field missing in recipient object which i checked on the layout page,the one and only field subject is being used by me.What is the issue, if anyone has worked on in please advice.Thanks

1 Answer 1

0

Basically, you have a lot of problems with misspelled and undeclared variables.

A few examples:

    if(Policy.IDP_PolicySubStatus__c!=null){

You haven't declared Policy, so there's nothing to reference.

    if (Product.Status__c.equals('Pending')) {

You haven't declared Product (but you did declare pproduct), but there's actually a classic system object (canonically, Schema.Product), so it's complaining about not being able to find some fields; even if it did, it wouldn't work as you expect, because you're actually referencing a static field reference and not a record.

As an aside, don't use the equals method; it can throw exceptions if there's null values. Instead, just use ==, as in:

    if (pproduct.Status__c == 'Pending') {

Which is easier to read, less typing, and most importantly, won't throw exceptions when Status__c is null.

1
  • Thanks for the reply, Always a delight to get answered from you. I ll keep the equal point noted. Although yes the misspelling were there, but sadly it was my bad as it was only here misspelled, everything is alright in the trigger itself.I have made the changes , Thanks again.
    – Niknit
    May 27, 2018 at 22:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .