• Tyler Harris
  • NEWBIE
  • 262 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 62
    Questions
  • 102
    Replies
I'm getting a Too many Async calls created on Class.userAddWorkround: line 8, column 1. I have a trigger making an async call to inactivate Contact and vice-versa. I created the class to receive a list of ids to process. I thought the list would 'bulky' enough to process all in 1 call. What am I missing?

Trigger flipPartnerAccess
trigger flipPartnerAccess on Contact (after update) {
	
    List<User> potentialUsers = [SELECT Id, ContactId FROM User WHERE Profile.userlicense.name = 'Partner Community Login'];
    Map<Id, User> emailToUserMap = new Map<Id, User>();
    List<Id> usersToDrop = new List<Id>();
    
    for(User u : potentialUsers){
        if(u != null){
        emailToUserMap.put(u.ContactId, u);
        }
        
    }

    for(Contact con : Trigger.new){
        if(con.Status__c =='Inactive'){
            usersToDrop.add(emailToUserMap.get(con.id).id);

    }
         
        }
    if(usersToDrop !=null){
            userAddWorkRound uak = new userAddWorkRound(usersToDrop);
    }

}

userAddWorkRound
Future
public class userAddWorkRound {
//Class is a workaround for the MIXED_DML_OPERATION, DML operation error on setup object is not permitted after you have updated a non-setup object (or vice versa): Contact, original object: User
    
    public userAddWorkRound(List<Id> uid){
        List<Id> UserID = uid;
        system.debug(UserID);
            if(!system.isFuture()){
            AddUserAccessObject(UserID);
            }
        
    }
    
@future
private static void AdduserAccessObject(List<id> uid){
    system.debug('running');
    List<User> u = [SELECT id FROM User WHERE id = :uid ];  
    system.debug(u);
    if(u.size() != null){
        for(User use:u){
            if(use.IsActive =true){
            use.IsActive =false;
            }
        }
         
  update u;

    }

}
}

Thanks for your help.
 
I can't seem to figure out how to get code coverage a few lines in my Lead Trigger that validates on an approval process. 

Apex Trigger
trigger RequireRejectionPartReg on Lead (before update) {

    Map<Id, Lead> rejectLeads = new Map<Id, Lead>{};
        Id gd = Schema.SObjectType.Lead.RecordTypeInfosByName.get('GlobalPRM Partner Registration').RecordTypeId;
        for(Lead ld : Trigger.new){

    
            if((ld.Rejection_Reason__c ==null && ld.Registration_Status__c =='Rejected')){
                if(ld.RecordTypeId == gd){
                rejectLeads.put(ld.id, ld);
                    rejectLeads.get(ld.id).addError('Operation Cancelled: Please provide a rejection reason on the Lead!');
                }
                
            }
            if(!rejectLeads.isEmpty()){
                List<Id> processInstanceIds = new List<Id>{};
                    for(Lead lds: [SELECT(SELECT Id FROM ProcessInstances ORDER BY CreatedDate DESC LIMIT 1) FROM Lead WHERE Id IN :rejectLeads.keySet()]){
                        if(processInstanceIds.size() > 0){
                        processInstanceIds.add(lds.ProcessInstances[0].Id);  
                        }
            
                                           
                    }
                for(ProcessInstance pi : [SELECT TargetObjectId,(SELECT Id, StepStatus, Comments FROM Steps ORDER BY CreatedDate DESC LIMIT 1) FROM ProcessInstance WHERE Id IN : processInstanceIds ORDER BY CreatedDate DESC]){
                    if((pi.Steps[0].StepStatus == 'Rejected')){
                        rejectLeads.get(pi.TargetObjectId).addError('Operation Cancelled: Please provide a rejection reason on the Lead!');
                    }
                }
            }
            
        }
    
}
Lines 19, 25 and 26 I'm still not getting code coverage. 
processInstanceIds.add(lds.ProcessInstances[0].Id);  

and
       if((pi.Steps[0].StepStatus == 'Rejected')){
                        rejectLeads.get(pi.TargetObjectId).addError('Operation Cancelled: Please provide a rejection reason on the Lead!');

Test Class
@isTest
public class TestRequireRejection {

     static testMethod void testRequireRejectMethod(){
         test.startTest();
         Id gl = [SELECT Id FROM RecordType WHERE Name='GlobalPRM Partner Registration' AND SObjectType='Lead' limit 1].Id;
        Lead l = new lead();
         l.FirstName = 'test';
         l.LastName = 'mctesty';
         l.LeadSource = 'Banner';
         l.Company = 'Test Company';
         l.Business_Segment__c = 'Connect';
         l.RecordTypeId = gl;
         l.Region__c = 'EMEA';
         l.Areas_of_Interest__c = 'Readers';
         l.Role__c = 'End-User';
         l.Rejection_Reason__c = '';
         
         insert l;
         
         Lead upl = [SELECT Id, Registration_Status__c FROM Lead WHERE Id = :l.id];
         
         upl.Registration_Status__c = 'Rejected';
         
         try{
             
         	update upl;
             system.debug(upl);
         }
         catch(Exception e){
             
             system.debug(e.getMessage());
             Boolean expectedException = e.getMessage().contains('Operation Cancelled: Please provide a rejection reason on the Lead!') ? true: false;
             system.assertEquals(expectedException, true);
             
         }
                        
             Approval.ProcessSubmitRequest app = new Approval.ProcessSubmitRequest();
             app.setObjectId(upl.id);
         	 app.setNextApproverIds(new Id[] {UserInfo.getUserId()});
             Approval.ProcessResult result = Approval.process(app);
 
                 
            test.stopTest();
         
    }  
}

 
I'm getting the error "Constructor not defined: [ApexPages.StandardSetController].<Constructor>(List<StoreFront2.DisplayMerchandise). I want to pass in the list of Products I've constructed in the List<DisplayMerchandise> products; variable. How can I accomplish this? Or is there a better way to code this?  Thanks.
 
public class StoreFront2{

List<DisplayMerchandise> products;


public StoreFront2(){
        ct=new Purchase_Line_Items__c();
        ct2=new Contact();
        flag = false;
        flip = false;
        flag2 = true; 
      
         
    }

public ApexPages.StandardSetController samplePagination{
        get{
            if(samplePagination == null){
                samplePagination = new ApexPages.StandardSetController(products);
                samplePagination.setPageSize(5);
            }
            return samplePagination;
        }
        set;
        
    }

    public class DisplayMerchandise {
        public Merchandise__c merchandise{get; set;}
        public Decimal count{get; set;}
        public Decimal tempCount{get;set;}
        public DisplayMerchandise(Merchandise__c item){
            this.merchandise = item;
            
        }
    }

   public List<DisplayMerchandise> getProducts() {
        if (products == null){
            products = new List<DisplayMerchandise>();
    
            for (Merchandise__c item :
            [SELECT id, name, description__c, price__c
            FROM Merchandise__c
            WHERE Total_Inventory__c > 0]) {
           
            products.add(new DisplayMerchandise(item));
            }
        }
        return products;
    }
}

 
Hello,
 
CASE( First_Touch__c, ISNULL(First_Touch__c), Days_to_Lead_Touch_Today__c,NOT(ISNULL(First_Touch__c)), Days_LeadTouch_Business_Hours_FirstTouch__c,Days_LeadTouch_Business_Hours_FirstTouch__c )
I'm getting a  Error: Incorrect argument type for function 'CASE()' with this formula. I need to conditionally show a different formula field value based on certain criteria. IF() statement not working as I'm getting a compile error. Want to see if CASE() will avoid that.

Thanks in advance.
 
Getting a Visualforce error on line 49 column 1
System.ListException: List index out of bounds: 0
Error is in expression '{!buy}' in component <apex:commandButton> in page confirmbuy: Class.StoreFront2.buy: line 49, column 1
Class.StoreFront2.buy: line 49, column 1

I'm trying to insert both a Purchase__c custom object record and a list of Merchandise__c line items at the same time. To do this I'm passing my "cart" values into a list and trying to add the merchanise items to the "counter" variable and insert them as "Merchandise__c" line items.
Apex
public virtual class StoreFront2 {    
    
    public String message { get; set; }
    List<DisplayMerchandise> products;
    Map<Id, DisplayMerchandise> cart;
    public Boolean incart{get;set;}
    public Id rowz;
    public id rowDel{ get;set; }
    public Boolean flip{ get;set; }
    public Boolean flag{ get;set; }
    public Boolean flag2 { get; set; }
    public Purchase_Line_Items__c ct{ get;set; }
    public Contact ct2{get;set;}
    
    public StoreFront2(){
        ct=new Purchase_Line_Items__c();
        ct2=new Contact();
        flag = false;
        flip = false;
        flag2 = true; 
      
    }
      
    public PageReference buy(){
        
        List<Merchandise__c> toMerch = new List<Merchandise__c>();
        
        List<id> updateMerch = new List<id>();
                
        PageReference send = new PageReference('/apex/StoreCart2');
        
        if(ct != null && cart !=null ){
            List<DisplayMerchandise> counter = new List<DisplayMerchandise>();
    		List<Merchandise_Line_Item__c> merchi = new List<Merchandise_Line_Item__c>();
            Decimal total = 0;
            counter = cart.values();
            system.debug(counter);
            
            
            for(Integer i = 0; i < counter.size(); i++){
                
                Decimal totalPrice = counter.get(i).count;
                
                total +=totalPrice;
                ct.Item_Quantity__c=total;     
                if(counter.size() > 0 || !counter.isEmpty()){
          		merchi.add(i,new Merchandise_Line_Item__c(Name =ct.Name,Purchases__c=ct.id,Merchandise_Item_Stable__c=counter.get(i).merchandise.id));
                }
            }	
            insert ct;
         	
            insert merchi;

      		
            
	
			
        }
        
        return send;     
    }
    
    
    public void doShow(){
        if(flip){
            flag = true;  
            flag2=false;
        }
        else{
            flag = false;
            flag2 = true;
        }
          
    }
 
    public PageReference shop(){
        handleTheBasket();
        message = 'You bought: ';
        for (DisplayMerchandise p:products){
            if(p.tempCount > 0){
               message += p.merchandise.name + ' (' + p.tempCount + ') ' ;
               }
            }
        return null;
    }
   
    
    public void remove(){
     rowz = (Id) ApexPages.currentPage().getParameters().get('rowDel');
        if(cart.containsKey(rowz)){
            cart.remove(rowz);
            if(cart.isEmpty()){
                incart = false;
            }      
        }  
       
    }
        public pageReference back(){
        PageReference doit = new PageReference('/apex/StoreCart');
        doit.setRedirect(false);
            return doit;
        }
    
    
    public Pagereference checkout(){
        if(cart.isEmpty()){
            ApexPages.Message myError = new ApexPages.Message(ApexPages.Severity.ERROR, 'Shopping Cart is Empty');
            ApexPages.addMessage(myError);
            return null;
        } 
        
        else{
        PageReference send = new PageReference('/apex/ConfirmBuy');
        return send;
        }
    } 
    
    
    public void handleTheBasket(){
        for(DisplayMerchandise c : products){
            if(c.tempCount > 0){
            if(cart.containsKey(c.merchandise.Id)){        
                cart.get(c.merchandise.Id).count += c.tempCount;
                
            }
            else{
                cart.put(c.merchandise.Id, c);
                cart.get(c.merchandise.Id).count = c.tempCount;
                incart = true;
      
            } 
        
        }
        }
        
    }
    
    public Map<Id, DisplayMerchandise> getCart() {
        if(cart == null){
            cart = new Map<Id, DisplayMerchandise>();
            incart = false;
                }
      
        return cart;
    }
    
    public class DisplayMerchandise {
        public Merchandise__c merchandise{get; set;}
        public Decimal count{get; set;}
        public Decimal tempCount{get;set;}
        public DisplayMerchandise(Merchandise__c item){
            this.merchandise = item;
            
        }
    }

    public List<DisplayMerchandise> getProducts() {
        if (products == null){
            products = new List<DisplayMerchandise>();
    
            for (Merchandise__c item :
            [SELECT id, name, description__c, price__c
            FROM Merchandise__c
            WHERE Total_Inventory__c > 0]) {
           
            products.add(new DisplayMerchandise(item));
            }
        }
        return products;
    }

}

Visualforce
<apex:page standardStylesheets="false" showHeader="false" sidebar="false" controller="StoreFront2">
    
    <apex:stylesheet value="{!URLFOR($Resource.styles)}"/>
    <h1>Store Front</h1>

    <apex:form >
        <apex:dataTable value="{!products}" var="pitem" rowClasses="odd,even">
            <apex:column headerValue="Product">
                <apex:outputText value="{!pitem.merchandise.name}" />
            </apex:column>
            <apex:column headervalue="Price">
                <apex:outputText value="{!pitem.merchandise.Price__c}" />
            </apex:column>
            <apex:column headerValue="#Items">
                <apex:inputText value="{!pitem.tempCount}"/>
            </apex:column>
        </apex:dataTable>

        <br/>

        <apex:commandButton action="{!shop}" value="Add to Cart" reRender="msg,cartPanel,cmdPanelId">
        </apex:commandButton>
    
        <apex:outputPanel id="msg">
            {!message}
        </apex:outputPanel>

        <br/>    

        <h1>Your Basket</h1>

        <apex:outputPanel id="cartPanel">
            <apex:dataTable id="cart" value="{!cart}" var="carti" rowClasses="odd,even">

                <apex:column headerValue="ID" rendered="false">
                    <apex:outputText value="{!cart[carti].merchandise.Id}" >
                    </apex:outputText>
                </apex:column>
                <apex:column headerValue="Product">
                    <apex:outputText value="{!cart[carti].merchandise.name}">
                    </apex:outputText>
                </apex:column>
                <apex:column headervalue="Price">
                    <apex:outputText value="{!cart[carti].merchandise.price__c}" />
                </apex:column>
                <apex:column headerValue="#Items">
                    <apex:outputText value="{!cart[carti].count}"/>
                </apex:column>
                <apex:column headerValue="Remove?">
                    <apex:commandButton action="{!Remove}" value="Remove" reRender="cart,cmdPanelId">
                        <apex:param name="rowDel" assignTo="{!rowDel}" value="{!carti}"/>
                    </apex:commandButton>
                </apex:column>             

            </apex:dataTable>
			<apex:outputPanel id="cmdPanelId">
				<apex:commandButton value="Checkout" action="{!checkout}" rendered="{!incart}" />
			</apex:outputPanel>
        </apex:outputPanel>

    </apex:form>

</apex:page>

 
I'm trying to insert two object records, but I'm getting an error because the 2nd object list doesn't see the 1st object id yet and I'm getting a "Missing Required Field validation error". Is there a way I can time, or chain these so they are both inserted with the correct relationship.
 
public StoreFront2(){
        ct=new Purchase_Line_Items__c();
        ct2=new Contact();
        flag = false;
        flip = false;
        flag2 = true; 
      
    }
      
    public PageReference buy(){
        
        List<Merchandise__c> toMerch = new List<Merchandise__c>();
        
        List<id> updateMerch = new List<id>();
                
        PageReference send = new PageReference('/apex/StoreCart2');
        
        if(ct != null && cart !=null ){
            List<DisplayMerchandise> counter = new List<DisplayMerchandise>();
    		List<Merchandise_Line_Item__c> merchi = new List<Merchandise_Line_Item__c>();
            Decimal total = 0;
            counter = cart.values();
            
            for(Integer i = 0; i < counter.size();i++){
                Decimal totalPrice = counter.get(i).count;
                total +=totalPrice;
                ct.Item_Quantity__c=total;
                system.debug(ct);
          		merchi.add(new Merchandise_Line_Item__c(Name ='Pencils',Purchases__c=ct.id, Merchandise_Item_Stable__c='a02F000000AuhTh'));
              
            }	
         	insert ct;
            insert merchi;

 
Hi All,

I'm getting a null exception error on line 27 when I look for email.binaryAttachments.size(). I'm attaching files to my emails before I send them, but they're not attaching to the Lead.

Apex
global class EmailDemoReceive implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult handleInBoundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope){
        
       Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        if([select count() from Lead where Name = :email.subject]==0){
         
            Lead leadz = new Lead();
            String addy = email.subject;
           
            if(String.isNotEmpty(addy)){
             List<String> nameParts = addy.split('\\bCompany=\\b');
            String namePart = addy.remove('Company=');
            System.debug(namePart);
            system.debug(nameParts);
 
            leadz.LastName = email.fromName;
            leadz.Company = namePart;
            String chopit = leadz.company;
            system.debug(leadz.Company);
            leadz.Email = email.fromAddress;
            leadz.Description = email.htmlBody;    
           
             insert leadz;   
          
                system.debug(email.binaryAttachments);
         
                    for(Integer i = 0; i < email.binaryAttachments.size(); i++){
                        Attachment attach = new attachment();
                        attach.ParentId = leadz.id;
                        attach.Name = email.binaryAttachments[i].filename;
                        attach.Body = email.binaryAttachments[i].body;
                        System.debug(attach);
                        
                        insert attach;
                        system.debug(attach.Id);
                    } 
                
                
            }
            
            else{
            leadz.LastName = email.fromName;
            System.debug(leadz.Company);
            leadz.Company = 'Unknown';
            System.debug(leadz.Company);
            leadz.Email = email.fromAddress;
            leadz.Description = email.htmlBody;
            insert leadz;   
                
            }
          
            
        }

        return result;
        
    }

}

 
I can't figure out why my page section is not rerendering. The debug is saying it should be returning true/false based on the checkbox, but the section is stil showing. I need to rerender the OuputPanel with the Id 'changem'.  I want to show/hide based on the boolean value of the inputCheckbox "{!flip}".

Visualforce
 
<apex:page controller="StoreFront2" showHeader="false" sidebar="false" >
    <apex:stylesheet value="{!URLFOR($Resource.styles)}"/>
    <h1>Confirm Page</h1>
  <apex:form >
      <apex:outputPanel rendered="{!flip}" id='changem'>
      <apex:pageBlock>
     	<apex:pageblocksection>
          Find Existing Contact <apex:inputField value="{!ct.Buyer__c}" ></apex:inputField><br/><br/>
          </apex:pageblocksection>
           
      </apex:pageBlock>
          </apex:outputPanel>
      <apex:outputPanel >
      <apex:pageBlock >
          
          <apex:outputPanel>
          <apex:pageBlock>
              Find Existing Buyer<apex:inputCheckbox value="{!flip}" ><apex:actionSupport event="onchange" reRender='changem' action='{!doShow}' status='StatusChange'/><apex:actionStatus startText='Updating page' id='StatusChange'/></apex:inputCheckbox><br/>
          </apex:pageBlock>
          </apex:outputPanel>
          
          	First Name: <apex:inputText title="First Name" /><br/>
          	Last Name: <apex:inputText title="Last Name" /><br/>
          	Email Address: <apex:inputText title="Email Address"/>
          
      		</apex:pageBlock>
          </apex:outputPanel>
      
     <apex:dataTable id="cart" value="{!cart}" var="carti" rowClasses="odd,even">
			
   <apex:column headerValue="ID" rendered="false">
       <apex:outputText value="{!cart[carti].merchandise.Id}" >
       </apex:outputText>
          </apex:column>
          <apex:column headerValue="Product">
              <apex:outputText value="{!cart[carti].merchandise.name}">
          	
         </apex:outputText>
          </apex:column>
          <apex:column headervalue="Price">
              <apex:outputText value="{!cart[carti].merchandise.price__c}" />
          </apex:column>
          <apex:column headerValue="#Items">
              <apex:outputText value="{!cart[carti].count}"/>
          </apex:column>
      </apex:dataTable><br/>
      <apex:commandButton action="{!back}" value="Back"/>
    </apex:form>
  
</apex:page>

Apex
public virtual class StoreFront2 {    

public StoreFront2(){
        ct=new Purchases__c();
        flip=false;
        system.debug(flip);
    }
   
    public void doShow(){
        if(flip){
            flip = false;
            
        }
        else{
            flip = true;
            system.debug(flip);
        }
          
    }

}
Log when I check the box
16:21:23:039 SYSTEM_MODE_ENTER true

16:21:23:040 VF_APEX_CALL j_id15|{!doShow}|PageReference: none
 
I'm having trouble rerendering a section on a Visualforce page.

I want to rerender the "Output Panel" with the id 'changeEm'. I've got a lookup to a Contact ct.Buyer__c and a checkbox that if changed to show/hide id='changeEm'

Let me know if there is a better Apex solution. Also, is there a way to how this occured in an AJAX fashion on page?
 
<apex:form >
      <apex:pageBlock >
     	
          Find Existing Contact <apex:inputField value="{!ct.Buyer__c}" ><apex:actionSupport event='onchange' reRender='changeEm'/></apex:inputField><br/><br/>
          Create New Buyer? <apex:inputCheckbox value ='{!turn}'><apex:actionSupport event='onchange' reRender='changeEm'/></apex:inputCheckbox>
           
      </apex:pageBlock>
      <apex:outputPanel id='changeEm'>
      <apex:pageBlock>
          First Name: <apex:inputText title="First Name" /><br/>
          Last Name: <apex:inputText title="Last Name" /><br/>
          		Email Address: <apex:inputText title="Email Address"/>
          
      </apex:pageBlock>
          </apex:outputPanel>
      
     <apex:dataTable id="cart" value="{!cart}" var="carti" rowClasses="odd,even">
			
   <apex:column headerValue="ID" rendered="false">
       <apex:outputText value="{!cart[carti].merchandise.Id}" >
       </apex:outputText>
          </apex:column>
          <apex:column headerValue="Product">
              <apex:outputText value="{!cart[carti].merchandise.name}">
          	
         </apex:outputText>
          </apex:column>
          <apex:column headervalue="Price">
              <apex:outputText value="{!cart[carti].merchandise.price__c}" />
          </apex:column>
          <apex:column headerValue="#Items">
              <apex:outputText value="{!cart[carti].count}"/>
          </apex:column>
      </apex:dataTable>
      <apex:commandButton action="{!back}" value="Back"/>
    </apex:form>