• Zoom_V
  • NEWBIE
  • 210 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 97
    Questions
  • 160
    Replies
I am attempting to automate the deactivation of User accounts for terminated employees. In order to streamline the process I am attempting to use Email Services to kick off some code which will look up an account and mark it deactivated upon receiving an email with "Termination" in the subject and the employee ID in the body. 

Here is some code I have which I cannot get to work : 
 
global class InboundEmailHandler implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
        if ( email.subject == 'Termination' ) {
            TerminateController.getInstance().terminate(email.plainTextBody);
        }
        return result;
    }
}
 
public class TerminateController() {
     @TestVisible private static final TerminateController INSTANCE = new TerminateController();
    public static TerminateController getInstance() {
        return INSTANCE;
    }
    public void terminate(String commaSeparatedString) {
        String[] employeeids = commaSeparatedString.split(',');
        List<User> users = [SELECT isActive FROM User WHERE employee_Id__c IN: employeeids and isActive = true];
        for ( User u : users ) {
            u.isActive = false;
        }
        update users;
    }

I can't get the controller to save properly. I continuously get an error : "expecting left curly bracket, found '(' at line 1 column 32 "

Any ideas on this ? 

Thank you.
  • November 17, 2016
  • Like
  • 0
I am attempting to write test code for this controller. What I've written only covers 9% of the code. Can anybody tell what I'm doing wrong ? 

Here is the controller :
 
public class UploadAttachControllerVendProdRev {
    
    public String selectedType {get;set;}
    public Boolean selectedAwesomeness {get;set;}
    public String description {get;set;}
    private Vendor_Product_Review__c contact {get;set;} 
    public String fileName {get;set;}
    public Blob fileBody {get;set;}
    public Vendor_Product_Review_Attachment__c objBVar{get;set;}
    
    public String contactproduct {get;set;}
    
    public UploadAttachControllerVendProdRev(ApexPages.StandardController controller) { 
        this.contact = (Vendor_Product_Review__c)controller.getRecord();
        
        objBVar = new Vendor_Product_Review_Attachment__c (Vendor_Product_Review__c = this.contact.id);
     
    }   
    
    // creates a new Vendor_Product_Review_Attachment__c record
    
    private Database.SaveResult saveCustomAttachment() {
   
                
        //Vendor_Product_Review_Attachment__c obj = new Vendor_Product_Review_Attachment__c();
        
        objBVar.Vendor_Product_Review__c = contact.Id; 
        objBVar.Vendor_Profile__c = contact.Vendor__c;
        objBVar.Vendor_Product__c = contact.Vendor_Product__c;
        objBVar.Description__c = description;
        objBVar.Document_type__c = selectedType;
       
       
        // fill out cust obj fields
        return Database.insert(objBVar);
        
    }
    
    // create an actual Attachment record with the Vendor_Product_Review_Attachment__c as parent
    
                
    private Database.SaveResult saveStandardAttachment(Id parentId) {
     
        Database.SaveResult result;
        
        Attachment attachment = new Attachment();
        attachment.body = this.fileBody;
        attachment.name = this.fileName;
        attachment.parentId = parentId;
        // insert the attahcment
        result = Database.insert(attachment);
        // reset the file for the view state
        fileBody = Blob.valueOf(' ');
        return result;
    }
    
    /**
    * Upload process is:
    *  1. Insert new Vendor_Product_Review_Attachment__c record
    *  2. Insert new Attachment with the new Vendor_Product_Review_Attachment__c record as parent
    *  3. Update the Vendor_Product_Review_Attachment__c record with the ID of the new Attachment
    **/
    public PageReference processUpload() {
    
        if(description =='' & filebody==null)
                {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 
                'You must include either a File or a Note.'));
                    return null;
                }
    
           
        /** if(description !='' & filebody==null)
                {        
                   Database.SaveResult customAttachmentResult = saveCustomAttachment();
                    
                // update the custom attachment record with some attachment info
                Vendor_Product_Review_Attachment__c customAttachment = [select id from Vendor_Product_Review_Attachment__c where id = :customAttachmentResult.getId()];                
                update customAttachment;
                }
         **/   
            
         try {
            Database.SaveResult customAttachmentResult = saveCustomAttachment();
       
            if (!customAttachmentResult.isSuccess()) {
                //ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR,
                  //'Could not save attachment because either filebody was empty or the customAttachmentResult was unsuccessful.'));
                return null;
                system.debug('customattachmentresult **************!!! ');
                return new PageReference('/'+contact.Id);
            }
      
            if (filebody != null) {
                Database.SaveResult attachmentResult = saveStandardAttachment(customAttachmentResult.getId());
           
                if (attachmentResult == null || !attachmentResult.isSuccess()) {
                    //ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR,
                      //'Could not save attachment.'));           
                    //return null;
                    return new PageReference('/'+contact.Id);
                } else {
                    // update the custom attachment record with some attachment info
                    Vendor_Product_Review_Attachment__c customAttachment = [select id from Vendor_Product_Review_Attachment__c where id = :customAttachmentResult.getId()];
                    customAttachment.name = this.fileName;
                    customAttachment.Attachment__c = attachmentResult.getId();
                    update customAttachment;
                }
            }
       } catch (Exception e) {
          ApexPages.AddMessages(e);
          return null;
       }

            return new PageReference('/'+contact.Id);
      }
        
    
    public PageReference back() {
        return new PageReference('/'+contact.Id);
    }     
}

Here is the test code I've written.
 
@isTest(SeeAllData = false)

private class TestUploadAttachControllerVendProdRev

    {    
        static testMethod void UnitTestUploadAttachControllerVendProdRev()
            
             {     
                Department__c dept = new Department__c();
                dept.Name = 'Dept1';
                dept.Department_Manager__c = '005i0000005o3zu';
                insert dept;                
                
                Vendor_Profile__c vprof = new Vendor_Profile__c();
                vprof.Name = 'ABCProf';
                vprof.Department_of_Record__c = dept.id;
                vprof.Department_Manager__c = '005i0000005o3zu';
                insert vprof;
                
                Vendor_Product__c vprod = new Vendor_Product__c();
                vprod.Name = 'ABCProd';
                vprod.Vendor__c = vprof.id;
                vprod.Reviewed_Vendor__c = vprof.id;
                vprof.Department_of_Record__c = dept.id;
                insert vprod;
                
                Vendor_Product__c vprod2 = new Vendor_Product__c();
                vprod2.Name = '123Prod';
                vprod2.Vendor__c = vprof.id;
                insert vprod2;
                
                Vendor_Contract__c vc = new Vendor_Contract__c();
                vc.Vendor__c = vprof.id;
                vc.Products_Included__c = '[ABCProd,123Prod]';
                insert vc ;
            
                Vendor_Product_Review__c vrev = new Vendor_Product_Review__c();
                vrev.Vendor__c = vprof.id;
                vrev.Vendor_Product__c = vprod.id;
                insert vrev ;
           
           
               ApexPages.StandardController sc = new ApexPages.standardController(vrev);
               UploadAttachControllerVendProdRev up = new UploadAttachControllerVendProdRev(sc);
          

             }
    
    }

Any help is appreciated. Thank you !
 
  • September 13, 2016
  • Like
  • 0
I currently have a custom button which I am using to launch a Flow by using a VF page as the source (which in tail launches an Apex Class). It works fine, but I need to put it in a VF page now and I'm not sure how to do that. 

This is the VF page which is the source of the button : 
 
<apex:page StandardController="Product__c" Extensions="New_ProductReview_With_Flow_Controller">
<flow:interview interview="{!myflow}" name="Product_Review" finishlocation="{!finishlocation}"> 
<apex:param name="VarProdRecID" value="{!Product__c.Id}"/>


</flow:interview>
</apex:page>

I'm not how the commandbutton line should be set up in the VF page. Should it be using action = ? Should it all be a URL with a param statement in it ?
  • August 10, 2016
  • Like
  • 0
I have what is essentially a custom Notes & Attachment feature which uses a VF page to give the user the ability to leave a Note of his/her attachment as well as choose a category to put the attachment into using a dropdown picklist (Document_Type__c). 

It works fine, but I would like for a user to be able to just enter something into the Notes__c field - and not be forced to include an attachment. 

As this code is, it will create the new record without the attachment - and then go on to create the attachment and then update the record which was created. I essentially need something which would check to see if there is an attachment after initial creation of the record - and then just ending if there is no attachment, and not attempt to uplaod the file.

I think it would have to come in after this line : 
 
return Database.insert(obj);

I can't figure out how to do that. Here is the full code :
 
public class UploadAttachmentControllerProdRev {
    
    public String selectedType {get;set;}
    public Boolean selectedAwesomeness {get;set;}
    public String Note {get;set;}
    private Product_Review__c contact {get;set;} 
    public String fileName {get;set;}
    public Blob fileBody {get;set;}
    
    public String contactproduct {get;set;}
    
    public UploadAttachmentControllerVendorProdRev(ApexPages.StandardController controller) { 
        this.contact = (Product_Review__c)controller.getRecord();
        //contactproduct = contact.Product__c;
    }   
    
    // creates a new Product_Review_Attachment__c record
    private Database.SaveResult saveCustomAttachment() {
        Product_Review_Attachment__c obj = new Product_Review_Attachment__c();
        obj.Product_Review__c = contact.Id; 
        obj.Product__c = contact.Product__c;
        obj.Note__c = Note;
        obj.Document_type__c = selectedType;
        //obj.awesome__c = selectedAwesomeness;
        // fill out cust obj fields
        return Database.insert(obj);
    }
    
    // create an actual Attachment record with the Product_Review_Attachment__c as parent
    private Database.SaveResult saveStandardAttachment(Id parentId) {
        Database.SaveResult result;
        
        Attachment attachment = new Attachment();
        attachment.body = this.fileBody;
        attachment.name = this.fileName;
        attachment.parentId = parentId;
        // inser the attahcment
        result = Database.insert(attachment);
        // reset the file for the view state
        fileBody = Blob.valueOf(' ');
        return result;
    }
    
    /**
    * Upload process is:
    *  1. Insert new Product_Review_Attachment__c record
    *  2. Insert new Attachment with the new Product_Review_Attachment__c record as parent
    *  3. Update the Product_Review_Attachment__c record with the ID of the new Attachment
    **/
    public PageReference processUpload() {
        try {
            Database.SaveResult customAttachmentResult = saveCustomAttachment();
        
            if (customAttachmentResult == null || !customAttachmentResult.isSuccess()) {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 
                  'Could not save attachment.'));
                return null;
            }
        
            Database.SaveResult attachmentResult = saveStandardAttachment(customAttachmentResult.getId());
        
            if (attachmentResult == null || !attachmentResult.isSuccess()) {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 
                  'Could not save attachment.'));            
                return null;
            } else {
                // update the custom attachment record with some attachment info
                Product_Review_Attachment__c customAttachment = [select id from Product_Review_Attachment__c where id = :customAttachmentResult.getId()];
                customAttachment.name = this.fileName;
                customAttachment.Attachment__c = attachmentResult.getId();
                update customAttachment;
            }
        
        } catch (Exception e) {
            ApexPages.AddMessages(e);
            return null;
        }
        
        return new PageReference('/'+contact.Id);
    }
    
    public PageReference back() {
        return new PageReference('/'+contact.Id);
    }     
}


Thank you for your help. 
  • August 05, 2016
  • Like
  • 0
I am attempting to put a text message just above the buttons of some of the records which will indicate to the user that something is still needed in order to Submit his request. For some reason my text will not center properly. I thought maybe it was because I am trying to do it at the very top of the record, and maybe that was impossible in that section. But I tried moving it to other parts of the record and it wouldn't work either.

Here is the top portion of the VisualForce code which contains my style and outputtext :
 
<apex:page standardcontroller="Product_Review__c">

    <head>     
     <style >
        .italicText 
        { 
            font-style: italic; 
            font-weight: bold
            font-size: 24px;
            text-align:center;
            width :100%;
        }                   
     </style>
    </head>

<apex:messages />

    <apex:sectionheader title="{!$ObjectType.Product_Review__c.label} Detail" subtitle="{!Product_Review__c.Name}"/>
    <chatter:feedwithfollowers entityId="{!Product_Review__c.Id}"/>
    <apex:form >
    <apex:outputtext style="text-align:center; width : 100%;font-size: 16px; font-weight: bold ;  color : #FF0000" value="{!Product_Review__c.Docs_Still_Needed__c}" rendered="{!IF(Product_Review__c.Docs_Still_Needed__c = '', false, true)}" />
        <apex:pageblock mode="maindetail" title="{!$ObjectType.Product_Review__c.label} Detail">
            <apex:pageblockbuttons >
                <apex:commandbutton value="Edit" action="{!Edit}"/>
                <apex:commandbutton value="Delete" action="{!Delete}"/>
                <apex:commandButton value="Submit for Approval" action="{!URLFOR($Action.Product_Review__c.submit, Id)}" id="Submit_for_Approval" rendered="{!IF(Product_Review__c.Status__c = 'Approved', false, true)}"/>

            </apex:pageblockbuttons>

The align:center attribute in the outputtext line is having no effect. The rest of the attributes such as font size and color are working properly.

Any idea what I'm doing wrong here ?

Thank you for your help.
  • August 03, 2016
  • Like
  • 0
This is a weird problem and I don't know if this is the proper forum to pursue an answer. But I tried posting in the customer service forum and did not get a reply.

We have some users who will only get a mirror image of their normal Salesforce interface within their Chatter Desktop client. It does not show the typical Chatter Desktop interface with the Chatter icons on the left and the dropdown at the top which shows "Recently Viewed". Instead it just shows a mirror image of their normal Salesforce login - but all cramped into the Chatter Desktop client.

I've never seen this before. I am looking through their permissions and they have the same permissions and settings as the users who are getting the proper Chatter interface in their Desktop Client.

I went into the Desktop Client settings and I don't see anything which would seem to be relevant to this problem. 

Is there another setting which needs to happen here ? 

One note : Both of these users had their password reset and had to re-login with their Desktop Client using their new password. I don't know if that is relevant or not, but I wanted to mention it. 
  • April 26, 2016
  • Like
  • 0
I have a case in which my users are working on a proposal which needs several different required documents to be attached to it. They would like to be able to have an approval process for each of the documents in order to review the individual document of the proposal when the document is attached. They don't want to have to wait until all of the documents have been attached and the proposal has been submitted as a whole. 

After they have updated one of the documents they will click a checkbox to show they've uploaded it. 

Ultimately, the proposal will be submitted as a whole and it will go through an approval process with that. The person approving the individual parts of the proposal may or may not be the same person who ends up approving the proposal when it is eventually submitted as a whole.

Is this possible ?
  • March 16, 2016
  • Like
  • 0
If one of my requests is for a threshold dollar amount it needs to be seen by an upper manager. However, the manager is not needed to "Approve" the request. The manager is only needed to "acknowledge" that he has seen it. Since the manager is not always available he does not want his interaction to be required and would like the approval process to continue without him. 

What would be the best way to handle this ? I'm thinking of different scenarios which would require different levels of approval and what not, but I think I may be overlooking an easier solution. 

Any help would be appreciated.
  • March 03, 2016
  • Like
  • 0
I have an app which would require a user to submit a request for a change to be made to a record.

The scenario : 

Records show salaries and benefits for employees. A manager would change the dollar amount to the Salary__c field and the number of weeks in the Vacation_Weeks__c field. This would require two different Requests to be produced and Submitted to the proper upper management. The upper management would like the ability to Approve or Reject all of those Requests with one push of a button (an Approve All or Reject All button). 

My tenative solution to this is to use Flow to automatically create a Request Package which is the master record to the individual Requests, which are essentially line items to the Request Package record. The upper management would go into the Request Package record, press the custom Approve All or Reject All button and all of the Requests are updated accordingly. 

My problem : I can properly update the Status field of those individual Requests with those buttons, but since this is not truly "Approving" or "Rejecting" the records it is not producing the Approval History data which goes along with pushing the native Salesforce "Approve/Reject" in an Approval Process.

So, what can be the solution to this ? If there was an "Approve" Static Action in Flow just as there is a "Submit for Approval" Static Action, I would be able to use that. But we don't have that.
  • March 01, 2016
  • Like
  • 0
I have a huge change set which needs to be deployed from a Dev sandbox to a Test sandbox. After each testing there are inevitable changes which need to happen with the code, and therefore a new deployment to the Test sandbox. Since I don't want to re-build the change set every time I need to deploy, I would like to simply Clone the already made and deploy that new "version". 

If I have made changes in the components which were part of the change set before I cloned it will those changes carry over to the new clone "version" of the change set ? Or do I need to re-build that change set from scratch every time I need to deploy the changes to the components ?

Thank you.
  • February 11, 2016
  • Like
  • 0
I am trying to figure out how to write the test code for this VF controller and a Trigger which will work on the same object. I've never written test code before, so I'm quite desperate right now. I'm studying the online help and am not really getting too far. Can anybody help with this ?

This code is creating a junction record between a Regulation__c record and a Vendor_Product__c record. Basically, the class queries each individual selection from a list (selectedvalues). Each selection in the list represents a corresponding Vendor_Product record. The class places them into a multi-valued field (Products_Affected__c) in the Regulations__c object. It queries each value to confirm that it wasn't already added to the field before.

The trigger then takes each value of the Products_Affected__c field, queries it to find the corresponding Vendor_Product__c record, and upserts a new junction record with the Products_Affected_Regulation_Entry__c object.

Here is the Class (VF controller) :
 
public class RegulationsVFControllerEdit {
private final Regulation__c main;
public String rightOptionsHidden { get; set; }
public String leftOptionsHidden { get; set; }
public String selectedMulPickKeyTech{get;set;} 
public string lookupid{get;set;}
public String message { get; set; }
public List<SelectOption> options { get; set; }
public List<SelectOption> selectedSubs2 { get; set; }
public String selectedItems { get; set; }
public String mainid {get;set;}
public String coid {get;set;}    
    public RegulationsVFControllerEdit(apexpages.standardcontroller controller)
        {
        selectedSubs2 = new list<SelectOption>();
        this.main = (Regulation__c) controller.getRecord();
        }

    public pageReference  execute()
        {
        return null;
        }

    public list<selectoption> getitems()
        {
        lookupid=main.Vendor__c;
        mainid=main.id;
        //Set<String> selectedItems = new Set<String>();
        selectedItems=main.Products_Affected__c;
        coid = main.id;
        selectedMulPickKeyTech=main.Products_Affected__c;

        List<selectoption> options= new list<selectoption>();
        if(lookupid != null)
            {
                    if(selectedMulPickKeyTech !=null)
                    {
                    selectedMulPickKeyTech=selectedMulPickKeyTech.replace('[','');                
                    selectedMulPickKeyTech=selectedMulPickKeyTech.replace(']','');

                    String[] selectedvalues = selectedMulPickKeyTech.split(',');
                    System.debug('selectedMulPickKeyTechLine43 ########'+selectedMulPickKeyTech); 
                    System.debug('selectedvaluesLine44 ########'+selectedvalues);         
                    selectedSubs2 = new list<SelectOption>();
                    for (String selectedvalue: selectedvalues) 
                        {
                        selectedSubs2.add(new SelectOption(selectedvalue,selectedvalue));
                        }

                     }   
             System.debug('lookupid ########'+lookupid); 
             System.debug('selectedSubs2Line52 ########'+selectedSubs2);  
             System.debug('selectedMulPickKeyTechLine54 ########'+selectedMulPickKeyTech); 
           Vendor_Profile__c a =[select name , (select name from Vendor_Products__r) from Vendor_Profile__c where id =:lookupid];
                for(Vendor_Product__c s : a.Vendor_Products__r)
                    {
                        //check that selected items dont already contain the keys
                        //if(!selectedItems.contains(s.name))
                    options.add(new SelectOption(s.name,s.name));
                    }
            }

            else
            options.add(new SelectOption('None','None'));
            return options;

        }

    public PageReference save()
        {
        message = null ;       
        Boolean first = true;
        if (selectedSubs2.size() > 0)
            {
           for ( SelectOption so : selectedSubs2 ) 
            {
                if (first) 
                    {
                    message = message ;
                    }
                    message = message + ', ' + so.getValue() ;
                    first = false;
            }   

                message = message.removeStart('null, ');
                message = message.normalizeSpace();
                message = '['+message+']';
                main.Products_Affected__c=message;
                }
        update main;

      System.debug('coid ########'+coid);

      //PageReference pr = new PageReference('/a7w/o');
      PageReference pr = new PageReference('/'+ mainid);

          pr.setRedirect(true);
          return pr;

        }
}

This is the trigger which runs after the record is saved :
 
trigger AutoCreateSubOnRegulation on Regulation__c(after insert,after update)
{
    //Since, we need two values from Regulation__c to be populated on the new Products_Affected_Regulation_Entry__c record.
    //So, taking a Map instead of list. Earlier, List<String> subAccNames=new List<String>();
    //Map of subAccountNames and Regulation__c Record.</b>
    Map<String, Regulation__c> subAccNames=new Map<String, Regulation__c>();

    for(Regulation__c newCont: Trigger.New) 
    {
        //Checking of the field is empty or not.</b>
        if(newCont.Products_Affected__c!=Null && newCont.Products_Affected__c!='') 
        {
            system.debug('newCont.Products_Affected__c---->'+newCont.Products_Affected__c);
            String temp=newCont.Products_Affected__c.normalizeSpace();
            temp=temp.replace(']',''); //No need for this if comma seperated values as I have taken.
            temp=temp.replace('[',''); //No need for this if comma seperated values as I have taken.</b>

            //Iterate the number of values in the temp variable by slitting them by comma
            //add put them in subAccNames</b>
            for(String acctName: temp.split(','))
            {
                subAccNames.put(acctName.normalizeSpace(), newCont);
                system.debug('subAccNames !!! '+subAccNames); 
            }
        }
    }

    //Take a Map of Name and Record for holding Vendor_Product__c Name and Vendor_Product__c Record.</b>
    Map<String, Vendor_Product__c> subAccIdsByName=new Map<String, Vendor_Product__c>();

    //Iterate over the Vendor Product records and create a Map with Venfor Product Id as Key and Vendor Product Record as Value.</b>
    for(Vendor_Product__c subacc: [SELECT Id, Vendor__c, Name FROM Vendor_Product__c WHERE Name IN :subAccNames.keySet()]) 
    {
        //Putting record in place of Id, as value in the map.</b>
        subAccIdsByName.put(subacc.Name, subacc);
        System.debug('subAcc Name and ID='+subacc.Name +'Id='+subacc.id+'Vendor_c='+subacc.Vendor__c);
    }

//&nbsp;   //This will hold the Products_Affected_Regulation_Entry__c records to be upserted.</b>
    List<Products_Affected_Regulation_Entry__c> subs = new List<Products_Affected_Regulation_Entry__c>();

    //Iterating over subAccNames Map.
    //No need to iterate again over Regulation__c records as we have already taken the Regulation__c record in the subAccNames Map.
    //Earlier: for (Regulation__c newContract : Trigger.New)</b>
    for(String ref1: subAccNames.keySet()) 
    {
        //Iterate over the subAccIdsByName Map.</b>
        for(String ref2: subAccIdsByName.keySet())
        {
            //Match if the Name in the subAccNames Map is equal to Name in the subAccIdsByName Map.</b>
            if(ref1==ref2)
            {
                Products_Affected_Regulation_Entry__c ssoc = new Products_Affected_Regulation_Entry__c();
                ssoc.Regulation__c=subAccNames.get(ref1).Id;
                //Access Vendor Product Id from the Map.</b>
                ssoc.Vendor_Product__c=subAccIdsByName.get(ref2).Id;
                //Access Vendor__c from the Map.</b>
                ssoc.Vendor__c=subAccIdsByName.get(ref2).Vendor__c;
                //Access Name from the Map.</b>
                ssoc.Regulation_and_Product__c=subAccNames.get(ref1).Name+'~'+subAccIdsByName.get(ref2).Id;
                //Put the records in the </b>subs </b>list.</b>
                subs.add(ssoc);
            }
        }
    }

    upsert subs Regulation_and_Product__c;
}

Like I said, I'm trying to learn it for myself, but that's going to take some time. I'd appreciate any kind of help I can get. 

Thank you.
  • February 09, 2016
  • Like
  • 0
I am using Flow for a wizard/interview method of creating records. One of the fields is an email address and I am getting errors due to users entering invalid email addresses. 

Does anybody know of an easy way to account for this ? I would need it to be a method which could run within Flow, which rules out Apex. Is there a function/command-based solution for this ? 

Thank you very much.
  • January 27, 2016
  • Like
  • 0
I would like to include a link on the screen whenever a user clicks on a Tab. What would be the best way to accomplish that ? 

Thank you.
  • January 22, 2016
  • Like
  • 0
I would like to include a link to a site on the screen whenever a user clicks on a Tab. What would be the best way to accomplish that ? 
  • January 22, 2016
  • Like
  • 0
I am using a record detail custom button to refer to a Visualforce page which in turn launches a Flow. That Flow then creates a new record. I would like my Finishlocation to be that newly created record. As it is now, I am only able to make the Finishlocation an already created record (such as the record I was in when I pushed the button ; or some other record which is a lookup field on that record).

I am referring to a variable which has the newly created record's ID.

Here is the Visualforce page which the custom button refers to :
 
<apex:page StandardController="Vendor_Product__c" Extensions="New_ProductReview_With_Flow_Controller2">
<flow:interview interview="{!myflow}" name="New_Product_Review" finishlocation="{!finishlocation}"> 
<apex:param name="VarVendProdRecID" value="{!Vendor_Product__c.Id}"/>
<apex:param name="VarVendProfileID" value="{!Vendor_Product__c.Vendor__r.Id}"/>
</flow:interview>
</apex:page>

Here is the controller : 
 
public class New_ProductReview_With_Flow_Controller2 {
     public Id recordId {get;set;}
    public flow.interview.New_Product_Review myflow {get;set;}

    public New_ProductReview_With_Flow_Controller2(ApexPages.StandardController stdController) {
        recordId = ApexPages.currentPage().getParameters().get('recordId');
    } 

    public String getendID() {        
        if (myflow !=null) return myflow.VarNewReviewRecID;
        else return 'home/home.jsp';
    }       

    public PageReference getFinishLocation() {        
        PageReference endlocation = new PageReference('/' + getendID());


        system.debug('VarNewReviewRecIDxxxx '+getendID()); 
        return endlocation;
    }
}

VARNewReviewRecID is a null value in the above debug for some reason, even though it is the Variable populated with the Create Record element in the Flow and I can see it is populated when I look at the debug logs. It is an input/output variable so I would think I could refer to it from Apex.

Any ideas ?
 
  • January 14, 2016
  • Like
  • 1
Another title for this post could have been : "How can I remove the New button from the Recent list view ?"

I don't want my users to be able to use the New button for a certain custom object. I have taken it out of the List Views, but it is still appearing in the Recent list view for that object. 

I can't find a way to get rid of it. The only thing I can think of is to maybe replace the Recent view with a Visualforce page. But how do I do that ? Is that possible ? If so, what would the code be for that ? 

If you know of an easier way to get rid of the New button in a Recent view I would love to hear about it.

Thank you.
  • January 07, 2016
  • Like
  • 0

I have an object (ObjectA) with two Master-Detail fields in it. I am attempting to auto-populate both of those Master-Detail fields whenever I create a new ObjectA record. I am attempting to accomplish this by using Process Builder. However, those Master-Detail fields are not available in the dropdown list of one of the fields to update when I use the Update Records action. 

Why is this ? Am I not able to update Master-Detail fields using Process Builder ? If so, is there a way around this ? 

Thank you.

  • December 29, 2016
  • Like
  • 0
I have what I call Employee Profiles in which each employee has currency fields which are the limits he/she can expense on a business trip. There is a field representing the dollar for their job title, and another field showing the user's dollar amounts. Their dollar limits may or may not be at the limit of their job title.

I am trying to create an Approval Process which will be submitted for a person to request an increase in an employee's limits. Sometimes the request may be above their current job title's limits, sometimes it may not be. I would like the Approval Process to be routed differently if the request is above the job title limit of the employee in question.

How can I put in the logic which will refer to the field on the object to see if the new requested limit is above the job title's limit ? As I see it, I can only put in actual numbers, not references to field values. 

Thank you.
  • December 17, 2015
  • Like
  • 0
I am attempting to use the Email Service address for Replies to certain Email Alerts. But we are unable to use Email Service addresses as Org-Wide addresses, and therefore we cannot use them as the From address on an Email Alert. 

I was going to set up Forwarding in another legitimate email address to be sent to the Email Service address to solve this. I'm using Gmail. But when a Forwarding address is named the system insists on sending a confirmation email to the address named as the Forwarding recipient. Since it's an Email Service address I don't know how to do this. 

Does anybody have any advice on how to accomplish this with an Email Service ? 

Thank you.
  • December 15, 2015
  • Like
  • 0
I have the following class which I am using with an Email Service. I decided to put Today() into one of the fields in the object which would be receiving the InboundEmail, but I am getting a "Compile Error : Method does not exist or incorrect signature : Today()"

Here is the code : 
 
global class VendorEmail implements 
        Messaging.InboundEmailHandler {


Vendor_Notes__c[] NewVendorNotes = new Vendor_Notes__c[0];

 global Messaging.InboundEmailResult handleInboundEmail(
  Messaging.InboundEmail email, 
  Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = 
        new Messaging.InboundEmailresult();
 
  // Captures email info
    
String emailAddress = envelope.fromAddress;
String fName = email.fromname.substring(
        0,email.fromname.indexOf(' '));
String lName = email.fromname.substring(
        email.fromname.indexOf(' '));
String[] emailBody = email.plainTextBody.split('\n', 0);
String phoneNumber = emailBody[0].substring(6);
       
//Associates email to proper Vendor Profile
//var today = new Date(0);  
Vendor_Profile__c venpro;
venpro = [select ID,ACH_Status__c from Vendor_Profile__c where name =
             :email.subject limit 1];
    ID jobId = venpro.ID;
    venpro.Date_of_Latest_Compliance_Certificate__c = Today();
    Update venpro;

try
    {
      NewVendorNotes.add(new Vendor_Notes__c(Sender__c = emailAddress,
      Vendor__c = jobId,
      Routing_Number__c = lName,
     Account_Number__c = phoneNumber
      ));
 
      insert NewVendorNotes;
      
      //Save any Binary Attachment
            
            if (email.binaryAttachments != null)
                {
                    for(Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) 
                    {
                        Attachment attachment = new Attachment();
        
                        attachment.Name = bAttachment.fileName;
                        attachment.Body = bAttachment.body;
                        attachment.ParentId = venpro.Id;
                        insert attachment;
                    }
               } 
   }
    
   catch (System.DmlException e)   
   {
           

            //Save any Binary Attachment
            
            if (email.binaryAttachments != null)
                {
                    for(Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) 
                    {
                        Attachment attachment = new Attachment();
        
                        attachment.Name = bAttachment.fileName;
                        attachment.Body = bAttachment.body;
                        attachment.ParentId = venpro.Id;
                        insert attachment;
                    }
               } 
}
return result;
       
    }
}

Anybody have any ideas ....?

Thank you very much for any help.
  • December 15, 2015
  • Like
  • 0
I am using a record detail custom button to refer to a Visualforce page which in turn launches a Flow. That Flow then creates a new record. I would like my Finishlocation to be that newly created record. As it is now, I am only able to make the Finishlocation an already created record (such as the record I was in when I pushed the button ; or some other record which is a lookup field on that record).

I am referring to a variable which has the newly created record's ID.

Here is the Visualforce page which the custom button refers to :
 
<apex:page StandardController="Vendor_Product__c" Extensions="New_ProductReview_With_Flow_Controller2">
<flow:interview interview="{!myflow}" name="New_Product_Review" finishlocation="{!finishlocation}"> 
<apex:param name="VarVendProdRecID" value="{!Vendor_Product__c.Id}"/>
<apex:param name="VarVendProfileID" value="{!Vendor_Product__c.Vendor__r.Id}"/>
</flow:interview>
</apex:page>

Here is the controller : 
 
public class New_ProductReview_With_Flow_Controller2 {
     public Id recordId {get;set;}
    public flow.interview.New_Product_Review myflow {get;set;}

    public New_ProductReview_With_Flow_Controller2(ApexPages.StandardController stdController) {
        recordId = ApexPages.currentPage().getParameters().get('recordId');
    } 

    public String getendID() {        
        if (myflow !=null) return myflow.VarNewReviewRecID;
        else return 'home/home.jsp';
    }       

    public PageReference getFinishLocation() {        
        PageReference endlocation = new PageReference('/' + getendID());


        system.debug('VarNewReviewRecIDxxxx '+getendID()); 
        return endlocation;
    }
}

VARNewReviewRecID is a null value in the above debug for some reason, even though it is the Variable populated with the Create Record element in the Flow and I can see it is populated when I look at the debug logs. It is an input/output variable so I would think I could refer to it from Apex.

Any ideas ?
 
  • January 14, 2016
  • Like
  • 1
I am using a custom New button in an object to launch a Visualforce page - which then launches a Flow. I would like to capture the Record ID of that record which I am in when I press the button and save the ID to a variable I can use within the Flow which gets launched.

How can I do this ?
  • November 06, 2015
  • Like
  • 1
I am attempting to automate the deactivation of User accounts for terminated employees. In order to streamline the process I am attempting to use Email Services to kick off some code which will look up an account and mark it deactivated upon receiving an email with "Termination" in the subject and the employee ID in the body. 

Here is some code I have which I cannot get to work : 
 
global class InboundEmailHandler implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
        if ( email.subject == 'Termination' ) {
            TerminateController.getInstance().terminate(email.plainTextBody);
        }
        return result;
    }
}
 
public class TerminateController() {
     @TestVisible private static final TerminateController INSTANCE = new TerminateController();
    public static TerminateController getInstance() {
        return INSTANCE;
    }
    public void terminate(String commaSeparatedString) {
        String[] employeeids = commaSeparatedString.split(',');
        List<User> users = [SELECT isActive FROM User WHERE employee_Id__c IN: employeeids and isActive = true];
        for ( User u : users ) {
            u.isActive = false;
        }
        update users;
    }

I can't get the controller to save properly. I continuously get an error : "expecting left curly bracket, found '(' at line 1 column 32 "

Any ideas on this ? 

Thank you.
  • November 17, 2016
  • Like
  • 0
I am attempting to write test code for this controller. What I've written only covers 9% of the code. Can anybody tell what I'm doing wrong ? 

Here is the controller :
 
public class UploadAttachControllerVendProdRev {
    
    public String selectedType {get;set;}
    public Boolean selectedAwesomeness {get;set;}
    public String description {get;set;}
    private Vendor_Product_Review__c contact {get;set;} 
    public String fileName {get;set;}
    public Blob fileBody {get;set;}
    public Vendor_Product_Review_Attachment__c objBVar{get;set;}
    
    public String contactproduct {get;set;}
    
    public UploadAttachControllerVendProdRev(ApexPages.StandardController controller) { 
        this.contact = (Vendor_Product_Review__c)controller.getRecord();
        
        objBVar = new Vendor_Product_Review_Attachment__c (Vendor_Product_Review__c = this.contact.id);
     
    }   
    
    // creates a new Vendor_Product_Review_Attachment__c record
    
    private Database.SaveResult saveCustomAttachment() {
   
                
        //Vendor_Product_Review_Attachment__c obj = new Vendor_Product_Review_Attachment__c();
        
        objBVar.Vendor_Product_Review__c = contact.Id; 
        objBVar.Vendor_Profile__c = contact.Vendor__c;
        objBVar.Vendor_Product__c = contact.Vendor_Product__c;
        objBVar.Description__c = description;
        objBVar.Document_type__c = selectedType;
       
       
        // fill out cust obj fields
        return Database.insert(objBVar);
        
    }
    
    // create an actual Attachment record with the Vendor_Product_Review_Attachment__c as parent
    
                
    private Database.SaveResult saveStandardAttachment(Id parentId) {
     
        Database.SaveResult result;
        
        Attachment attachment = new Attachment();
        attachment.body = this.fileBody;
        attachment.name = this.fileName;
        attachment.parentId = parentId;
        // insert the attahcment
        result = Database.insert(attachment);
        // reset the file for the view state
        fileBody = Blob.valueOf(' ');
        return result;
    }
    
    /**
    * Upload process is:
    *  1. Insert new Vendor_Product_Review_Attachment__c record
    *  2. Insert new Attachment with the new Vendor_Product_Review_Attachment__c record as parent
    *  3. Update the Vendor_Product_Review_Attachment__c record with the ID of the new Attachment
    **/
    public PageReference processUpload() {
    
        if(description =='' & filebody==null)
                {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 
                'You must include either a File or a Note.'));
                    return null;
                }
    
           
        /** if(description !='' & filebody==null)
                {        
                   Database.SaveResult customAttachmentResult = saveCustomAttachment();
                    
                // update the custom attachment record with some attachment info
                Vendor_Product_Review_Attachment__c customAttachment = [select id from Vendor_Product_Review_Attachment__c where id = :customAttachmentResult.getId()];                
                update customAttachment;
                }
         **/   
            
         try {
            Database.SaveResult customAttachmentResult = saveCustomAttachment();
       
            if (!customAttachmentResult.isSuccess()) {
                //ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR,
                  //'Could not save attachment because either filebody was empty or the customAttachmentResult was unsuccessful.'));
                return null;
                system.debug('customattachmentresult **************!!! ');
                return new PageReference('/'+contact.Id);
            }
      
            if (filebody != null) {
                Database.SaveResult attachmentResult = saveStandardAttachment(customAttachmentResult.getId());
           
                if (attachmentResult == null || !attachmentResult.isSuccess()) {
                    //ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR,
                      //'Could not save attachment.'));           
                    //return null;
                    return new PageReference('/'+contact.Id);
                } else {
                    // update the custom attachment record with some attachment info
                    Vendor_Product_Review_Attachment__c customAttachment = [select id from Vendor_Product_Review_Attachment__c where id = :customAttachmentResult.getId()];
                    customAttachment.name = this.fileName;
                    customAttachment.Attachment__c = attachmentResult.getId();
                    update customAttachment;
                }
            }
       } catch (Exception e) {
          ApexPages.AddMessages(e);
          return null;
       }

            return new PageReference('/'+contact.Id);
      }
        
    
    public PageReference back() {
        return new PageReference('/'+contact.Id);
    }     
}

Here is the test code I've written.
 
@isTest(SeeAllData = false)

private class TestUploadAttachControllerVendProdRev

    {    
        static testMethod void UnitTestUploadAttachControllerVendProdRev()
            
             {     
                Department__c dept = new Department__c();
                dept.Name = 'Dept1';
                dept.Department_Manager__c = '005i0000005o3zu';
                insert dept;                
                
                Vendor_Profile__c vprof = new Vendor_Profile__c();
                vprof.Name = 'ABCProf';
                vprof.Department_of_Record__c = dept.id;
                vprof.Department_Manager__c = '005i0000005o3zu';
                insert vprof;
                
                Vendor_Product__c vprod = new Vendor_Product__c();
                vprod.Name = 'ABCProd';
                vprod.Vendor__c = vprof.id;
                vprod.Reviewed_Vendor__c = vprof.id;
                vprof.Department_of_Record__c = dept.id;
                insert vprod;
                
                Vendor_Product__c vprod2 = new Vendor_Product__c();
                vprod2.Name = '123Prod';
                vprod2.Vendor__c = vprof.id;
                insert vprod2;
                
                Vendor_Contract__c vc = new Vendor_Contract__c();
                vc.Vendor__c = vprof.id;
                vc.Products_Included__c = '[ABCProd,123Prod]';
                insert vc ;
            
                Vendor_Product_Review__c vrev = new Vendor_Product_Review__c();
                vrev.Vendor__c = vprof.id;
                vrev.Vendor_Product__c = vprod.id;
                insert vrev ;
           
           
               ApexPages.StandardController sc = new ApexPages.standardController(vrev);
               UploadAttachControllerVendProdRev up = new UploadAttachControllerVendProdRev(sc);
          

             }
    
    }

Any help is appreciated. Thank you !
 
  • September 13, 2016
  • Like
  • 0
I have what is essentially a custom Notes & Attachment feature which uses a VF page to give the user the ability to leave a Note of his/her attachment as well as choose a category to put the attachment into using a dropdown picklist (Document_Type__c). 

It works fine, but I would like for a user to be able to just enter something into the Notes__c field - and not be forced to include an attachment. 

As this code is, it will create the new record without the attachment - and then go on to create the attachment and then update the record which was created. I essentially need something which would check to see if there is an attachment after initial creation of the record - and then just ending if there is no attachment, and not attempt to uplaod the file.

I think it would have to come in after this line : 
 
return Database.insert(obj);

I can't figure out how to do that. Here is the full code :
 
public class UploadAttachmentControllerProdRev {
    
    public String selectedType {get;set;}
    public Boolean selectedAwesomeness {get;set;}
    public String Note {get;set;}
    private Product_Review__c contact {get;set;} 
    public String fileName {get;set;}
    public Blob fileBody {get;set;}
    
    public String contactproduct {get;set;}
    
    public UploadAttachmentControllerVendorProdRev(ApexPages.StandardController controller) { 
        this.contact = (Product_Review__c)controller.getRecord();
        //contactproduct = contact.Product__c;
    }   
    
    // creates a new Product_Review_Attachment__c record
    private Database.SaveResult saveCustomAttachment() {
        Product_Review_Attachment__c obj = new Product_Review_Attachment__c();
        obj.Product_Review__c = contact.Id; 
        obj.Product__c = contact.Product__c;
        obj.Note__c = Note;
        obj.Document_type__c = selectedType;
        //obj.awesome__c = selectedAwesomeness;
        // fill out cust obj fields
        return Database.insert(obj);
    }
    
    // create an actual Attachment record with the Product_Review_Attachment__c as parent
    private Database.SaveResult saveStandardAttachment(Id parentId) {
        Database.SaveResult result;
        
        Attachment attachment = new Attachment();
        attachment.body = this.fileBody;
        attachment.name = this.fileName;
        attachment.parentId = parentId;
        // inser the attahcment
        result = Database.insert(attachment);
        // reset the file for the view state
        fileBody = Blob.valueOf(' ');
        return result;
    }
    
    /**
    * Upload process is:
    *  1. Insert new Product_Review_Attachment__c record
    *  2. Insert new Attachment with the new Product_Review_Attachment__c record as parent
    *  3. Update the Product_Review_Attachment__c record with the ID of the new Attachment
    **/
    public PageReference processUpload() {
        try {
            Database.SaveResult customAttachmentResult = saveCustomAttachment();
        
            if (customAttachmentResult == null || !customAttachmentResult.isSuccess()) {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 
                  'Could not save attachment.'));
                return null;
            }
        
            Database.SaveResult attachmentResult = saveStandardAttachment(customAttachmentResult.getId());
        
            if (attachmentResult == null || !attachmentResult.isSuccess()) {
                ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 
                  'Could not save attachment.'));            
                return null;
            } else {
                // update the custom attachment record with some attachment info
                Product_Review_Attachment__c customAttachment = [select id from Product_Review_Attachment__c where id = :customAttachmentResult.getId()];
                customAttachment.name = this.fileName;
                customAttachment.Attachment__c = attachmentResult.getId();
                update customAttachment;
            }
        
        } catch (Exception e) {
            ApexPages.AddMessages(e);
            return null;
        }
        
        return new PageReference('/'+contact.Id);
    }
    
    public PageReference back() {
        return new PageReference('/'+contact.Id);
    }     
}


Thank you for your help. 
  • August 05, 2016
  • Like
  • 0
I am attempting to put a text message just above the buttons of some of the records which will indicate to the user that something is still needed in order to Submit his request. For some reason my text will not center properly. I thought maybe it was because I am trying to do it at the very top of the record, and maybe that was impossible in that section. But I tried moving it to other parts of the record and it wouldn't work either.

Here is the top portion of the VisualForce code which contains my style and outputtext :
 
<apex:page standardcontroller="Product_Review__c">

    <head>     
     <style >
        .italicText 
        { 
            font-style: italic; 
            font-weight: bold
            font-size: 24px;
            text-align:center;
            width :100%;
        }                   
     </style>
    </head>

<apex:messages />

    <apex:sectionheader title="{!$ObjectType.Product_Review__c.label} Detail" subtitle="{!Product_Review__c.Name}"/>
    <chatter:feedwithfollowers entityId="{!Product_Review__c.Id}"/>
    <apex:form >
    <apex:outputtext style="text-align:center; width : 100%;font-size: 16px; font-weight: bold ;  color : #FF0000" value="{!Product_Review__c.Docs_Still_Needed__c}" rendered="{!IF(Product_Review__c.Docs_Still_Needed__c = '', false, true)}" />
        <apex:pageblock mode="maindetail" title="{!$ObjectType.Product_Review__c.label} Detail">
            <apex:pageblockbuttons >
                <apex:commandbutton value="Edit" action="{!Edit}"/>
                <apex:commandbutton value="Delete" action="{!Delete}"/>
                <apex:commandButton value="Submit for Approval" action="{!URLFOR($Action.Product_Review__c.submit, Id)}" id="Submit_for_Approval" rendered="{!IF(Product_Review__c.Status__c = 'Approved', false, true)}"/>

            </apex:pageblockbuttons>

The align:center attribute in the outputtext line is having no effect. The rest of the attributes such as font size and color are working properly.

Any idea what I'm doing wrong here ?

Thank you for your help.
  • August 03, 2016
  • Like
  • 0
If one of my requests is for a threshold dollar amount it needs to be seen by an upper manager. However, the manager is not needed to "Approve" the request. The manager is only needed to "acknowledge" that he has seen it. Since the manager is not always available he does not want his interaction to be required and would like the approval process to continue without him. 

What would be the best way to handle this ? I'm thinking of different scenarios which would require different levels of approval and what not, but I think I may be overlooking an easier solution. 

Any help would be appreciated.
  • March 03, 2016
  • Like
  • 0
I have an app which would require a user to submit a request for a change to be made to a record.

The scenario : 

Records show salaries and benefits for employees. A manager would change the dollar amount to the Salary__c field and the number of weeks in the Vacation_Weeks__c field. This would require two different Requests to be produced and Submitted to the proper upper management. The upper management would like the ability to Approve or Reject all of those Requests with one push of a button (an Approve All or Reject All button). 

My tenative solution to this is to use Flow to automatically create a Request Package which is the master record to the individual Requests, which are essentially line items to the Request Package record. The upper management would go into the Request Package record, press the custom Approve All or Reject All button and all of the Requests are updated accordingly. 

My problem : I can properly update the Status field of those individual Requests with those buttons, but since this is not truly "Approving" or "Rejecting" the records it is not producing the Approval History data which goes along with pushing the native Salesforce "Approve/Reject" in an Approval Process.

So, what can be the solution to this ? If there was an "Approve" Static Action in Flow just as there is a "Submit for Approval" Static Action, I would be able to use that. But we don't have that.
  • March 01, 2016
  • Like
  • 0
I am trying to figure out how to write the test code for this VF controller and a Trigger which will work on the same object. I've never written test code before, so I'm quite desperate right now. I'm studying the online help and am not really getting too far. Can anybody help with this ?

This code is creating a junction record between a Regulation__c record and a Vendor_Product__c record. Basically, the class queries each individual selection from a list (selectedvalues). Each selection in the list represents a corresponding Vendor_Product record. The class places them into a multi-valued field (Products_Affected__c) in the Regulations__c object. It queries each value to confirm that it wasn't already added to the field before.

The trigger then takes each value of the Products_Affected__c field, queries it to find the corresponding Vendor_Product__c record, and upserts a new junction record with the Products_Affected_Regulation_Entry__c object.

Here is the Class (VF controller) :
 
public class RegulationsVFControllerEdit {
private final Regulation__c main;
public String rightOptionsHidden { get; set; }
public String leftOptionsHidden { get; set; }
public String selectedMulPickKeyTech{get;set;} 
public string lookupid{get;set;}
public String message { get; set; }
public List<SelectOption> options { get; set; }
public List<SelectOption> selectedSubs2 { get; set; }
public String selectedItems { get; set; }
public String mainid {get;set;}
public String coid {get;set;}    
    public RegulationsVFControllerEdit(apexpages.standardcontroller controller)
        {
        selectedSubs2 = new list<SelectOption>();
        this.main = (Regulation__c) controller.getRecord();
        }

    public pageReference  execute()
        {
        return null;
        }

    public list<selectoption> getitems()
        {
        lookupid=main.Vendor__c;
        mainid=main.id;
        //Set<String> selectedItems = new Set<String>();
        selectedItems=main.Products_Affected__c;
        coid = main.id;
        selectedMulPickKeyTech=main.Products_Affected__c;

        List<selectoption> options= new list<selectoption>();
        if(lookupid != null)
            {
                    if(selectedMulPickKeyTech !=null)
                    {
                    selectedMulPickKeyTech=selectedMulPickKeyTech.replace('[','');                
                    selectedMulPickKeyTech=selectedMulPickKeyTech.replace(']','');

                    String[] selectedvalues = selectedMulPickKeyTech.split(',');
                    System.debug('selectedMulPickKeyTechLine43 ########'+selectedMulPickKeyTech); 
                    System.debug('selectedvaluesLine44 ########'+selectedvalues);         
                    selectedSubs2 = new list<SelectOption>();
                    for (String selectedvalue: selectedvalues) 
                        {
                        selectedSubs2.add(new SelectOption(selectedvalue,selectedvalue));
                        }

                     }   
             System.debug('lookupid ########'+lookupid); 
             System.debug('selectedSubs2Line52 ########'+selectedSubs2);  
             System.debug('selectedMulPickKeyTechLine54 ########'+selectedMulPickKeyTech); 
           Vendor_Profile__c a =[select name , (select name from Vendor_Products__r) from Vendor_Profile__c where id =:lookupid];
                for(Vendor_Product__c s : a.Vendor_Products__r)
                    {
                        //check that selected items dont already contain the keys
                        //if(!selectedItems.contains(s.name))
                    options.add(new SelectOption(s.name,s.name));
                    }
            }

            else
            options.add(new SelectOption('None','None'));
            return options;

        }

    public PageReference save()
        {
        message = null ;       
        Boolean first = true;
        if (selectedSubs2.size() > 0)
            {
           for ( SelectOption so : selectedSubs2 ) 
            {
                if (first) 
                    {
                    message = message ;
                    }
                    message = message + ', ' + so.getValue() ;
                    first = false;
            }   

                message = message.removeStart('null, ');
                message = message.normalizeSpace();
                message = '['+message+']';
                main.Products_Affected__c=message;
                }
        update main;

      System.debug('coid ########'+coid);

      //PageReference pr = new PageReference('/a7w/o');
      PageReference pr = new PageReference('/'+ mainid);

          pr.setRedirect(true);
          return pr;

        }
}

This is the trigger which runs after the record is saved :
 
trigger AutoCreateSubOnRegulation on Regulation__c(after insert,after update)
{
    //Since, we need two values from Regulation__c to be populated on the new Products_Affected_Regulation_Entry__c record.
    //So, taking a Map instead of list. Earlier, List<String> subAccNames=new List<String>();
    //Map of subAccountNames and Regulation__c Record.</b>
    Map<String, Regulation__c> subAccNames=new Map<String, Regulation__c>();

    for(Regulation__c newCont: Trigger.New) 
    {
        //Checking of the field is empty or not.</b>
        if(newCont.Products_Affected__c!=Null && newCont.Products_Affected__c!='') 
        {
            system.debug('newCont.Products_Affected__c---->'+newCont.Products_Affected__c);
            String temp=newCont.Products_Affected__c.normalizeSpace();
            temp=temp.replace(']',''); //No need for this if comma seperated values as I have taken.
            temp=temp.replace('[',''); //No need for this if comma seperated values as I have taken.</b>

            //Iterate the number of values in the temp variable by slitting them by comma
            //add put them in subAccNames</b>
            for(String acctName: temp.split(','))
            {
                subAccNames.put(acctName.normalizeSpace(), newCont);
                system.debug('subAccNames !!! '+subAccNames); 
            }
        }
    }

    //Take a Map of Name and Record for holding Vendor_Product__c Name and Vendor_Product__c Record.</b>
    Map<String, Vendor_Product__c> subAccIdsByName=new Map<String, Vendor_Product__c>();

    //Iterate over the Vendor Product records and create a Map with Venfor Product Id as Key and Vendor Product Record as Value.</b>
    for(Vendor_Product__c subacc: [SELECT Id, Vendor__c, Name FROM Vendor_Product__c WHERE Name IN :subAccNames.keySet()]) 
    {
        //Putting record in place of Id, as value in the map.</b>
        subAccIdsByName.put(subacc.Name, subacc);
        System.debug('subAcc Name and ID='+subacc.Name +'Id='+subacc.id+'Vendor_c='+subacc.Vendor__c);
    }

//&nbsp;   //This will hold the Products_Affected_Regulation_Entry__c records to be upserted.</b>
    List<Products_Affected_Regulation_Entry__c> subs = new List<Products_Affected_Regulation_Entry__c>();

    //Iterating over subAccNames Map.
    //No need to iterate again over Regulation__c records as we have already taken the Regulation__c record in the subAccNames Map.
    //Earlier: for (Regulation__c newContract : Trigger.New)</b>
    for(String ref1: subAccNames.keySet()) 
    {
        //Iterate over the subAccIdsByName Map.</b>
        for(String ref2: subAccIdsByName.keySet())
        {
            //Match if the Name in the subAccNames Map is equal to Name in the subAccIdsByName Map.</b>
            if(ref1==ref2)
            {
                Products_Affected_Regulation_Entry__c ssoc = new Products_Affected_Regulation_Entry__c();
                ssoc.Regulation__c=subAccNames.get(ref1).Id;
                //Access Vendor Product Id from the Map.</b>
                ssoc.Vendor_Product__c=subAccIdsByName.get(ref2).Id;
                //Access Vendor__c from the Map.</b>
                ssoc.Vendor__c=subAccIdsByName.get(ref2).Vendor__c;
                //Access Name from the Map.</b>
                ssoc.Regulation_and_Product__c=subAccNames.get(ref1).Name+'~'+subAccIdsByName.get(ref2).Id;
                //Put the records in the </b>subs </b>list.</b>
                subs.add(ssoc);
            }
        }
    }

    upsert subs Regulation_and_Product__c;
}

Like I said, I'm trying to learn it for myself, but that's going to take some time. I'd appreciate any kind of help I can get. 

Thank you.
  • February 09, 2016
  • Like
  • 0
Another title for this post could have been : "How can I remove the New button from the Recent list view ?"

I don't want my users to be able to use the New button for a certain custom object. I have taken it out of the List Views, but it is still appearing in the Recent list view for that object. 

I can't find a way to get rid of it. The only thing I can think of is to maybe replace the Recent view with a Visualforce page. But how do I do that ? Is that possible ? If so, what would the code be for that ? 

If you know of an easier way to get rid of the New button in a Recent view I would love to hear about it.

Thank you.
  • January 07, 2016
  • Like
  • 0

I have an object (ObjectA) with two Master-Detail fields in it. I am attempting to auto-populate both of those Master-Detail fields whenever I create a new ObjectA record. I am attempting to accomplish this by using Process Builder. However, those Master-Detail fields are not available in the dropdown list of one of the fields to update when I use the Update Records action. 

Why is this ? Am I not able to update Master-Detail fields using Process Builder ? If so, is there a way around this ? 

Thank you.

  • December 29, 2016
  • Like
  • 0
I have what I call Employee Profiles in which each employee has currency fields which are the limits he/she can expense on a business trip. There is a field representing the dollar for their job title, and another field showing the user's dollar amounts. Their dollar limits may or may not be at the limit of their job title.

I am trying to create an Approval Process which will be submitted for a person to request an increase in an employee's limits. Sometimes the request may be above their current job title's limits, sometimes it may not be. I would like the Approval Process to be routed differently if the request is above the job title limit of the employee in question.

How can I put in the logic which will refer to the field on the object to see if the new requested limit is above the job title's limit ? As I see it, I can only put in actual numbers, not references to field values. 

Thank you.
  • December 17, 2015
  • Like
  • 0
I am attempting to use the Email Service address for Replies to certain Email Alerts. But we are unable to use Email Service addresses as Org-Wide addresses, and therefore we cannot use them as the From address on an Email Alert. 

I was going to set up Forwarding in another legitimate email address to be sent to the Email Service address to solve this. I'm using Gmail. But when a Forwarding address is named the system insists on sending a confirmation email to the address named as the Forwarding recipient. Since it's an Email Service address I don't know how to do this. 

Does anybody have any advice on how to accomplish this with an Email Service ? 

Thank you.
  • December 15, 2015
  • Like
  • 0
I have the following class which I am using with an Email Service. I decided to put Today() into one of the fields in the object which would be receiving the InboundEmail, but I am getting a "Compile Error : Method does not exist or incorrect signature : Today()"

Here is the code : 
 
global class VendorEmail implements 
        Messaging.InboundEmailHandler {


Vendor_Notes__c[] NewVendorNotes = new Vendor_Notes__c[0];

 global Messaging.InboundEmailResult handleInboundEmail(
  Messaging.InboundEmail email, 
  Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = 
        new Messaging.InboundEmailresult();
 
  // Captures email info
    
String emailAddress = envelope.fromAddress;
String fName = email.fromname.substring(
        0,email.fromname.indexOf(' '));
String lName = email.fromname.substring(
        email.fromname.indexOf(' '));
String[] emailBody = email.plainTextBody.split('\n', 0);
String phoneNumber = emailBody[0].substring(6);
       
//Associates email to proper Vendor Profile
//var today = new Date(0);  
Vendor_Profile__c venpro;
venpro = [select ID,ACH_Status__c from Vendor_Profile__c where name =
             :email.subject limit 1];
    ID jobId = venpro.ID;
    venpro.Date_of_Latest_Compliance_Certificate__c = Today();
    Update venpro;

try
    {
      NewVendorNotes.add(new Vendor_Notes__c(Sender__c = emailAddress,
      Vendor__c = jobId,
      Routing_Number__c = lName,
     Account_Number__c = phoneNumber
      ));
 
      insert NewVendorNotes;
      
      //Save any Binary Attachment
            
            if (email.binaryAttachments != null)
                {
                    for(Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) 
                    {
                        Attachment attachment = new Attachment();
        
                        attachment.Name = bAttachment.fileName;
                        attachment.Body = bAttachment.body;
                        attachment.ParentId = venpro.Id;
                        insert attachment;
                    }
               } 
   }
    
   catch (System.DmlException e)   
   {
           

            //Save any Binary Attachment
            
            if (email.binaryAttachments != null)
                {
                    for(Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) 
                    {
                        Attachment attachment = new Attachment();
        
                        attachment.Name = bAttachment.fileName;
                        attachment.Body = bAttachment.body;
                        attachment.ParentId = venpro.Id;
                        insert attachment;
                    }
               } 
}
return result;
       
    }
}

Anybody have any ideas ....?

Thank you very much for any help.
  • December 15, 2015
  • Like
  • 0
I am attempting to add the following button to a Visualforce page, which is functioning as the override to the View of an object.

The button will call another VF page - which in turn will call a Flow. I know the code works because I've used the button when using the object in a Page Layout.

Here is the following code for both the VF page it will call, and the extension/controller code it will run :

VF Page :
<apex:page StandardController="Vendor_Profile__c" Extensions="New_RelatedVendor_With_Flow_Controller">
<flow:interview interview="{!myflow}" name="New_Related_Vendor" finishlocation="{!finishlocation}"> 
<apex:param name="VarPrimeVendProfRecID" value="{!Vendor_Profile__c.Id}"/>
</flow:interview>
</apex:page>

Extension :
 
public class New_RelatedVendor_With_Flow_Controller {
    public New_RelatedVendor_With_Flow_Controller(ApexPages.StandardController controller) {
         }

public flow.interview.New_Related_Vendor myflow {get;set;}
    public New_RelatedVendor_With_Flow_Controller() {
    }    

    public String getendID() {        
        if (myflow !=null) return myflow.VarPrimeVendProfRecID;
        else return 'home/home.jsp';
        }       

    public PageReference getFinishLocation() {        
        PageReference endlocation = new PageReference('/' + getendID());
        return endlocation;
        }
}

Thank you for any help you can provide. 
 
  • December 04, 2015
  • Like
  • 0