• 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 Apex Heap Error on my HttpResponse on an XML feed I'm consuming. How can I optimize the consumption of the XML on line
33  HttpResponse res = h.send(req); ?
 
/*************************************************
 Class: GlobalPRM_RssRetrieval.cls
 Description: schedule apex for RSS Feed Retrieval
 Auther: Christine Wang
 Date:   1/15/2015

 Revision History:
---------------------------------------------------- 
***************************************************/ 
global class GlobalPRM_RssRetrieval implements Schedulable {
    public static string sourceURL = GlobalPRM_Setting__c.getAll().values().get(0).GlobalPRM_RssRetrieval_EndPoint__c;
        //'http://www.hidglobal.com/sites/default/files/pp_resources.xml';
    global GlobalPRM_RssRetrieval () {

    }
    
    global void execute(SchedulableContext c) {
        updateFileIndex();
    }

    @future(callout=true)
    static global void updateFileIndex() {
        List<Dom.XMLNode> extFileList = GlobalPRM_RssRetrieval.getRSSFeed(sourceURL);
        System.Debug('# OF POSTS FOUND: ' + extFileList.size() );
    }
    static global List<Dom.XMLNode> getRSSFeed(string URL) {
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        // url that returns the XML in the response body  
    
        req.setEndpoint(url);
        req.setMethod('GET');
        HttpResponse res = h.send(req);
        Dom.Document doc = res.getBodyDocument();
        
        Dom.XMLNode rss = doc.getRootElement();
        System.debug('>>' + rss.getName());

        List<External_File__c> extFileList = new List<External_File__c>();
        List<Dom.XMLNode> rssList = new List<Dom.XMLNode>();
        for(Dom.XMLNode child : rss.getChildren()) {
           External_File__c ef = new External_File__c();
           for(Dom.XMLNode channel : child.getChildren()) {
               if(channel.getName() != null ) {
                    //System.debug('@@@@' + channel.getName() + ' = ' +channel.getText());
                   if( channel.getName() == 'File' ){
                        ef.File__c = channel.getText();
                        ef.File_URL__c =  (ef.File__c.substringAfter('href="') ).substringBefore('"');
                        ef.File_Type__c =  (ef.File__c.substringAfter('type="') ).substringBefore(';');
                        ef.File_Name__c = ef.File_URL__c.substring(ef.File_URL__c.lastIndexOf('/')+1);
                   }
                   else if( channel.getName() == 'Nid' ){
                       ef.Nid__c =  channel.getText();
                       System.debug('Nid__c = ' +  ef.Nid__c);
                   }
                   else if( channel.getName() == 'agile_eco_num' ){
                       ef.agile_eco_num__c =  channel.getText();
                   }
                   else if( channel.getName() == 'agile_english_parent_num' ){
                       ef.agile_english_parent_num__c =  channel.getText();
                   }
                   else if( channel.getName() == 'agile_part_num' ){
                       ef.agile_part_num__c  =  channel.getText();                   
                   }
                   else if( channel.getName() == 'Body' ){
                       ef.Body__c =  channel.getText();
                   }
                   else if( channel.getName() == 'Brand' ){
                       ef.Brand__c =  channel.getText();
                   }
                   else if( channel.getName() == 'Content-UUID' ){
                       ef.Content_UUID__c  =  channel.getText();
                   }
                   else if( channel.getName() == 'Display-Title' ){
                       ef.Display_Title__c  =  channel.getText();
                   }
                   else if( channel.getName() == 'Display-URL' ){
                       ef.Display_URL__c  =  channel.getText();
                   }
                   else if( channel.getName() == 'Document-type' ){
                       ef.Document_type__c   =  channel.getText();
                   }
                   else if( channel.getName() == 'Language' ){
                       ef.Language__c  =  channel.getText();
                   }
                   else if( channel.getName() == 'no-name' ){
                       ef.no_name__c  =  channel.getText();
                   }
                   else if( channel.getName() == 'Product-category' ){
                       ef.Product_category__c   =  channel.getText();
                   }
                   else if( channel.getName() == 'Published' ){
                       ef.Published__c   =  channel.getText();
                   }
                   else if( channel.getName() == 'System-Title' ){
                       ef.System_Title__c    =  channel.getText();
                   }
                   else if( channel.getName() == 'Updated-date' ){
                       ef.Updated_date__c     =  channel.getText();
                       try{
                           datetime startDate = datetime.newInstance(0);
                           ef.Update_DateTime__c  = startDate.addSeconds(Integer.valueOf(channel.getText()));
                       }catch(Exception e){
                           System.debug('GlobalPRM_RssRetrieval Update-dateTime Exception:'+e.getMessage());
                       }

                   }
               }
           }
           if (ef.Nid__c != null){
               String namex = ef.File_Name__c;
               if (namex.length() > 49){
                   namex = namex.substring(0, 49);
               }
               ef.Name = namex;
               ef.Update_Indication__c = true;
               extFileList.add(ef); 
           }     

        }
        system.debug( 'list size:' + extFileList.size() );
        system.debug(extFileList);
        upsert extFileList Nid__c;
        return rssList;
        
    }
}

 
Is it possible to deploy a single Lighting App to a Production instance that is not 'Lightning Enabled'? 
I'm noticing when I use the Lightning Design System it's tacking on a aura class and a 'data-aura-rendered-by' attribute. What does this do?

Thanks.
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'm getting a null pointer exception on a for loop through list variable of a custom class. The loop was previously working  on an Sobject:

Class ProductsWrapper
global class ProductsWrapper {

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

Code that Errors Line 6
List<ProductsWrapper> products;
Map<Id, ProductsWrapper> cart;

public void handleTheBasket(){
      
        for(ProductsWrapper 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;
      
            } 
        
        }
        }
        
    }


 
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,

I need a way to identify a Contact as an Active Community user. I've added a field called Partner Community User? on the contact that I want to flip whenever a Contact is enabled as a Partner User. I've written some code using a @future calls to bypass the setup object error. 

I'm getting the 

"cannot insert update activate entity" error in my trigger.
Apex Trigger

trigger flipContactPartnerActive on User (after update) {

   //List<Contact> potentialContacts = [SELECT id, name FROM Contact WHERE Account.IsPartner = true AND Status__c ='Active' AND Email !='' ];
    //Map<Id, Contact> ContactMap = new Map<Id,Contact>();
    Contact upcon = new Contact();
    
    
   // for(Contact con:potentialContacts){
    //    if(con !=null){
    //      ContactMap.put(con.id, con);
    //        }
        
   // } 
    
    for(User usr: Trigger.new){
        if(usr.IsActive == true && usr.ContactId !=null && usr.UserType =='PowerPartner'){
         upcon.id = usr.ContactId;
            if(upcon != null){
            utilPartnerClassTrue upt = new utilPartnerClassTrue(upcon.id);
            }
 
        }
        if(usr.IsActive == false && usr.ContactId !=null && usr.UserType =='PowerPartner'){
         upcon.id = usr.ContactId;
            if(upcon != null){
            utilPartnerClassFalse upf = new utilPartnerClassFalse(upcon.id);
            }
        }
    }
    
}

APEX utillity classes
public class utilPartnerClassTrue {

    public utilPartnerClassTrue(Id cid){
        List<ID> ContactID = new List<ID>{cid};
            AddContactUserObject(ContactID);
        
    }
    
@future
private static void AddContactUserObject(List<id> cid){
    Contact co = [SELECT id, Partner_Community_Access__c FROM Contact WHERE id = :cid[0] ];   
    if(co != null){
    	if(co.Partner_Community_Access__c != 'Yes'){
    	   co.Partner_Community_Access__c = 'Yes';
        system.debug(co);
    }
  update co;
        system.debug(co);
    }
  
}   
    
    
}
 
public class utilPartnerClassFalse {

    public utilPartnerClassFalse(Id cid){
        List<ID> ContactID = new List<ID>{cid};
            AddContactUserObject(ContactID);
        
    }
    
@future
private static void AddContactUserObject(List<id> cid){
    Contact co = [SELECT id,Partner_Community_Access__c FROM Contact WHERE id = :cid[0] ];   
    if(co != null){
    	if(co.Partner_Community_Access__c != 'No'){
    	   co.Partner_Community_Access__c = 'No';
        system.debug(co);
    }
  update co;
    }
  
}   
    
    
}

 
Hello,

I wanted to force a user to authenticate before being able to access any pages on the site. Can this be done in the settings? Or do I need to code this? Where would I start to check if a user is authenticated and has an active sessesion ID.

Thanks.
I've got a trigger that's throwing the following error:

Error:

shareBackCase: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: [] Trigger.shareBackCase: line 19, column 1


What I'm trying to do is when a case is assigned to a Queue I want the user to be able to access the case with "Read" access. I can't seem to get the Sharing Rule to insert. What do I need to do fix?
 
trigger shareBackCase on Case (after insert) {
	ID recordTypeId = [SELECT Id, Name FROM RecordType WHERE name ='Commissions' LIMIT 1].id;
    System.debug(recordTypeId);
    List <CaseShare> newCazeList = new List<CaseShare>();

    for(Case c:Trigger.new){
       CaseShare newCaze = new CaseShare();
        System.debug(c.RecordTypeId);
        if(c.RecordTypeId == recordTypeId){
            newCaze.CaseId = c.Id;
            newCaze.UserOrGroupId = c.CreatedById;
        	newCaze.CaseAccessLevel = 'Read';
            newCaze.RowCause = 'Manual';
            newCazeList.add(newCaze);
        }

    }
    
    insert newCazeList;
}

My org is a private sharing model.
I want to hide the Employee field if Scope = "individual sales". Can't get the javascript to fire. I have a onchange attribute on the Scope field calling the hideEmployee() function. I want to hide

JS
function hideEmployee(){
        var employee1 = document.getElementById('{!$Component.frm:comMainCommissions:comFirst:employee:employeeField}');
        var scopez = document.getElementById('{!$Component.frm:comMainCommissions:comFirst:scopes:scopesField}');
            if(scopez == 'Individual Sales'){
             
                employee1.style.display = 'none';
            
            }
            else{
       
            employee1.style.display = 'inline';
            }
        reRenderEmployee();
        }

Visualforce
<apex:actionFunction name="reRenderEmployee" reRender="employee" />
        <apex:sectionHeader rendered="{!isCaseEdit}" title="Case Edit" subtitle="{!objCase.CaseNumber}"/>
        <apex:sectionHeader rendered="{!isCaseNew}" title="New Case" subtitle="{!objCase.CaseNumber}"/>
        
        <!-- Commissions -->
        <apex:pageBlock id="comMainCommissions" title="Case Edit" rendered="{!IsCommissionsRecType}" >
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!saveCase}"/>
                 <apex:commandButton value="Save & Close" action="{!saveAndCloseCase}"/>
                <apex:commandButton value="Cancel" immediate="true" action="{!cancelCase}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection id="comFirst" title="Case Information" >
                                   
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Case Owner"></apex:outputLabel>
                    <apex:outputField value="{!objCase.ownerid}"/>                   
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                
                    <apex:outputLabel value="Status"/>
                    <apex:inputField required="true" value="{!objCase.status}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Reason Re-opened" />
                    <apex:inputField required="true" value="{!objCase.Reason_Re_opened__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Case Number" />
                    <apex:inputField value="{!objCase.CaseNumber}"/>
                </apex:pageBlockSectionItem>
      
				<apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Case Record Type"/>
                    <apex:outputField value="{!objCase.RecordTypeId}"/>
                </apex:pageBlockSectionItem>
				<apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Request Type" />
                    <apex:inputField required="true" value="{!objCase.Request_Type__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Priority.inlineHelpText}" rendered="{!!ispivCLASS}">                   
                    <apex:outputLabel value="Priority" />
                    <apex:inputField value="{!objCase.Priority}"/>
                </apex:pageBlockSectionItem>
                

            	
   				
                <apex:pageBlockSectionItem id="scopes" HelpText="{!$ObjectType.Case.fields.Scope__c.inlineHelpText}" >                   
                    <apex:outputLabel value="Scope" />
                    <apex:inputField required="true" value="{!objCase.Scope__c}" id="scopesField" onchange="hideEmployee()"/>
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Case Origin" />
                    <apex:inputField required="true" value="{!objCase.Origin}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem id="employee" HelpText="{!$ObjectType.Case.fields.Employee__c.inlineHelpText}" >                   
                    <apex:outputLabel value="Employee" />
                    <apex:inputField required="true"  id="employeeField" value="{!objCase.Employee__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Invoice_Number__c.inlineHelpText}" >                   
                    <apex:outputLabel value="Invoice Number" />
                    <apex:inputField required="false" value="{!objCase.Invoice_Number__c}"/>
                </apex:pageBlockSectionItem>
       			<apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Organization" />
                    <apex:inputField required="true" value="{!objCase.Organization__c}"/>
                </apex:pageBlockSectionItem>

                
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Period" />
                    <apex:inputField required="true" value="{!objCase.Period__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Region" />
                    <apex:inputField required="true" value="{!objCase.Region__c}"/>
                </apex:pageBlockSectionItem>
        
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Year" />
                    <apex:inputField required="true" value="{!objCase.Year__c}"/>
                </apex:pageBlockSectionItem>
                
           
            </apex:pageBlockSection>
           
            
         
           
            <apex:pageBlockSection title="Description Information" id="Desc">
                <apex:pageBlockSectionItem id="DescriptionSection">                   
                    <apex:outputLabel value="Subject"/>                    
                    <apex:inputField id="subject" required="{!isCustService}" style="width:500px;" value="{!objCase.Subject}"/>
                </apex:pageBlockSectionItem>                
                <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Description"/>                    
                    <apex:inputField style="width:450px;height:100px;" value="{!objCase.Description}"/>
                </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Internal Comments"/>                    
                    <apex:inputField style="width:450px;height:100px;" value="{!objCaseComment.CommentBody}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
           
       
            
            <apex:pageBlockSection title="Web Information">
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Web Email"/>                    
                    <apex:inputField value="{!objCase.SuppliedEmail}"/>
                </apex:pageBlockSectionItem>                 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Web Company"/>                    
                    <apex:inputField value="{!objCase.SuppliedCompany}"/>
                </apex:pageBlockSectionItem>  
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Web Name"/>                    
                    <apex:inputField value="{!objCase.SuppliedName}"/>
                </apex:pageBlockSectionItem>  
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Web Phone"/>                    
                    <apex:inputField value="{!objCase.SuppliedPhone}"/>
                </apex:pageBlockSectionItem>            
            </apex:pageBlockSection>
            <apex:pageBlockSection title="System Information">
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Source System"/>
                    <apex:outputPanel >
                        <apex:outputfield rendered="{!!($Profile.Name=='System Administrator')}" value="{!objCase.Source_System__c}"/>                  
                        <apex:inputField rendered="{!$Profile.Name=='System Administrator'}" value="{!objCase.Source_System__c}"/>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>                 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Source System ID"/>
                    <apex:outputPanel >    
                        <apex:outputfield rendered="{!!($Profile.Name=='System Administrator')}" value="{!objCase.Source_System_ID__c}"/>                               
                        <apex:inputField rendered="{!$Profile.Name=='System Administrator'}" value="{!objCase.Source_System_ID__c}"/>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>  
                <apex:pageBlockSectionItem >                   
                </apex:pageBlockSectionItem>  
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Checked for Spam"/>                    
                    <apex:inputField value="{!objCase.Checked_for_Spam__c}"/>
                </apex:pageBlockSectionItem>            
            </apex:pageBlockSection>
        </apex:pageBlock>

 
Hello,

I'm a bit stumped in my own code. I've got some JavaScript that calls an ActionFunction that then is supposed to rerender an id called "sensorSku". I have no idea where this id is in my visualforce code. Does the ActionFunction call something less explicit like 'sensorskusection' ? There isn't an Id with "sensorSku' in my Visualforce at all. The code is targeting the Sensor_SKU__c field.

JavaScript
function setSSKU(){
            
            var SSKUE = document.getElementById('{!$Component.frm:pbMainLumidigm:LumidigmSection:sensorSkuSection:sensorSkuif}');
            var model = document.getElementById('{!$Component.frm:pbMainLumidigm:caseRoutingSection:SSKUSectionItem:LuModel}').value;
            if(model=='M-Series'){
                for(i=0; i < SSKUE.options.length; i++){
     				if(SSKUE.options[i].text.toString().indexOf('V') >= 0){
                        SSKUE.options[i].style.display = 'none';
                        SSKUE.options[i].setAttribute("disabled","disabled");
                       
                        }
                    if(SSKUE.options[i].text.toString().indexOf('M') >= 0){
                        if(SSKUE.options[i].style.display == 'none'){
                            SSKUE.options[i].style.display ='block';
                        	SSKUE.options[i].removeAttribute("disabled");
                        }
                    }
                }
            }
            
            if(model=='V-Series'){
                for(i=0; i < SSKUE.options.length; i++){
     				if(SSKUE.options[i].text.toString().indexOf('M') >= 0){
                        SSKUE.options[i].style.display = 'none';
    					SSKUE.options[i].setAttribute("disabled","disabled");
            	    }
                    if(SSKUE.options[i].text.toString().indexOf('V')>=0){
                        if(SSKUE.options[i].style.display =='none'){
                            SSKUE.options[i].style.display = 'block';
                            SSKUE.options[i].removeAttribute("disabled");
                        }
                    }
                }
            }
                
            reRenderSSKU();
        }

Visualforce
<apex:actionFunction reRender="pbsResInfo" immediate="true" action="{!showProblemCode}" name="callshowProblemCode">
            <apex:param value="drdValue" name="drdValue"/>
        </apex:actionFunction>
        <apex:actionFunction name="reRenderSSKU" reRender="sensorSku"/>
        <apex:sectionHeader rendered="{!isCaseEdit}" title="Case Edit" subtitle="{!objCase.CaseNumber}"/>
        <apex:sectionHeader rendered="{!isCaseNew}" title="New Case" subtitle="{!objCase.CaseNumber}"/>
        
        <!-- Lumidigm -->
        <apex:pageBlock id="pbMainLumidigm" title="Case Edit" rendered="{!IsLumidigmRecType}">
  
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!saveCase}" onclick="return validateChannelPartner();"/>
                 <apex:commandButton value="Save & Close" action="{!saveAndCloseCase}" onclick="return validateChannelPartner();"/>
                <apex:commandButton value="Cancel" immediate="true" action="{!cancelCase}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection id="pbsFirst" title="Case Information" >
            <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Parent Case"></apex:outputLabel>
                    <apex:inputField value="{!objCase.ParentId}"/>                   
                </apex:pageBlockSectionItem>                                   
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Case Owner"></apex:outputLabel>
                    <apex:outputField value="{!objCase.ownerid}"/>                   
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Case Record Type"/>
                    <apex:outputField value="{!objCase.RecordTypeId}"/>
                </apex:pageBlockSectionItem>
               <apex:pageBlockSectionItem id="pbsItemaccName" >                   
                    <apex:outputLabel value="Account Name"/>
                    <apex:outputPanel id="opAccName">                       
                        <apex:outputLabel id="txtAccName" value="{!strAccName}"/>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>  
                <apex:pageBlockSectionItem >                
                    <apex:outputLabel value="Status"/>
                    <apex:inputField required="true" value="{!objCase.status}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Contact Name"/>
                        <apex:ActionRegion >
                            <apex:actionFunction name="callsetAccountName" rerender="opAccName, opchPartnerAcc" action="{!setAccountName}">
                                <apex:param value="" name="purcPath"/>
                            </apex:actionFunction>
                            <apex:inputField onChange="setAccountName();" value="{!objCase.ContactId}" required="true"/>
                        </apex:ActionRegion>
                </apex:pageBlockSectionItem>     
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Reason_Re_opened__c.inlineHelpText}">                   
                    <apex:outputLabel value="Reason Re-opened"/>                    
                    <apex:inputField value="{!objCase.Reason_Re_opened__c}"/>
                </apex:pageBlockSectionItem>
                                   
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Test Track Pro Item Number"/>
                    <apex:inputField value="{!objCase.Test_Track_Pro_Item_Number__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Case Origin" />
                    <apex:inputField required="true" value="{!objCase.Origin}"/>
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Priority.inlineHelpText}" rendered="{!!ispivCLASS}">                   
                    <apex:outputLabel value="Priority" />
                    <apex:inputField value="{!objCase.Priority}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Support_Level__c.inlineHelpText}" >                   
                    <apex:outputLabel value="Support Level" />
                    <apex:inputField required="true" value="{!objCase.Support_Level__c}"/>
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Time_Spent__c.inlineHelpText}">                   
                    <apex:outputLabel value="Time Spent" />
                    <apex:inputField rendered="true" value="{!objCase.Time_Spent__c}"/>
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Repair Time" />
                    <apex:inputField value="{!objCase.Repair_Time__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Visible in Self-Service Portal" />
                    <apex:inputField value="{!objCase.IsVisibleInSelfService}"/>
                </apex:pageBlockSectionItem>
               <!--<apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Is this an Order Issue"/>
                    <apex:inputField required="true" id="selPurchasePath" value="{!objCase.Order_Issue__c}" />                        
                </apex:pageBlockSectionItem>-->          
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Case_Language__c.inlineHelpText}">                   
                    <apex:outputLabel value="Case Language" />
                    <apex:inputField required="true" value="{!objCase.Case_Language__c}"/>
                </apex:pageBlockSectionItem>                
               <!--<apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Reason for Contact" />
                    <apex:inputField required="true" value="{!objCase.Reason_for_Contact__c}"/>             
                </apex:pageBlockSectionItem>-->                 
                
                <apex:pageBlockSectionItem id="pbitemPurchasepath">                   
                    <apex:outputLabel value="Purchase Path"/>
                    <apex:inputField id="selPurchasePath" value="{!objCase.Purchase_Path__c}" onchange="return setChannelPartAcc(this,'{!$Component.pbsItemCPA.txtCPA}','{!$Component.pbsItemaccName:txtAccName}');"/>                        
                </apex:pageBlockSectionItem>    
                <apex:pageBlockSectionItem >  
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem id="pbsItemCPA">                   
                    <apex:outputLabel value="Channel Partner account"/>
                    <apex:outputPanel id="opchPartnerAcc">
                        <div id="dvchannelPartner">
                            <apex:inputField id="txtCPA" value="{!objCase.Channel_Partner_account__c}"/>
                        </div>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >  
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem >  
                </apex:pageBlockSectionItem>    
                
                <apex:pageBlockSectionItem >  
                </apex:pageBlockSectionItem>
                
            </apex:pageBlockSection>    
            <apex:pageBlockSection title="Additional Information" rendered="{!isCustService}">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Region"></apex:outputLabel>
                    <apex:inputField required="true" value="{!objCase.Region__c}"/>                   
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection> 
            <apex:pageBlockSection title="Product Information" rendered="{!isCustService}">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Product"></apex:outputLabel>
                    <apex:inputField value="{!objCase.Product__c}"/>                   
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Model"></apex:outputLabel>
                    <apex:inputField id="SSKU" value="{!objCase.Model__c}" onchange="setSSKU()"/>                   
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Contract Information" rendered="{!ispivCLASS}">
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Serial_License_No_Lookup__c.inlineHelpText}">                   
                    <apex:outputLabel value="Serial/License No. Lookup"/>
                    <apex:inputField value="{!objCase.Serial_License_No_Lookup__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Contract"/>
                    <apex:inputField value="{!objCase.Contract__c}"/>
                </apex:pageBlockSectionItem>
                
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Case Routing" id="caseRoutingSection">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Region"></apex:outputLabel>
                    <apex:inputField required="{!If(ispivCLASS == true,false,true)}" value="{!objCase.Region__c}"/>                   
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Firmware"/>
                    <apex:inputField value="{!objCase.Firmware__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Product"/>
                    <apex:inputField required="true" value="{!objCase.Product__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Driver"/>
                    <apex:inputField value="{!objCase.Driver__c}"/>
                </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem id="SSKUSectionItem">
                    <apex:outputLabel value="Model"></apex:outputLabel>
                    <apex:inputField id="LuModel" required="true" value="{!objCase.Model__c}" onchange="setSSKU()"/>                   
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Software"/>
                    <apex:inputField value="{!objCase.Software__c}"/>
                </apex:pageBlockSectionItem>
          
                

                
                
                
                <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType || ispivCLASS}">                   
                    <apex:outputLabel value="OS Language"/>
                    <apex:inputField value="{!objCase.OS_Language__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType}">                   
                    <apex:outputLabel value="Configuration Card Part #"/>
                    <apex:inputField value="{!objCase.Configuration_Card_Part__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType || ispivCLASS}" >                   
                    <apex:outputLabel value="Allow Remote Support"/>                    
                    <apex:inputField value="{!objCase.Allow_Remote_Support__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem rendered="{!isPAERecType}" > 
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem rendered="{!isPAERecType}" > 
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem rendered="{!isPAERecType}" > 
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem rendered="{!isPAERecType}" > 
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockSection Title="Lumidigm" rendered="{!IsLumidigmRecType}" id="LumidigmSection">
            <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Printer_Serial_Number_or_Asure_ID__c.inlineHelpText}">                   
                    <apex:outputLabel value="License Key/Serial Number"/>
                    
                    <!--<apex:inputField value="{!objCase.Serial_License_No_Lookup__c}"/>-->
                    <apex:inputField value="{!objCase.Printer_Serial_Number_or_Asure_ID__c}"/>
             </apex:pageBlockSectionItem>
                <apex:pageblocksectionitem >
                    <apex:outputLabel value="Module/Part #" />
                        <apex:inputField value="{!objCase.Lumidigm_Part__c}" />
                    </apex:pageblocksectionitem>
                <apex:pageblocksectionitem >
                        <apex:outputLabel value="Help Topic" />
                        <apex:inputField value="{!objCase.Help_Topic__c}" required="true"/>
                  </apex:pageblocksectionitem>
                
                    <apex:pageblocksectionitem id="sensorSkuSection">
                        <apex:outputLabel value="Sensor SKU"/>
                        <apex:inputField id="sensorSkuif" value="{!objCase.Sensor_SKU__c}" required="true"/>
                    </apex:pageblocksectionitem>
                <apex:pageblocksectionitem >
                        <apex:outputLabel value="Integration Package"/>
                        <apex:inputField value="{!objCase.Integration_Package__c}"/>
                    </apex:pageblocksectionitem>
            <apex:pageblocksectionitem >
                        <apex:outputLabel value="OS" />
                        <apex:inputField value="{!objCase.OS__c}" />
                    </apex:pageblocksectionitem>
                      
                	
                    
                    <apex:pageblocksectionitem >
                    <apex:outputLabel value="Implementation Language"/>
                    <apex:inputField value="{!objCase.Implementation_Language__c}"/>
                    </apex:pageblocksectionitem>                                              
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Description Information" id="Desc">
                <apex:pageBlockSectionItem id="DescriptionSection">                   
                    <apex:outputLabel value="Subject"/>                    
                    <apex:inputField id="subject" required="{!isCustService}" style="width:500px;" value="{!objCase.Subject}"/>
                </apex:pageBlockSectionItem>                
                <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Description"/>                    
                    <apex:inputField style="width:450px;height:100px;" value="{!objCase.Description}"/>
                </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Internal Comments"/>                    
                    <apex:inputField style="width:450px;height:100px;" value="{!objCaseComment.CommentBody}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Resolution Information" rendered="{!!isCustService}">
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType || ispivCLASS || isLumidigmRecType }">                   
                    <apex:outputLabel value="Category"/>                    
                    <apex:inputField required="true" value="{!objCase.Category__c}"/>
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem rendered="{!isPAERecType || isLaserCardRecType}">                   
                    <apex:outputLabel value="Problem Code"/>
                    
                   <apex:inputField required="true" value="{!objCase.Problem_Code_NewList__c}"/>
                </apex:pageBlockSectionItem>
                    
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Shipping Information" rendered="{!!isCustService && !ispivCLASS }">
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Use_Contact_Address_for_Shipping__c.inlineHelpText}">                   
                    <apex:outputLabel value="Use Contact Address for Shipping" />                    
                    <apex:inputField value="{!objCase.Use_Contact_Address_for_Shipping__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Via"/>                    
                    <apex:inputField value="{!objCase.Via__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType}">                   
                    <apex:outputLabel value="Shipping From HID Region"/>                    
                    <apex:inputField value="{!objCase.Shipping_From_HID_Region__c}"/>
                </apex:pageBlockSectionItem>                 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Attention"/>                    
                    <apex:inputField value="{!objCase.Attention__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Shipping Account #"/>                    
                    <apex:inputField value="{!objCase.Shipping_Account__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Shipping Address"/>                    
                    <apex:inputField value="{!objCase.Shipping_Address__c}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
 
            <apex:pageBlockSection rendered="{!isRCNHRecType}" title="Product to Ship Information">
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Product Description 1" />                    
                    <apex:inputField value="{!objCase.Product_Description_1__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Quantity 1"/>                    
                    <apex:inputField value="{!objCase.Quantity_1__c}"/>
                </apex:pageBlockSectionItem>                 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Product Description 2" />                    
                    <apex:inputField value="{!objCase.Product_Description_2__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Quantity 2"/>                    
                    <apex:inputField value="{!objCase.Quantity_2__c}"/>
                </apex:pageBlockSectionItem><apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Product Description 3" />                    
                    <apex:inputField value="{!objCase.Product_Description_3__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Quantity 3"/>                    
                    <apex:inputField value="{!objCase.Quantity_3__c}"/>
                </apex:pageBlockSectionItem><apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Product Description 4" />                    
                    <apex:inputField value="{!objCase.Product_Description_4__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Quantity 4"/>       
                    <apex:inputField value="{!objCase.Quantity_4__c}"/>
                </apex:pageBlockSectionItem><apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Product Description 5" />                    
                    <apex:inputField value="{!objCase.Product_Description_5__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Quantity 5"/>                    
                    <apex:inputField value="{!objCase.Quantity_5__c}"/>
                </apex:pageBlockSectionItem><apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Product Description 6" />                    
                    <apex:inputField value="{!objCase.Product_Description_6__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Quantity 6"/>                    
                    <apex:inputField value="{!objCase.Quantity_6__c}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
           


 
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.
 
I've got a Test class that when an Opportunity is "blank saved" the Primary Contact is pulled from the OpportunityContactRole and dropped into a field called "Primary Contact" on the Opportunity. I cannot get any code coverage and the Primary Contact field isn't populating. How can I mimic a save?
 
isTest public class TestContactRolePop { static testMethod void validateOppContact(){ Test.startTest(); Account nAcc = new Account(Name='Test Well Opp'); insert nAcc; system.debug(nAcc); Opportunity nOpp = new Opportunity(Name='Test Well Opp',CloseDate=date.parse('10/31/2015'), Account=nAcc, RecordTypeId='01280000000PyvL', Region__c='NAM', Opportunity_Type__c='Project',StageName='Discovery', Business_Segment__c='Animal ID', Dominant_Technology__c='Edge',Type='One-shot revenue' ); insert nOpp; system.debug(nOpp.Primary_Contact__c); Contact nCon = new Contact(FirstName='Testy',LastName='Test', Account=nAcc, Pricing_Notifications__c='No'); insert nCon; system.debug(nCon); OpportunityContactRole nOppCon = new OpportunityContactRole(OpportunityId=nOpp.id, IsPrimary=true,ContactId=nCon.Id); insert nOppCon; system.debug(nOppCon); update nOpp; system.debug(nOpp.Primary_Contact__c); system.assertEquals(nOpp.Primary_Contact__c,nCon.Name); Test.stopTest(); } }


Trigger
trigger ContactRoleName on Opportunity (before update) { Map<Id,String> mapOppIdWithConLN = new Map<Id,String>(); for(OpportunityContactRole oCR:[select Id, IsPrimary, Contact.Name,Contact.LastName, OpportunityId FROM OpportunityContactRole where opportunityId IN :Trigger.new and isprimary = true]){ mapOppIdWithConLN.put(oCR.OpportunityId, oCR.Contact.Name); } for(Opportunity opp:Trigger.new){ if(mapOppIdWithConLN.containsKey(opp.id)){ opp.Primary_Contact__c = mapOppIdWithConLN.get(opp.id); } } }


 
I've got a Test class that when an Opportunity is "blank saved" the Primary Contact is pulled from the OpportunityContactRole and dropped into a field called "Primary Contact" on the Opportunity. I cannot get any code coverage and the Primary Contact field isn't populating. How can I mimic a save?

Test Class
@isTest

public class TestContactRolePop {

    
    static testMethod void validateOppContact(){
        Test.startTest();
        
        	Account nAcc = new Account(Name='Test Well Opp');
        	insert nAcc;
        system.debug(nAcc);
        	Opportunity nOpp = new Opportunity(Name='Test Well Opp',CloseDate=date.parse('10/31/2015'), Account=nAcc, RecordTypeId='01280000000PyvL', Region__c='NAM', Opportunity_Type__c='Project',StageName='Discovery', Business_Segment__c='Animal ID', Dominant_Technology__c='Edge',Type='One-shot revenue' );
            insert nOpp;
        system.debug(nOpp.Primary_Contact__c);
    		Contact nCon = new Contact(FirstName='Testy',LastName='Test', Account=nAcc, Pricing_Notifications__c='No');
        	insert nCon;
        system.debug(nCon);
        	OpportunityContactRole nOppCon = new OpportunityContactRole(OpportunityId=nOpp.id, IsPrimary=true,ContactId=nCon.Id);
			insert nOppCon;
        system.debug(nOppCon);
            update nOpp;

        system.debug(nOpp.Primary_Contact__c);
system.assertEquals(nOpp.Primary_Contact__c,nCon.Name);
        
    	Test.stopTest();
        
        
    }
}
Trigger
trigger ContactRoleName on Opportunity (before update) {
    
    
    Map<Id,String> mapOppIdWithConLN = new Map<Id,String>();
    
    for(OpportunityContactRole oCR:[select Id, IsPrimary, Contact.Name,Contact.LastName, OpportunityId FROM OpportunityContactRole where opportunityId IN :Trigger.new and isprimary = true]){
        
        mapOppIdWithConLN.put(oCR.OpportunityId, oCR.Contact.Name);
    }

    for(Opportunity opp:Trigger.new){
        if(mapOppIdWithConLN.containsKey(opp.id)){
            opp.Primary_Contact__c = mapOppIdWithConLN.get(opp.id);
        }
        
    }
}


 
I've got my setSSKU() function setup to fire on the Model field, but I can't get my code to set the values on the Model and SKU(
<apex:inputField id="SSKU" value="{!objCase.Sensor_SKU__c}"/>
) fields. This code workw the the <apex:form> tag not sure why it's not working on this page.

JS
function setSSKU(){ var SSKUE = document.getElementById('{!$Component.pbMainLumidigm:SSKU}'); var model = document.getElementById('{!$Component.pbMainLumidigm:LuModel}').value; if(model=='M-Series'){ for(i=0; i < SSKUE.options.length; i++){ if(SSKUE.options[i].text.indexOf('V') >= 0){ SSKUE.options[i].style.display = 'none'; } if(SSKUE.options[i].text.indexOf('M') >= 0){ if(SSKUE.options[i].style.display == 'none'){ SSKUE.options[i].style.display ='block'; } } } } if(model=='V-Series'){ for(i=0; i < SSKUE.options.length; i++){ if(SSKUE.options[i].text.indexOf('M') >= 0){ SSKUE.options[i].style.display = 'none'; } if(SSKUE.options[i].text.indexOf('V')>=0){ if(SSKUE.options[i].style.display =='none'){ SSKUE.options[i].style.display = 'block'; } } } } }




Visualforce
<apex:pageBlock id="pbMainLumidigm" title="Case Edit" rendered="{!IsLumidigmRecType}"> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!saveCase}" onclick="return validateChannelPartner();"/> <apex:commandButton value="Save & Close" action="{!saveAndCloseCase}" onclick="return validateChannelPartner();"/> <apex:commandButton value="Cancel" immediate="true" action="{!cancelCase}"/> </apex:pageBlockButtons> <apex:pageBlockSection id="pbsFirst" title="Case Information" > <apex:pageBlockSectionItem > <apex:outputLabel value="Parent Case"></apex:outputLabel> <apex:inputField value="{!objCase.ParentId}"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlockSection> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Product"/> <apex:inputField required="true" value="{!objCase.Product__c}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Model"></apex:outputLabel> <apex:inputField id="LuModel" required="true" value="{!objCase.Model__c}" onchange="setSSKU()"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > </apex:pageBlockSectionItem> <apex:pageBlockSectionItem rendered="{!isRCNHRecType || ispivCLASS}"> <apex:outputLabel value="OS Language"/> <apex:inputField value="{!objCase.OS_Language__c}"/> </apex:pageBlock>

 
I've got my setSSKU() function setup to fire on the Model field, but I can't get my code to set the values on the Model and SKU(
<apex:inputField id="SSKU" value="{!objCase.Sensor_SKU__c}"/>
) fields. This code workw the the <apex:form> tag not sure why it's not working on this page.

JS
function setSSKU(){
        var SSKUE = document.getElementById('{!$Component.pbMainLumidigm:SSKU}');
        var model = document.getElementById('{!$Component.pbMainLumidigm:LuModel}').value;
        if(model=='M-Series'){
            
        for(i=0; i < SSKUE.options.length; i++){
        if(SSKUE.options[i].text.indexOf('V') >= 0){
        SSKUE.options[i].style.display = 'none';
                   
         }
         if(SSKUE.options[i].text.indexOf('M') >= 0){
          if(SSKUE.options[i].style.display == 'none'){
              SSKUE.options[i].style.display ='block';
           }
        }
         }
         }
        
        if(model=='V-Series'){
            for(i=0; i < SSKUE.options.length; i++){
 				if(SSKUE.options[i].text.indexOf('M') >= 0){
                    SSKUE.options[i].style.display = 'none';

        	}
                if(SSKUE.options[i].text.indexOf('V')>=0){
                    if(SSKUE.options[i].style.display =='none'){
                        SSKUE.options[i].style.display = 'block';
                        }
                    }
           }
            }

        }

Visualforce
<apex:pageBlock id="pbMainLumidigm" title="Case Edit" rendered="{!IsLumidigmRecType}">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!saveCase}" onclick="return validateChannelPartner();"/>
                 <apex:commandButton value="Save & Close" action="{!saveAndCloseCase}" onclick="return validateChannelPartner();"/>
                <apex:commandButton value="Cancel" immediate="true" action="{!cancelCase}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection id="pbsFirst" title="Case Information" >
            <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Parent Case"></apex:outputLabel>
                    <apex:inputField value="{!objCase.ParentId}"/>                   
                </apex:pageBlockSectionItem>                                   
 
                                   
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Test Track Pro Item Number"/>
                    <apex:inputField value="{!objCase.Test_Track_Pro_Item_Number__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Case Origin" />
                    <apex:inputField required="true" value="{!objCase.Origin}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Serial_License_No_Lookup__c.inlineHelpText}">                   
                    <apex:outputLabel value="Serial/License No. Lookup"/>
                    <apex:inputField value="{!objCase.Serial_License_No_Lookup__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Priority.inlineHelpText}" rendered="{!!ispivCLASS}">                   
                    <apex:outputLabel value="Priority" />
                    <apex:inputField value="{!objCase.Priority}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Support_Level__c.inlineHelpText}">                   
                    <apex:outputLabel value="Support Level" />
                    <apex:inputField required="true" value="{!objCase.Support_Level__c}"/>
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Time_Spent__c.inlineHelpText}">                   
                    <apex:outputLabel value="Time Spent" />
                    <apex:inputField rendered="true" value="{!objCase.Time_Spent__c}"/>
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Repair Time" />
                    <apex:inputField value="{!objCase.Repair_Time__c}"/>
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Visible in Self-Service Portal" />
                    <apex:inputField value="{!objCase.IsVisibleInSelfService}"/>
                </apex:pageBlockSectionItem>
    <!--            <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Is this an Order Issue"/>
                    <apex:inputField required="true" id="selPurchasePath" value="{!objCase.Order_Issue__c}" />                        
                </apex:pageBlockSectionItem>          -->
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Case_Language__c.inlineHelpText}">                   
                    <apex:outputLabel value="Case Language" />
                    <apex:inputField required="true" value="{!objCase.Case_Language__c}"/>
                </apex:pageBlockSectionItem>                
    <!--            <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Reason for Contact" />
                    <apex:inputField required="true" value="{!objCase.Reason_for_Contact__c}"/>             
                </apex:pageBlockSectionItem>       -->            
                
                <apex:pageBlockSectionItem id="pbitemPurchasepath">                   
                    <apex:outputLabel value="Purchase Path"/>
                    <apex:inputField id="selPurchasePath" value="{!objCase.Purchase_Path__c}" onchange="return setChannelPartAcc(this,'{!$Component.pbsItemCPA.txtCPA}','{!$Component.pbsItemaccName:txtAccName}');"/>                        
                </apex:pageBlockSectionItem>    
                <apex:pageBlockSectionItem >  
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem id="pbsItemCPA">                   
                    <apex:outputLabel value="Channel Partner account"/>
                    <apex:outputPanel id="opchPartnerAcc">
                        <div id="dvchannelPartner">
                            <apex:inputField id="txtCPA" value="{!objCase.Channel_Partner_account__c}"/>
                        </div>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >  
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem >  
                </apex:pageBlockSectionItem>    
                
                <apex:pageBlockSectionItem >  
                </apex:pageBlockSectionItem>
                
            </apex:pageBlockSection>    
            <apex:pageBlockSection title="Additional Information" rendered="{!isCustService}">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Region"></apex:outputLabel>
                    <apex:inputField required="true" value="{!objCase.Region__c}"/>                   
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection> 
            <apex:pageBlockSection title="Product Information" rendered="{!isCustService}">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Product"></apex:outputLabel>
                    <apex:inputField value="{!objCase.Product__c}"/>                   
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Model"></apex:outputLabel>
                    <apex:inputField value="{!objCase.Model__c}"/>                   
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Contract Information" rendered="{!ispivCLASS}">
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Serial_License_No_Lookup__c.inlineHelpText}">                   
                    <apex:outputLabel value="Serial/License No. Lookup"/>
                    <apex:inputField value="{!objCase.Serial_License_No_Lookup__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Contract"/>
                    <apex:inputField value="{!objCase.Contract__c}"/>
                </apex:pageBlockSectionItem>
                
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Case Routing">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Region"></apex:outputLabel>
                    <apex:inputField required="{!If(ispivCLASS == true,false,true)}" value="{!objCase.Region__c}"/>                   
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Firmware"/>
                    <apex:inputField value="{!objCase.Firmware__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Product"/>
                    <apex:inputField required="true" value="{!objCase.Product__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Driver"/>
                    <apex:inputField value="{!objCase.Driver__c}"/>
                </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Model"></apex:outputLabel>
                    <apex:inputField id="LuModel" required="true" value="{!objCase.Model__c}" onchange="setSSKU()"/>                   
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Software"/>
                    <apex:inputField value="{!objCase.Software__c}"/>
                </apex:pageBlockSectionItem>
          
                

                
                
                
                <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType || ispivCLASS}">                   
                    <apex:outputLabel value="OS Language"/>
                    <apex:inputField value="{!objCase.OS_Language__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType}">                   
                    <apex:outputLabel value="Configuration Card Part #"/>
                    <apex:inputField value="{!objCase.Configuration_Card_Part__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType || ispivCLASS}" >                   
                    <apex:outputLabel value="Allow Remote Support"/>                    
                    <apex:inputField value="{!objCase.Allow_Remote_Support__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem rendered="{!isPAERecType}" > 
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem rendered="{!isPAERecType}" > 
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem rendered="{!isPAERecType}" > 
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem rendered="{!isPAERecType}" > 
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockSection Title="Lumidigm" rendered="{!IsLumidigmRecType}">
            <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Printer_Serial_Number_or_Asure_ID__c.inlineHelpText}">                   
                    <apex:outputLabel value="License Key/Serial Number"/>
                    
                    <!--<apex:inputField value="{!objCase.Serial_License_No_Lookup__c}"/>-->
                    <apex:inputField value="{!objCase.Printer_Serial_Number_or_Asure_ID__c}"/>
             </apex:pageBlockSectionItem>
                
                <apex:pageblocksectionitem >
                        <apex:outputLabel value="Help Topic" />
                        <apex:inputField value="{!objCase.Help_Topic__c}"/>
                  </apex:pageblocksectionitem>
                
                    <apex:pageblocksectionitem >
                        <apex:outputLabel value="Sensor SKU"/>
                        <apex:inputField id="SSKU" value="{!objCase.Sensor_SKU__c}"/>
                    </apex:pageblocksectionitem>
                <apex:pageblocksectionitem >
                        <apex:outputLabel value="Integration Package"/>
                        <apex:inputField value="{!objCase.Integration_Package__c}"/>
                    </apex:pageblocksectionitem>
            <apex:pageblocksectionitem >
                        <apex:outputLabel value="OS" />
                        <apex:inputField value="{!objCase.OS__c}" />
                    </apex:pageblocksectionitem>
                      
                	
                    
                    <apex:pageblocksectionitem >
                    <apex:outputLabel value="Implementation Language"/>
                    <apex:inputField value="{!objCase.Implementation_Language__c}"/>
                    </apex:pageblocksectionitem>                                              
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Description Information" id="Desc">
                <apex:pageBlockSectionItem id="DescriptionSection">                   
                    <apex:outputLabel value="Subject"/>                    
                    <apex:inputField id="subject" required="{!isCustService}" style="width:500px;" value="{!objCase.Subject}"/>
                </apex:pageBlockSectionItem>                
                <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Description"/>                    
                    <apex:inputField style="width:450px;height:100px;" value="{!objCase.Description}"/>
                </apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem >
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Internal Comments"/>                    
                    <apex:inputField style="width:450px;height:100px;" value="{!objCaseComment.CommentBody}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection title="Shipping Information" rendered="{!!isCustService && !ispivCLASS }">
                <apex:pageBlockSectionItem HelpText="{!$ObjectType.Case.fields.Use_Contact_Address_for_Shipping__c.inlineHelpText}">                   
                    <apex:outputLabel value="Use Contact Address for Shipping" />                    
                    <apex:inputField value="{!objCase.Use_Contact_Address_for_Shipping__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Via"/>                    
                    <apex:inputField value="{!objCase.Via__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType}">                   
                    <apex:outputLabel value="Shipping From HID Region"/>                    
                    <apex:inputField value="{!objCase.Shipping_From_HID_Region__c}"/>
                </apex:pageBlockSectionItem>                 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Attention"/>                    
                    <apex:inputField value="{!objCase.Attention__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Shipping Account #"/>                    
                    <apex:inputField value="{!objCase.Shipping_Account__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Shipping Address"/>                    
                    <apex:inputField value="{!objCase.Shipping_Address__c}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
 
            <apex:pageBlockSection rendered="{!isRCNHRecType}" title="Product to Ship Information">
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Product Description 1" />                    
                    <apex:inputField value="{!objCase.Product_Description_1__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Quantity 1"/>                    
                    <apex:inputField value="{!objCase.Quantity_1__c}"/>
                </apex:pageBlockSectionItem>                 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Product Description 2" />                    
                    <apex:inputField value="{!objCase.Product_Description_2__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Quantity 2"/>                    
                    <apex:inputField value="{!objCase.Quantity_2__c}"/>
                </apex:pageBlockSectionItem><apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Product Description 3" />                    
                    <apex:inputField value="{!objCase.Product_Description_3__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Quantity 3"/>                    
                    <apex:inputField value="{!objCase.Quantity_3__c}"/>
                </apex:pageBlockSectionItem><apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Product Description 4" />                    
                    <apex:inputField value="{!objCase.Product_Description_4__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Quantity 4"/>       
                    <apex:inputField value="{!objCase.Quantity_4__c}"/>
                </apex:pageBlockSectionItem><apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Product Description 5" />                    
                    <apex:inputField value="{!objCase.Product_Description_5__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Quantity 5"/>                    
                    <apex:inputField value="{!objCase.Quantity_5__c}"/>
                </apex:pageBlockSectionItem><apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Product Description 6" />                    
                    <apex:inputField value="{!objCase.Product_Description_6__c}"/>
                </apex:pageBlockSectionItem>      
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Quantity 6"/>                    
                    <apex:inputField value="{!objCase.Quantity_6__c}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="RMA Information" rendered="{!!ispivCLASS}">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="RMA Request"/>                    
                    <apex:inputField value="{!objCase.RMA_Case__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="RMA Technician"/>                    
                    <apex:inputField value="{!objCase.RMA_Technician__c}"/>
                </apex:pageBlockSectionItem> 
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="RMA Type (In)"/>                    
                    <apex:inputField value="{!objCase.RMA_Type__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="RMA Type (Out)"/>                    
                    <apex:inputField value="{!objCase.RMA_Type_Out__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="RMA Number (In)"/>                    
                    <apex:inputField value="{!objCase.RMA_Number_In__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="RMA Number (Out)"/>                    
                    <apex:inputField value="{!objCase.RMA_Number_Out__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="RMA Date (In)"/>                    
                    <apex:inputField value="{!objCase.RMA_Date_In__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="RMA Date (Out)"/>                    
                    <apex:inputField value="{!objCase.RMA_Date_Out__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="RMA Expiration Date"/>                    
                    <apex:inputField value="{!objCase.RMA_Expiration_Date__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType || isCustService}">
                    <apex:outputLabel value="Oracle RMA Creation Date"/>                    
                    <apex:inputField value="{!objCase.Oracle_RMA_Creation_Date__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType || isCustService}">
                    <apex:outputLabel value="RMA SF Date"/>                    
                    <apex:inputField value="{!objCase.RMA_SF_Date__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType || isCustService}">
                    <apex:outputLabel value="Advanced Replacement Created Date"/>                    
                    <apex:inputField value="{!objCase.Advanced_Replacement_Created_Date__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType || isCustService}">
                    <apex:outputLabel value="Oracle Disposition Date"/>                    
                    <apex:inputField value="{!objCase.Oracle_Disposition_Date__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType || isCustService}">
                    <apex:outputLabel value="RMA Received Date"/>                    
                    <apex:inputField value="{!objCase.RMA_Received_Date__c}"/>
                </apex:pageBlockSectionItem>
                
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType || isCustService}">
                    <apex:outputLabel value="RMA Tested Date"/>                    
                    <apex:inputField value="{!objCase.RMA_Tested_Date__c}"/>
                </apex:pageBlockSectionItem>    
                              
                <apex:pageBlockSectionItem rendered="{!isRCNHRecType || isCustService}">
                    <apex:outputLabel value="Replacement Shipped Date"/>                    
                    <apex:inputField value="{!objCase.Replacement_Shipped_Date__c}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Web Information">
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Web Email"/>                    
                    <apex:inputField value="{!objCase.SuppliedEmail}"/>
                </apex:pageBlockSectionItem>                 
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Web Company"/>                    
                    <apex:inputField value="{!objCase.SuppliedCompany}"/>
                </apex:pageBlockSectionItem>  
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Web Name"/>                    
                    <apex:inputField value="{!objCase.SuppliedName}"/>
                </apex:pageBlockSectionItem>  
                <apex:pageBlockSectionItem >                   
                    <apex:outputLabel value="Web Phone"/>                    
                    <apex:inputField value="{!objCase.SuppliedPhone}"/>
                </apex:pageBlockSectionItem>            
            </apex:pageBlockSection>
        
        </apex:pageBlock>

 
Hi All,

How can I hide picklist options if they contain a number?

For example hide picklist option if it contains "M"

JS
function setSSKU(){
        var SSKUE = document.getElementById('{!$Component.tktForm:SSKU}');
        var model = document.getElementById('{!$Component.tktForm:selModel}').value;
        var m = [];
        //var v = [];
        if(model=='M-Series'){
            
            for(i=0; i < SSKUE.options.length; i++){
 
                m.push(SSKUE[i]);
                //SSKUE.options[i].style.display ="none";
                console.log(m);
                }
            }
        
        if(model=='V-Series'){
            SSKUE.options[1].style.display ="none";
            SSKUE.options[2].style.display ="none";

        	
           }
            

        }

VF
<apex:outputpanel id="SSPanel" style="display: none;">    
             <div class="label" style="{!If(strLanguageCode=='ru','height:30px;','')}">
                <label for="SSKU" id='S_SKU'><span class="req">*</span>
                Sensor SKU:
              
                <!-- License Key/Serial Number -->
                </label> 
             </div>
             <div class="val" style="{!If(strLanguageCode=='ru','height:33px;','')}">
                 <apex:inputField id="SSKU" value="{!objCase.Sensor_SKU__c}"/>  
             </div>
            </apex:outputpanel>

 
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>

 
Is it possible to (securely) with SSO or some other method, to use Salesforce login credentials to access a third-party web application (Cornerstone for example)? How could I accomplish this? We do not a have a SAML server internally. What from a code perscpective would I need to create to do this?

​Thank you for your help. 
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>