• Daniel Mason
  • NEWBIE
  • 20 Points
  • Member since 2014


  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 31
    Replies

Afternoon Team, 

I think i am having one of these days where i cant do the basics in salesforce.

Aim : I would like the class below to only execute if the recordtype developername = "intermittent'". If the recordtype developername = "pending' then do nothing. Currently my class below executes on either Record type. "intermittent" or "pending ".

This is the query i use to Query RT Object for Flow object          
 select id,developername,Name from RecordType where SobjectType='flow__c' and developername='intermittent'  

I have created a trigger which calls an utils class

Trigger:

/********************************************************************
 * UpdateCurrencyInsert 
 *
 * Before Insert trigger on Flow
 ********************************************************************/
trigger UpdateCurrencyInsert on Flow__c (before insert) 
{
  FlowUtils.ValidateCurrencyUpdate(Trigger.new);
}
 

Class:

public class FlowUtils {
 
   public static void ValidateCurrencyUpdate(List<Flow__c> flows ) {


      List<Id> opportunityIds = new List<Id>();
      Map<Id, String> oppIdCurrencyCode = new Map<Id, String>();
      for (Flow__c Flow: flows ) {
          opportunityIds.add(Flow.opportunity__c);
      }
      
      for(Opportunity opp : [Select CurrencyIsoCode from Opportunity where Id in: opportunityIds]) {
        oppIdCurrencyCode.put(opp.Id, opp.CurrencyIsoCode);
      }
      
      for(Flow__c flow : flows) {
        flow.CurrencyIsoCode = oppIdCurrencyCode.get(flow.opportunity__c);
      }   
   }
 }
Looking forward to your help and advise 

Afternoon Team, 
I am hoping you can help me.
I have the created the following class & test class (see below) however i am getting Code Coverage 73% (45/61). Using the developer console i can see that i am not testing the following scenarios on these lines 72-76,82-84,95,98-105. I have been trying all week to increase my code coverage, but i am really struggling to find a solution

if its not to much bother is it possible if you can help me review my test class and get the code coverage above the 75% threshold needed so i can deploy.

Class

/*************************************************************************************************************************
Class Name      :   SalesMarketing
Class Desc.     :   Class used for Sales & Marketing Visual Force Page   
Author          :   DM
Description     :   This class is used to populate the Sales & Marketing VF component, displaying  Material Name,Product, 
                    item from Material_Records__c and Quantity from Materials_Junction__c. Records are selected from the 
                    page (using the checkbox) once an quantity is added the user pushes "save" these records will map 
                    back to the "Sales & Marketing" Object with relevant information selected.
                    
***************************************************************************************************************************/


public with sharing class SalesMarketing
{
    public List<Material_Records__c> Materials {get;set;} 
    public List<materialWrapper> materialWrapperList {get;set;} 
    public Materials_Junction__c marketingJunction {get;set;}
    public String searchString {get;set;} 
    public SalesMarketing(ApexPages.StandardController controller)
    //public SalesMarketing()
    {   
        system.debug('++ Inside Constructor ');
        marketingJunction = (Materials_Junction__c) controller.getRecord();
        materialWrapperList = new List<materialWrapper>();
        Materials = [select ID,name,Product__c, Item__c, Active__c from Material_Records__c where Active__c =true limit 10];
        for(Material_Records__c obj : Materials)
        {
            materialWrapper tempObj= new materialWrapper();
            tempObj.recordId = obj.id;
            tempObj.name = obj.name;
            tempObj.product = obj.Product__c;
            tempObj.item = obj.Item__c;
            tempObj.selectB = false;
            materialWrapperList.add(tempObj);
        }
    }
    
    public Pagereference getProductOrItemData(){
        materialWrapperList.clear();
        system.debug('+++ searchString is '+ searchString); 
        system.debug('+++ Length for searchString is '+ searchString.length());  
        //String searchVal= searchString.trim();
        String searchVal='%'+searchString.trim() +'%';
        system.debug('+++ searchString is '+ searchVal); 

         Materials = [select ID,name,Product__c, Item__c, Active__c from Material_Records__c where Active__c =true and (Product__c like :searchVal OR Item__c like :searchVal)];
        for(Material_Records__c obj : Materials)
        {   
            materialWrapper tempObj= new materialWrapper();
            tempObj.recordId = obj.id;
            tempObj.name = obj.name;
            tempObj.product = obj.Product__c;
            tempObj.item = obj.Item__c;
            tempObj.selectB = false;
            materialWrapperList.add(tempObj);
        }
        system.debug('+++ materialWrapperList is '+ materialWrapperList);
        system.debug('++ materialWrapperList size is '+ materialWrapperList.size());
        return null;
    }

    //save method
    public Pagereference save()
    {
        list<Materials_Junction__c> recordToInsert = new list<Materials_Junction__c>();
        try{
        for(materialWrapper obj : materialWrapperList)
        {
         Materials_Junction__c temp ;
            if(obj.selectB == true)
            {
               temp = new Materials_Junction__c();
               temp.sales_and_marketing__c = marketingJunction.sales_and_marketing__c;
               temp.Material_Records__c= obj.recordId;
               temp.quantity__C = obj.quantity; 
               recordToInsert.add(temp);
            }
            //recordToInsert.add(temp); you are adding element outside the if condition that the reason for save button error
        }
        insert recordToInsert; 
        return new Pagereference('/'+marketingJunction.sales_and_marketing__c);
        }catch(Exception e){
        ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.Error,e.getMessage()));
        return null;
        }       
    }
    
    
    public class materialWrapper
    {
        public string recordId {get; set;}
        public string name {get; set;}
        public string product {get; set;}
        public string item {get; set;}
        public Decimal quantity {get; set;}
        public boolean selectB {get; set;}
        
   public void materialWrapper()
       {
           recordId = '';
            name = '';
            product = '';
            item = '';
           quantity = 0.0;
           selectB = false;
       }
    }
}
 

Test Class
 

/*************************************************************************************************************************
Class Name      :   SalesMarketingTest
Author          :   Daniel Mason
Description     :   This test class creates a test record for Sales&Mkt. Also tests VF Page SalesMarketingNew   
Class Used      :   This test class ensure code coverage for NewMKtMaterialsRequest(100%) & SalesMarketing(83%)
***************************************************************************************************************************/   
@isTest
private class SalesMarketingTest
{
    static testmethod void  SalesMarketing()
    {
 
CoreDataTest.getData();


/**This is test data for Creating an Material Request*/          

        sales_and_marketing__c MKTRequest = new sales_and_marketing__c(
               Name = 'Test Name',
               Sales_Contact__c = CoreDataTest.contacts[1].id,
               Number_of_Attendees__c = decimal.valueof('20'),
               Business_Cards__c ='Yes',
                     //  Delivery_Date__c =   datatype "Date/Time" 
               Delivery_Date__c = DateTime.newInstance(2011, 11, 18, 3, 3, 3),
                   //Event_Date__c = datatype "Date" 
               Event_Date__c = Date.newInstance(2017,2,2),
               Delivery_Street__c = 'Test',
               Delivery_City__c  = 'Test',
               Delivery_State_Province__c = 'Test',
               Delivery_Zip_Postal_Code__c = 'Test',
               Delivery_Country__c = 'Test'
                   );
        insert MKTRequest;

/**This is test data for Creating an Material Record*/
        Material_Records__c MRecords= new Material_Records__c(
               Active__c = True,
               Item__c='United States',
               Product__c='Test Name');
        insert MRecords;

/** This is test data for Materials_Junction*/
        Materials_Junction__c MJunction= new Materials_Junction__c(
               Material_Records__c =MRecords.id,
               sales_and_marketing__c= MKTRequest.id);
        insert MJunction;

/**Checking that Materials_Junction__c has a record. */
        MJunction = [
            Select 
            Id, 
            Name, 
            Material_Records__c, 
            sales_and_marketing__c 
                From Materials_Junction__c 
            WHERE sales_and_marketing__r.id =:MKTRequest.Id 
            AND  Material_Records__r.id =:MRecords.id];
            
/**Debug logs*/            
            
system.debug('DAN MKTRequest.Sales_Contact__r.User__c'+MKTRequest.Sales_Contact__r.User__c);
system.debug('DAN MKTRequest.Sales_Contact__c'+MKTRequest.Sales_Contact__c);
system.debug('DAN CoreDataTest.users[0].Id'+CoreDataTest.users[0].Id);
system.debug(' Dan CoreDataTest.users[1].Id '+CoreDataTest.users[1].Id);
system.debug(' Dan UserInfo.getUserId(); '+UserInfo.getUserId());
system.debug(' Dan CoreDataTest.contacts[1].id; '+CoreDataTest.contacts[1].user__C);
            
/**System Assert Statements. Checking that Record has the correct value from insert statements*/

system.assertEquals(MKTRequest.Id, MJunction.sales_and_marketing__c); //Check that Sales& MKT Id is same as MKTRequest.Id
system.assertEquals(MRecords.Id, MJunction.Material_Records__c ); //Check that MaterialRecordsID is same as MRecords.Id

  
// Testing the VFpage: SalesMarketingNew  
ApexPages.StandardController mktnewcontroller= new ApexPages.StandardController(MKTRequest);
NewMKtMaterialsRequest extension = new NewMKtMaterialsRequest(mktnewcontroller); // controller extensionPageReference NewMKT= extension.RedirectToMKTRequest(); 
          

/***Wrapper */
        Test.StartTest();
        ApexPages.StandardController sc = new ApexPages.StandardController(MJunction);

        SalesMarketing controller = new SalesMarketing(sc);
        controller.searchString = 'Test Name';
        controller.getProductOrItemData();
        System.assertEquals(controller.save().getUrl(), '/'+MKTRequest.id);
        SalesMarketing.materialWrapper wrapper= new SalesMarketing.materialWrapper();
        Test.StopTest();
    }
}

 

i  have created a Class called "SalesMarketing" and i am writing the test class called "SalesMarketingTest" although the test class is passing the "SalesMarketing" class has 0% Code Coverage
 
/*************************************************************************************************************************
Class Name      :   SalesMarketing
Class Desc.     :   Class used for Sales & Marketing Visual Force Page   
Author          :   DM
Description     :   This class is used to populate the Sales & Marketing VF component, displaying  Material Name,Product, 
                    item from Material_Records__c and Quantity from Materials_Junction__c. Records are selected from the 
                    page (using the checkbox) once an quantity is added the user pushes "save" these records will map 
                    back to the "Sales & Marketing" Object with relevant information selected.

***************************************************************************************************************************/


public with sharing class SalesMarketing
{
    public List<Material_Records__c> Materials {get;set;} 
    public List<materialWrapper> materialWrapperList {get;set;} 
    public Materials_Junction__c marketingJunction {get;set;}
    public String searchString {get;set;} 
    public SalesMarketing(ApexPages.StandardController controller)
    //public SalesMarketing()
    {   
        system.debug('++ Inside Constructor ');
        marketingJunction = (Materials_Junction__c) controller.getRecord();
        materialWrapperList = new List<materialWrapper>();
        Materials = [select ID,name,Product__c, Item__c, Active__c from Material_Records__c where Active__c =true limit 10];
        for(Material_Records__c obj : Materials)
        {
            materialWrapper tempObj= new materialWrapper();
            tempObj.recordId = obj.id;
            tempObj.name = obj.name;
            tempObj.product = obj.Product__c;
            tempObj.item = obj.Item__c;
            tempObj.selectB = false;
            materialWrapperList.add(tempObj);
        }
    }

    public Pagereference getProductOrItemData(){
        materialWrapperList.clear();
        system.debug('+++ searchString is '+ searchString); 
        system.debug('+++ Length for searchString is '+ searchString.length());  
        //String searchVal= searchString.trim();
        String searchVal='%'+searchString.trim() +'%';
        system.debug('+++ searchString is '+ searchVal); 

         Materials = [select ID,name,Product__c, Item__c, Active__c from Material_Records__c where Active__c =true and (Product__c like :searchVal OR Item__c like :searchVal)];
        for(Material_Records__c obj : Materials)
        {   
            materialWrapper tempObj= new materialWrapper();
            tempObj.recordId = obj.id;
            tempObj.name = obj.name;
            tempObj.product = obj.Product__c;
            tempObj.item = obj.Item__c;
            tempObj.selectB = false;
            materialWrapperList.add(tempObj);
        }
        system.debug('+++ materialWrapperList is '+ materialWrapperList);
        system.debug('++ materialWrapperList size is '+ materialWrapperList.size());
        return null;
    }

    //save method
    public Pagereference save()
    {
        list<Materials_Junction__c> recordToInsert = new list<Materials_Junction__c>();
        try{
        for(materialWrapper obj : materialWrapperList)
        {
         Materials_Junction__c temp ;
            if(obj.selectB == true)
            {
                temp = new Materials_Junction__c();
                temp.sales_and_marketing__c = marketingJunction.sales_and_marketing__c;
                temp.Material_Records__c= obj.recordId;
                temp.quantity__C = obj.quantity; 
                recordToInsert.add(temp);
            }
            //recordToInsert.add(temp); you are adding element outside the if condition that the reason for save button error
        }
        insert recordToInsert; 
        return new Pagereference('/'+marketingJunction.sales_and_marketing__c);
        }catch(Exception e){
        ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.Error,e.getMessage()));
        return null;
        }       
    }


    public class materialWrapper
    {
        public string recordId {get; set;}
        public string name {get; set;}
        public string product {get; set;}
        public string item {get; set;}
        public Decimal quantity {get; set;}
        public boolean selectB {get; set;}

        public void materialWrapper()
        {
            recordId = '';
            name = '';
            product = '';
            item = '';
            quantity = 0.0;
            selectB = false;
        }
    }
}

This is my test class 
 
@isTest
private class SalesMarketingTest
{
    static testmethod void  SalesMarketing()
    {

        /**
        ***************************************************************************************** 
        *                     This is test data for Creating an Account
        ***************************************************************************************** 
        */  
            Account acct = new Account
                  (Name='Test');
            insert acct;

        /**
        ***************************************************************************************** 
        *                     Querying RT Object for Contact object
        * Sales_Contact__c on Material Request has an Filter Criteria Applied on lookup
        *Filter = Contact Record Type = Schroders Employee
        ***************************************************************************************** 
        */  

        RecordType rt = [select id,developername,Name from RecordType where SobjectType='Contact' and developername='Employee' Limit 1];

        /**
        ***************************************************************************************** 
        *                     This is test data for Creating an Contact 
        *                         Passing Contact RT Id From Query Above
        ***************************************************************************************** 
        */     
            Contact cont = new Contact (
                   AccountId= acct.id,
                   MailingCountry ='United States',
                   recordTypeId=rt.id,
                   LastName ='Test Name');
            insert cont;

        /**
        ***************************************************************************************** 
        *                     This is test data for Creating an Material Request
        ***************************************************************************************** 
        */          

            sales_and_marketing__c MKTRequest = new sales_and_marketing__c(
                   Name = 'Test Name',
                   Sales_Contact__c = Cont.id,
                         //  Delivery_Date__c =   datatype "Date/Time" 
                   Delivery_Date__c = DateTime.newInstance(2011, 11, 18, 3, 3, 3),
                       //Event_Date__c = datatype "Date" 
                   Event_Date__c = Date.newInstance(2017,2,2)
                       );
            insert MKTRequest;

        /**
        ***************************************************************************************** 
        *                     This is test data for Creating an Material Record
        ***************************************************************************************** 
        */
            Material_Records__c MRecords= new Material_Records__c(
                   Active__c = True,
                   Item__c='United States',
                   Product__c='Test Name');
            insert MRecords;

        /**
        ***************************************************************************************** 
        *                          This is test data for Materials_Junction
        ***************************************************************************************** 
        */
            Materials_Junction__c MJunction= new Materials_Junction__c(
                   Material_Records__c =MRecords.id,
                   sales_and_marketing__c= MKTRequest.id);
            insert MJunction;

        /**
        ***************************************************************************************** 
        *Checking that Materials_Junction__c has a record. 
        ***************************************************************************************** 
        */
        MJunction = [
            Select 
            Id, 
            Name, 
            Material_Records__c, 
            sales_and_marketing__c 
                From Materials_Junction__c 
            WHERE sales_and_marketing__r.id =:MKTRequest.Id 
            AND  Material_Records__r.id =:MRecords.id];
        /**
        ***************************************************************************************** 
        *System Assert Statements. Checking that Record has the correct value from insert statements
        ***************************************************************************************** 
        */
        system.assertEquals(MKTRequest.Id, MJunction.sales_and_marketing__c); //Check that Sales& MKT Id is same as MKTRequest.Id
        system.assertEquals(MRecords.Id, MJunction.Material_Records__c ); //Check that MaterialRecordsID is same as MRecords.Id


        /**
        ***************************************************************************************** 
        *Wrapper
        ***************************************************************************************** 
        */

        //Test.StartTest();

        //materialWrapper obj = new materialWrapper();

        SalesMarketing.materialWrapper wrapper= new SalesMarketing.materialWrapper();
        //Test.StopTest();
    }
}

 

Hi SalesForce Community. 

I am hoping you can help,I have encountered different issues with my email template, and i have searched different forums and getting my self more and more confused.

To give some context I am trying to Create a VF email template that returns fields from the related list on the sales_and_marketing__c object.

I have three objects in question (See Two images attached)
sales_and_marketing__c, 
Material_Records__c, 
Materials_Junction__c

When on the sales_and_marketing__c object there is a related list.
When you scroll down to the related list and click on new it opens up a pop up box which is the Materials_Junction__c. (See image below)
User-added image
Materials_Junction__c object has three fields. 

 

Material_Records__c Data Type Master-Detail(Material Records)
Quantity__c  Data Type Number(18, 0)
sales_and_marketing__c Data Type Master-Detail(Sales & Marketing)

When you click on the magifning class on "Materal record" fields you are presenting with the following.
User-added image

Which is this object 

 

Material Records Object

after selecting your materials you will return to this screen(See below) you add in a quanity amount and press save.
User-added image
Once you push "save" the materials you have selected along with quantity will be presented on the  sales_marketing object (as seen below)

User-added image

On my email template i should see .

Name of "Sales and Marketing" Record ( so example above it would be "Test")
Then 5 lines to show the products, item , quantity  

Products and Item comes from the Material_Records__c object, and quantity  from the Materials_Junction__c object

This is my attempt at my VF page 

<messaging:emailTemplate recipientType="Contact"
relatedToType="sales_and_marketing__c"
subject="Testing VF page: {!relatedTo.name}">

<messaging:htmlEmailBody >  
<html>
    <body>
    <STYLE type="text/css">
        TH {font-size: 11px; font-face: arial;background: #CCCCCC; border-width: 1;  text-align: center } 
        TD  {font-size: 11px; font-face: verdana } 
        TABLE {border: solid #CCCCCC; border-width: 1}
        TR {border: solid #CCCCCC; border-width: 1}
     </STYLE>
     <font face="arial" size="2"> 

<p>Dear {!recipient.name},</p>
<p>Below is a list of materials related to : {!relatedTo.name}.</p>

<table border="0" >
    <tr > 
        <th>Action</th><th>Case Number</th><th>Subject</th><th>Creator Email</th>
    </tr>
    <apex:repeat var="cx" value="{!relatedTo.Materials_Junction__r}">
        <tr>
            <td><a href="https://na1.salesforce.com/{!cx.Materials_Record__c}">View</a> |
            <a href="https://na1.salesforce.com/{!cx.Materials_Record__c}/e">Edit</a></td>
              <td>{!cx.Materials_Record__r.Product__c}</td>
        <td>{!cx.Materials_Record__r.Active__c}</td>
        <td>{!cx.Materials_Record__r.Item__c}</td>
            </tr>
    </apex:repeat>                 
</table>
<p />
     </font>
        </body>
    </html>
</messaging:htmlEmailBody> 

<messaging:plainTextEmailBody>

Dear {!recipient.name},

Below is a list of cases related to Account: {!relatedTo.name}

[ product ] - [ active ] - [ Itemss] 

<apex:repeat var="cx" value="{!relatedTo.Materials_Junction__r}">
[ {!cx.Materials_Record__r.Product__c} ] - [ {!cx.Materials_Record__r.Active__c} ] - [{!cx.Materials_Record__r.Item__c} ]  
</apex:repeat>

For more information login to http://www.salesforce.com
</messaging:plainTextEmailBody>    
</messaging:emailTemplate>

 
Hi All , 

I am hoping you can help me.

Requirements; 
Once the Obligiations is  complete, the ‘Complete Obligiation’ button should be clicked by the User and the following should happen:
  1. The "Obligation Next Due" field should never fall on a weekend or any date which is referenced in the "business hours"
  2. The "Obligation Next Due" field  should calculate the next "date value" based on the Frequency and
    Deadline Date 
  3. Update the ‘Obligation Last Completed on" with the data of the button execution. 


Object Name    Client_Obligations
API Name    Client_Obligations__c

field: frequency
api : Frequency__c
data type : picklist 
value : Monthly_BD

Business hours name : Client Obligations
id : https://emea.salesforce.com/01m200000000VjK

Expected out come : 

frequency : Monthly_BD
Deadline Date 9/16/2016 (12th business day of september)
User pushes the button "Complete Obligiation’ the "Obligation Next Due" should be "10/17/2016" (12th business day of october)

Really appreciate your help and advice 

Hope all is well.

I am a newbie to visual force and apex and have looked at various documentation online. (Especially this pdf https://www.developerforce.com/guides/Visualforce_in_Practice.pdf, however i really need some SF expertise from the community to help me get this over the line, as i dont know how to proceed.

Required outcome : User goes to the sales_and_marketing__c object, scrolls to the related list called Materials_Junction__c. Upon clicking the"new" button the following visual page below should be presented. The user would then select the appropriate products (using the tickbox) and adding an quantity number. Upon pressing save, the values selected should be mapped back to the sales_and_marketing__c object,

Visual Force page 
<apex:page controller="testWrapper">
<script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++){
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
    <apex:form >
        <apex:pageBlock title="Select Product">

            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
         
            <apex:pageBlockTable value="{!materialWrapperList}" var="MKT"> <!-- for loop of contact in Materials -->
                <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
                        <apex:inputCheckbox value="{!MKT.selectB}" id="inputId"/>
                    </apex:column>
               <!-- <apex:column value="{!MKT.selectB}"/>-->
         
                <apex:column value="{!MKT.name}"/>       
                <apex:column value="{!MKT.Product}"/>
                <apex:column value="{!MKT.Item}"/>
                <apex:column headerValue="Quantity">
                    <apex:inputText value="{!MKT.quantity}"/>
                </apex:column>

            </apex:pageBlockTable>

        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Class
 
public with sharing class testWrapper
{
    public List<Materials__c> Materials {get;set;} 
    public List<materialWrapper> materialWrapperList {get;set;} 
    
    public testWrapper()
    {   
        materialWrapperList = new List<materialWrapper>();
        Materials = [select ID,name,Product__c, Item__c,Quanity__c, Active__c from Materials__c where Active__c =true limit 10];
        for(Materials__c obj : Materials)
        {
            materialWrapper tempObj= new materialWrapper();
            tempObj.recordId = obj.id;
            tempObj.name = obj.name;
            tempObj.product = obj.Product__c;
            tempObj.item = obj.Item__c;
            tempObj.quantity = obj.Quanity__c;
            tempObj.selectB = false;
            materialWrapperList.add(tempObj);
        }
    }

    //save method
    public void save()
    {
        list<Materials_Junction__c> recordToInsert = new list<Materials_Junction__c>();
        
        for(materialWrapper obj : materialWrapperList)
        {
         Materials_Junction__c temp ;
            if(obj.selectB == true)
            {
                temp = new Materials_Junction__c();
                temp.sales_and_marketing__c = 'a032000000VQaRT';
                temp.Materials__C= obj.recordId;
                temp.quantity__C = obj.quantity; 
                recordToInsert.add(temp);
            }
            //recordToInsert.add(temp); you are adding element outside the if condition that the reason for save button error
        }
        insert recordToInsert;        
    }
    
    
    public class materialWrapper
    {
        public string recordId {get; set;}
        public string name {get; set;}
        public string product {get; set;}
        public string item {get; set;}
        public Decimal quantity {get; set;}
        public boolean selectB {get; set;}
        
        public void materialWrapper()
        {
            recordId = '';
            name = '';
            product = '';
            item = '';
            quantity = 0.0;
            selectB = false;
        }
    }
}

 
Good afternoon,
I am hoping you can help me.
I am building a POC and i have hit a brick wall and really appreciate some help form the community.

Problems :
My visual force page doesnt show a tick box. When i push save, i dont see the record being mapped back anywhere. when on Materials_Junction object and look at Buttons, Links, and Actions i edit the "new" button to add the visual force page, however no vf pages are presented.

Ideal Solution :
Go to the sales & marketing object, scroll to the "Materials_Junction" related list and click on "New". Upon clicking on "New" it should open up the "visual force" page below (which references the "materials" object). The user should select the "material" via a tick box add a quantity,upon clicking the save button on the visual force page, the values the user has selected should get mapped back to the "sales & marketing object"
Apex Controller

Apex controller 
public with sharing class testWrapper
{
    public List<Materials__c> Materials {get;set;} 
    public List<materialWrapper> materialWrapperList {get;set;} 
    
    public testWrapper()
    {   
        materialWrapperList = new List<materialWrapper>();
        Materials = [select ID,name,Product__c, Item__c,Quanity__c, Active__c from Materials__c where Active__c =true limit 10];
        for(Materials__c obj : Materials)
        {
            materialWrapper tempObj= new materialWrapper();
            tempObj.recordId = obj.id;
            tempObj.name = obj.name;
            tempObj.product = obj.Product__c;
            tempObj.item = obj.Item__c;
            tempObj.quantity = obj.Quanity__c;
            tempObj.selectB = false;
            materialWrapperList.add(tempObj);
        }
    }

    //save method
    public void save()
    {
        list<Materials_Junction__c> recordToInsert = new list<Materials_Junction__c>();
        
        for(materialWrapper obj : materialWrapperList)
        {
         Materials_Junction__c temp ;
            if(obj.selectB == true)
            {
                temp = new Materials_Junction__c();
                temp.sales_and_marketing__c = 'a032000000VQaRT';
                temp.Materials__C= obj.recordId;
                temp.quantity__C = obj.quantity; 
                recordToInsert.add(temp);
            }
            //recordToInsert.add(temp); you are adding element outside the if condition that the reason for save button error
        }
        insert recordToInsert;        
    }
    
    
    public class materialWrapper
    {
        public string recordId {get; set;}
        public string name {get; set;}
        public string product {get; set;}
        public string item {get; set;}
        public Decimal quantity {get; set;}
        public boolean selectB {get; set;}
        
        public void materialWrapper()
        {
            recordId = '';
            name = '';
            product = '';
            item = '';
            quantity = 0.0;
            selectB = false;
        }
    }
}

visual force page 
<apex:page controller="testWrapper">
    <apex:form >
        <apex:pageBlock title="Select Product">

            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>

            <apex:pageBlockTable value="{!materialWrapperList}" var="MKT"> <!-- for loop of contact in Materials -->
                <apex:column value="{!MKT.selectB}"/>
                <apex:column value="{!MKT.name}"/>       
                <apex:column value="{!MKT.Product}"/>
                <apex:column value="{!MKT.Item}"/>
                <apex:column headerValue="Quantity">
                    <apex:inputText value="{!MKT.quantity}"/>
                </apex:column>

            </apex:pageBlockTable>

        </apex:pageBlock>
    </apex:form>
</apex:page>

Really appreciate all the help i can get 

Afternoon All, 

I am trying to save my VF page but i am getting the following error "Error: Unknown property 'testWrapper.materialWrapper.select' ". 

Aim - The user will go to the sales_and_marketing__c object ,scroll down to the Materials_Junction related list. click "new", this should then call the VF page listed below. and return all the records from the Materials object which are active (Crtieria in Class). The user then selects the Materials, fills in quantity. When the User Saves this should then be mapped back to the sales_and_marketing__c object

Really appreciate your help 

I have the following Controller : 

public with sharing class testWrapper
{
    public List<Materials__c> Materials {get;set;} 
    public List<materialWrapper> materialWrapperList {get;set;} 
    
    public testWrapper()
    {
        Materials = [select ID,name,Product__c, Item__c,Quanity__c, Active__c from Materials__c where Active__c =true limit 10];
        for(Materials__c obj : Materials)
        {
            materialWrapper tempObj= new materialWrapper();
            tempObj.recordId = obj.id;
            tempObj.name = obj.name;
            tempObj.product = obj.Product__c;
            tempObj.item = obj.Item__c;
            tempObj.quantity = obj.Quanity__c;
            tempObj.selectB = false;
            materialWrapperList.add(tempObj);
        }
    }

    //save method
    public void save()
    {
        list<Materials_Junction__c> recordToInsert = new list<Materials_Junction__c>();
        
        for(materialWrapper obj : materialWrapperList)
        {
         Materials_Junction__c temp ;
            if(obj.selectB == true)
            {
                temp = new Materials_Junction__c();
                temp.sales_and_marketing__c = '01I20000000rV6V';
                temp.Materials__C= obj.recordId;
                temp.quantity__C = obj.quantity; 
            }
            recordToInsert.add(temp);
        }
        insert recordToInsert;
    }
    
    
    public class materialWrapper
    {
        public string recordId {get; set;}
        public string name {get; set;}
        public string product {get; set;}
        public string item {get; set;}
        public Decimal quantity {get; set;}
        public boolean selectB {get; set;}
        
        public void materialWrapper()
        {
            recordId = '';
            name = '';
            product = '';
            item = '';
            quantity = 0.0;
            selectB = false;
        }
    }
}

Visual Force Page :

apex:page controller="testWrapper">
<apex:form >
    <apex:pageBlock title="Select Product">

        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlockButtons>

        <apex:pageBlockTable value="{!materialWrapperList}" var="MKT"> 
            <apex:column value="{!MKT.select}"/>
            <apex:column value="{!MKT.name}"/>       
            <apex:column value="{!MKT.Product}"/>
            <apex:column value="{!MKT.Item}"/>
            <apex:column headerValue="Quanity">
                <apex:inputField value="{!MKT.Quanity}"/>
            </apex:column>

        </apex:pageBlockTable>

    </apex:pageBlock>
</apex:form>

Hi All, 

I am hoping you can help me.

This is my Controller, however when i am saving i am getting the the following error message "Error: Compile Error: Invalid field Materials for SObject Materials_Junction__c at line 33 column 17"

i have looked through the relevant examples on wrapper classes however i am a now stuck. 

Really appreciated you help 

public with sharing class testWrapper
{
    public List<Materials__c> Materials {get;set;} 
    public List<materialWrapper> materialWrapperList {get;set;} 
    
    public testWrapper()
    {
        Materials = [select ID,name,Product__c, Item__c,Quanity__c, Active__c from Materials__c where Active__c =true limit 10];
        for(Materials__c obj : Materials)
        {
            materialWrapper tempObj= new materialWrapper();
            tempObj.recordId = obj.id;
            tempObj.name = obj.name;
            tempObj.product = obj.Product__c;
            tempObj.item = obj.Item__c;
            tempObj.quantity = obj.Quanity__c;
            tempObj.selectB = false;
            materialWrapperList.add(tempObj);
        }
    }

    //save method
    public void save()
    {
        list<Materials_Junction__c> recordToInsert = new list<Materials_Junction__c>();
        
        for(materialWrapper obj : materialWrapperList)
        {
            if(obj.selectB == true)
            {
                Materials_Junction__c temp = new Materials_Junction__c();
                temp.sales_and_marketing__c = '01I20000000rV6V';
                temp.Materials= obj.recordIdId;
                temp.quantity = obj.quantity; 
            }
            recordToInsert.add(obj);
        }
        insert recordToInsert;
    }
    
    
    public class materialWrapper
    {
        public string recordId {get; set;}
        public string name {get; set;}
        public string product {get; set;}
        public string item {get; set;}
        public Decimal quantity {get; set;}
        public boolean selectB {get; set;}
        
        public void materialWrapper()
        {
            recordId = '';
            name = '';
            product = '';
            item = '';
            quantity = 0.0;
            selectB = false;
        }
    }
}

Materials Object API 

Materials Object API

Materials Object Fields 

Materials Object Fields

Materials_Junction API 

Materials Junction Object API

Materials_Junction Fields 
Materials Junction Object Fields
 

HI All, 

I am hoping you can help me. I am very new to VF and Apex and been using different resources on line and i am now stuck and dont know how to proceed. i am getting the following error 'unexpected token: '{' at line 39 column 26' when trying to save the class

Aim : The user should go to the Sales & Marketing Object, click on a related list, this should then open up a VF page. The VF page should show all of the records from the Materials Object. The user should select the records and the Quanity value, upon save this should then map back to  Sales & Marketing Object

I have created the following three objects
 
Materials = 01I20000000rV5S
Materials Junction = 01I20000000rV6B
Sales and Marketing = 01I20000000rV6V

This is the class that i have produced  


public with sharing class test
{
    public List<Materials__c> Materials {get;set;} //global variables
    public List<materialWrapper> materialWrapperList {get;set;} //use this list on vf page and not Materials

    //constructor
    public test()
    {
        Materials = [select ID,name,Product__c, Item__c,Quanity__c, Active__c from Materials__c where Active__c =true limit 10];
        for(Materials__c obj : Materials){
            materialWrapper tempObj= new materialWrapper();
            tempObj.recordId = obj.id;
            tempObj.name = obj.name;
            tempObj.product = obj.Product__c;
            tempObj.item = obj.Item__c;
            tempObj.quantity = obj.Quanity__c;
            tempObj.select = false;
            materialWrapperList.add(tempObj);
        }
    }

    //save method
    public void save()
    {
        list<Materials_Junction__c> recordToInsert = new list<Materials_Junction__c>();
        for(materialWrapper obj : materialWrapperList){
            if(obj.select == true){
                Materials_Junction__c temp = new Materials_Junction__c();
                temp.sales_and_marketing__c = '01I20000000rV6V';
                temp.Materials= obj.recordId;
                temp.quantity = obj.quantity; 
            }
            recordToInsert.add(obj);
        }
        insert recordToInsert;
    }
    
    
    public materialWrapper{
        string recordId {get; set;}
        string name {get; set;}
        string product {get; set;}
        string item {get; set;}
        string quantity {get; set;}
        boolean select {get; set;}
        
        public void materialWrapper(){
            recordId = '';
            name = '';
            product = '';
            item = '';
            quantity = '';
            select = false;
        }
    }
}

Materials Junction Fields
User-added image

Materials Object Fields 
User-added image

Hoping you can help 

Looking forward to your response 

Many thanks 

Hi fellow Salesforcers

I need some help.

Aim : A user goes to Salesforce and marketing Object , scrolls to related list marketing materials. Click new. This  should then opens up a VF page which lists all records in material object.

The User will select what records they want. Upon clicking save,  the records chosen should  map back to the "Sales and marketing" object 

In my developer org i have created the following three objects ; 

Sales & marketing
Marketing materials
Material conjuction

Marketing Materials object has the following fields 

Product (text)
Item (text)
Active (check box)

Materials conjunction object has the following fields 
Master detail to sales and marketing oject 
master detail to materials object 

I have looked at intro to visual force and I have used the examples and tailored to my needs. To grasp the concept but I am a little confused . I have built this in my own Dev org more than happy to create a new user to walk through this.

Markup
 

<apex:page controller="test">
    <apex:form >
        <apex:pageBlock title="Select Product">

            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>

            <apex:pageBlockTable value="{!Materials}" var="MKT"> <!-- for loop of contact in Materials -->
                  <apex:column value="{!MKT.name}"/>       
                <apex:column value="{!MKT.Product__c}"/>
                <apex:column value="{!MKT.Item__c}"/>
                 <apex:column value="{!MKT.Quanity__c}"/>
                 <apex:column value="{!MKT.Active__c}"/>

                    <apex:column headerValue="Quanity">
                    <apex:inputField value="{!MKT.Quanity__c}"/>
                </apex:column>

            </apex:pageBlockTable>

        </apex:pageBlock>
    </apex:form>
</apex:page>
Controller
public with sharing class test
{
    public List<Materials__c> Materials {get;set;} //global variables

    //constructor
    public test()
    {
        Materials = [select ID,name,Product__c, Item__c,Quanity__c, Active__c from Materials__c where Active__c =true limit 10];
    }

    //save method
    public void save()
    {
        update Materials;
    }
}
This is the current outcome, however as you can see when i save its just update quantity value on the materials object
User-added image

Looking forward to your response 

Regards
Masond3
HI All
I need some help creating a trigger. This is my first time creating a trigger so my applogises if its incorrect.

Aim : Every time a task is created which meets criteria ( See below) then change the status (picklist) from “Not started” to “Completed”

The trigger should only fire if it meets the following criteria RecordTypeId = '0123000000007ZoAAI'

Type.contains 'meeting:'

Type.contains 'Call;'

Type = 'Other - see subject'

ownerid = 00E30000000gYL8 

I have attempted to create the following trigger, but I am not sure if I am on the correct lines

Really looking forward to your help
 
trigger UpdateStatus on Task (after insert) {

   for (Task t : trigger.new){
            if (t.RecordTypeId == '0123000000007ZoAAI'){
            if (t.Type.contains('meeting:')){
            if (t.Type.contains ('Call;'))
            if (t.Type = 'Other - see subject';
                    }
                }
            }
        }
}
// Need to include assigned to owner/
if(t.OwnerId == '00E30000000gYL8'){

Status = 'Completed':

 
Good afternoon

I am hoping someone can help. I have spent the last couple of hour’s researching the different possibilities and I am none the wiser

Aim – If a value is added to the following field “Mailing Recipient” on either the lead object or contact object it updates the picklist in the other object

I would also like to mention I'm not a developer so I haven’t attempted any triggers or batch however I do grasps the basics of reading code.

Object : Contact
Field :  Mailing Recipient
Api name : Mailing_Recipients__c
Data type :  Picklist (Multi-Select)

Object : Lead
Field :  Mailing Recipient
Api name : Mailing_Recipients__c
Data type :  Picklist (Multi-Select)

Really looking forward to your help and guidance
 
Many thanks
Mason

 

Hey all

I hope all is well, i really need some help wit the following below.


I have created the following button ( which sits on the campaign object)

User-added image
However when i click on the button i get the following error message

User-added image

This is the class, which i want the button to call. Anyone have any ideas why this is not working ? 

i would like to point out i dont have a test class, and the code coverage is at 0%

This is the apex class which is called from the button 

public String mysw {get; set;}

  Webservice static String initiateswapproval(String mysw) {
    //change Campaign__c to your sObject
   Campaign sw = new Campaign(Id=mysw);

//make sure you add the custom field Submitted for Approval on your object as this is what you
//will use as your approval process entry criteria.
//This is the approval process entry I used: Entry Criteria  (Campaign: Approved Date EQUALS null) AND (campaign: Submitted for Approval EQUALS TODAY)

sw.Submitted_for_Approval__c = System.Now();

update sw;


 // Create an approval request for the record

    Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();

    req1.setComments('Submitting request for approval automatically');

    req1.setObjectId(mysw);

    Approval.ProcessResult result = Approval.process(req1);

  return null;


  }
}
This is my approval process. I know that the entry criteria is correct, however i am not sure about the approval steps

User-added image

HI All

I am slowly loosing the will to live at the moment, and I don’t know whether I am over complication the situation or not.

Currently I have an object called “Certificates” Which sits on the contact and is only used by one profile “Retail”

There are currently two record types ;
CPD Certificate
Certificate of Attendance

Dependent on the record type you choose, you are generated with an email template.

Now I don’t want to create a separate record type for a new profile to use the object.  I want to use the existing record type, but identify which profile within the record type, and generate the email from there.

To do this I have created a picklist field called “team” and I have the following two values ;
Retail
Institutional

If the user selects “Retail” I want the existing email template to be sent out

<messaging:emailTemplate subject="{!relatedTo.Date__c} {!relatedTo.RecordType.Name} {!relatedTo.Name}" recipientType="Contact" relatedToType="Certificate__c">
    <messaging:htmlEmailBody >
        <p>Dear {!recipient.FirstName},</p>
        <p>Please find attached your {!relatedTo.RecordType.Name} for the event you attended on&nbsp;<c:DisplayFormattedDate date_time_value="{!relatedTo.Date__c}" date_time_format="EEE MMM d kk:mm:ss z yyyy"/>.</p>
        <p>Kind Regards,</p>
        <p>{!recipient.Owner.Name}</p>
        <hr />        
        <c:Attendance_Certificate Certificate="{!relatedTo}" />
    </messaging:htmlEmailBody>
    <messaging:plainTextEmailBody >
        Dear {!recipient.FirstName},
        Please find attached your {!relatedTo.RecordType.Name} for the event you attended on {!day(relatedTo.Date__c)}/{!month(relatedTo.Date__c)}/{!year(relatedTo.Date__c)}
        Kind Regards,
        {!recipient.Owner.Name}
    </messaging:plainTextEmailBody>
    <messaging:attachment renderAs="PDF" filename="{!relatedTo.RecordType.Name}_{!relatedTo.Name}.pdf">
        <html>
            <body>
                <c:Attendance_Certificate Certificate="{!relatedTo}"/>
            </body>
        </html>
    </messaging:attachment>
</messaging:emailTemplate>



however if they select “Institutional” a new email template is generated.

also how can i amend the details within the PDF ? as for the new Institutional email template, there is a different MD, And registration number etc

Looking forward to your help 

KR 

D


Can this be done ?

HI All

I am slowly loosing the will to live at the moment, and I don’t know whether I am over complication the situation or not.

Currently I have an object called “Certificates” Which sits on the contact and is only used by one profile “Retail”

There are currently two record types ;
CPD Certificate
Certificate of Attendance

Dependent on the record type you choose, you are generated with an email template.

Now I don’t want to create a separate record type for a new profile to use the object.  I want to use the existing record type, but identify which profile within the record type, and generate the email from there.

To do this I have created a picklist field called “team” and I have the following two values ;
Retail
Institutional

If the user selects “Retail” I want the existing email template to be sent out

<messaging:emailTemplate subject="{!relatedTo.Date__c} {!relatedTo.RecordType.Name} {!relatedTo.Name}" recipientType="Contact" relatedToType="Certificate__c">
    <messaging:htmlEmailBody >
        <p>Dear {!recipient.FirstName},</p>
        <p>Please find attached your {!relatedTo.RecordType.Name} for the event you attended on&nbsp;<c:DisplayFormattedDate date_time_value="{!relatedTo.Date__c}" date_time_format="EEE MMM d kk:mm:ss z yyyy"/>.</p>
        <p>Kind Regards,</p>
        <p>{!recipient.Owner.Name}</p>
        <hr />        
        <c:Attendance_Certificate Certificate="{!relatedTo}" />
    </messaging:htmlEmailBody>
    <messaging:plainTextEmailBody >
        Dear {!recipient.FirstName},
        Please find attached your {!relatedTo.RecordType.Name} for the event you attended on {!day(relatedTo.Date__c)}/{!month(relatedTo.Date__c)}/{!year(relatedTo.Date__c)}
        Kind Regards,
        {!recipient.Owner.Name}
    </messaging:plainTextEmailBody>
    <messaging:attachment renderAs="PDF" filename="{!relatedTo.RecordType.Name}_{!relatedTo.Name}.pdf">
        <html>
            <body>
                <c:Attendance_Certificate Certificate="{!relatedTo}"/>
            </body>
        </html>
    </messaging:attachment>
</messaging:emailTemplate>



however if they select “Institutional” a new email template is generated.

also how can i amend the details within the PDF ? as for the new Institutional email template, there is a different MD, And registration number etc

Looking forward to your help 

KR 

D


Can this be done ?

Afternoon Team, 

I think i am having one of these days where i cant do the basics in salesforce.

Aim : I would like the class below to only execute if the recordtype developername = "intermittent'". If the recordtype developername = "pending' then do nothing. Currently my class below executes on either Record type. "intermittent" or "pending ".

This is the query i use to Query RT Object for Flow object          
 select id,developername,Name from RecordType where SobjectType='flow__c' and developername='intermittent'  

I have created a trigger which calls an utils class

Trigger:

/********************************************************************
 * UpdateCurrencyInsert 
 *
 * Before Insert trigger on Flow
 ********************************************************************/
trigger UpdateCurrencyInsert on Flow__c (before insert) 
{
  FlowUtils.ValidateCurrencyUpdate(Trigger.new);
}
 

Class:

public class FlowUtils {
 
   public static void ValidateCurrencyUpdate(List<Flow__c> flows ) {


      List<Id> opportunityIds = new List<Id>();
      Map<Id, String> oppIdCurrencyCode = new Map<Id, String>();
      for (Flow__c Flow: flows ) {
          opportunityIds.add(Flow.opportunity__c);
      }
      
      for(Opportunity opp : [Select CurrencyIsoCode from Opportunity where Id in: opportunityIds]) {
        oppIdCurrencyCode.put(opp.Id, opp.CurrencyIsoCode);
      }
      
      for(Flow__c flow : flows) {
        flow.CurrencyIsoCode = oppIdCurrencyCode.get(flow.opportunity__c);
      }   
   }
 }
Looking forward to your help and advise 


I am new to salesforce. I am SQL developer...Is there any way to check data using any tool.. without going to salesforce List.

 

Afternoon Team, 
I am hoping you can help me.
I have the created the following class & test class (see below) however i am getting Code Coverage 73% (45/61). Using the developer console i can see that i am not testing the following scenarios on these lines 72-76,82-84,95,98-105. I have been trying all week to increase my code coverage, but i am really struggling to find a solution

if its not to much bother is it possible if you can help me review my test class and get the code coverage above the 75% threshold needed so i can deploy.

Class

/*************************************************************************************************************************
Class Name      :   SalesMarketing
Class Desc.     :   Class used for Sales & Marketing Visual Force Page   
Author          :   DM
Description     :   This class is used to populate the Sales & Marketing VF component, displaying  Material Name,Product, 
                    item from Material_Records__c and Quantity from Materials_Junction__c. Records are selected from the 
                    page (using the checkbox) once an quantity is added the user pushes "save" these records will map 
                    back to the "Sales & Marketing" Object with relevant information selected.
                    
***************************************************************************************************************************/


public with sharing class SalesMarketing
{
    public List<Material_Records__c> Materials {get;set;} 
    public List<materialWrapper> materialWrapperList {get;set;} 
    public Materials_Junction__c marketingJunction {get;set;}
    public String searchString {get;set;} 
    public SalesMarketing(ApexPages.StandardController controller)
    //public SalesMarketing()
    {   
        system.debug('++ Inside Constructor ');
        marketingJunction = (Materials_Junction__c) controller.getRecord();
        materialWrapperList = new List<materialWrapper>();
        Materials = [select ID,name,Product__c, Item__c, Active__c from Material_Records__c where Active__c =true limit 10];
        for(Material_Records__c obj : Materials)
        {
            materialWrapper tempObj= new materialWrapper();
            tempObj.recordId = obj.id;
            tempObj.name = obj.name;
            tempObj.product = obj.Product__c;
            tempObj.item = obj.Item__c;
            tempObj.selectB = false;
            materialWrapperList.add(tempObj);
        }
    }
    
    public Pagereference getProductOrItemData(){
        materialWrapperList.clear();
        system.debug('+++ searchString is '+ searchString); 
        system.debug('+++ Length for searchString is '+ searchString.length());  
        //String searchVal= searchString.trim();
        String searchVal='%'+searchString.trim() +'%';
        system.debug('+++ searchString is '+ searchVal); 

         Materials = [select ID,name,Product__c, Item__c, Active__c from Material_Records__c where Active__c =true and (Product__c like :searchVal OR Item__c like :searchVal)];
        for(Material_Records__c obj : Materials)
        {   
            materialWrapper tempObj= new materialWrapper();
            tempObj.recordId = obj.id;
            tempObj.name = obj.name;
            tempObj.product = obj.Product__c;
            tempObj.item = obj.Item__c;
            tempObj.selectB = false;
            materialWrapperList.add(tempObj);
        }
        system.debug('+++ materialWrapperList is '+ materialWrapperList);
        system.debug('++ materialWrapperList size is '+ materialWrapperList.size());
        return null;
    }

    //save method
    public Pagereference save()
    {
        list<Materials_Junction__c> recordToInsert = new list<Materials_Junction__c>();
        try{
        for(materialWrapper obj : materialWrapperList)
        {
         Materials_Junction__c temp ;
            if(obj.selectB == true)
            {
               temp = new Materials_Junction__c();
               temp.sales_and_marketing__c = marketingJunction.sales_and_marketing__c;
               temp.Material_Records__c= obj.recordId;
               temp.quantity__C = obj.quantity; 
               recordToInsert.add(temp);
            }
            //recordToInsert.add(temp); you are adding element outside the if condition that the reason for save button error
        }
        insert recordToInsert; 
        return new Pagereference('/'+marketingJunction.sales_and_marketing__c);
        }catch(Exception e){
        ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.Error,e.getMessage()));
        return null;
        }       
    }
    
    
    public class materialWrapper
    {
        public string recordId {get; set;}
        public string name {get; set;}
        public string product {get; set;}
        public string item {get; set;}
        public Decimal quantity {get; set;}
        public boolean selectB {get; set;}
        
   public void materialWrapper()
       {
           recordId = '';
            name = '';
            product = '';
            item = '';
           quantity = 0.0;
           selectB = false;
       }
    }
}
 

Test Class
 

/*************************************************************************************************************************
Class Name      :   SalesMarketingTest
Author          :   Daniel Mason
Description     :   This test class creates a test record for Sales&Mkt. Also tests VF Page SalesMarketingNew   
Class Used      :   This test class ensure code coverage for NewMKtMaterialsRequest(100%) & SalesMarketing(83%)
***************************************************************************************************************************/   
@isTest
private class SalesMarketingTest
{
    static testmethod void  SalesMarketing()
    {
 
CoreDataTest.getData();


/**This is test data for Creating an Material Request*/          

        sales_and_marketing__c MKTRequest = new sales_and_marketing__c(
               Name = 'Test Name',
               Sales_Contact__c = CoreDataTest.contacts[1].id,
               Number_of_Attendees__c = decimal.valueof('20'),
               Business_Cards__c ='Yes',
                     //  Delivery_Date__c =   datatype "Date/Time" 
               Delivery_Date__c = DateTime.newInstance(2011, 11, 18, 3, 3, 3),
                   //Event_Date__c = datatype "Date" 
               Event_Date__c = Date.newInstance(2017,2,2),
               Delivery_Street__c = 'Test',
               Delivery_City__c  = 'Test',
               Delivery_State_Province__c = 'Test',
               Delivery_Zip_Postal_Code__c = 'Test',
               Delivery_Country__c = 'Test'
                   );
        insert MKTRequest;

/**This is test data for Creating an Material Record*/
        Material_Records__c MRecords= new Material_Records__c(
               Active__c = True,
               Item__c='United States',
               Product__c='Test Name');
        insert MRecords;

/** This is test data for Materials_Junction*/
        Materials_Junction__c MJunction= new Materials_Junction__c(
               Material_Records__c =MRecords.id,
               sales_and_marketing__c= MKTRequest.id);
        insert MJunction;

/**Checking that Materials_Junction__c has a record. */
        MJunction = [
            Select 
            Id, 
            Name, 
            Material_Records__c, 
            sales_and_marketing__c 
                From Materials_Junction__c 
            WHERE sales_and_marketing__r.id =:MKTRequest.Id 
            AND  Material_Records__r.id =:MRecords.id];
            
/**Debug logs*/            
            
system.debug('DAN MKTRequest.Sales_Contact__r.User__c'+MKTRequest.Sales_Contact__r.User__c);
system.debug('DAN MKTRequest.Sales_Contact__c'+MKTRequest.Sales_Contact__c);
system.debug('DAN CoreDataTest.users[0].Id'+CoreDataTest.users[0].Id);
system.debug(' Dan CoreDataTest.users[1].Id '+CoreDataTest.users[1].Id);
system.debug(' Dan UserInfo.getUserId(); '+UserInfo.getUserId());
system.debug(' Dan CoreDataTest.contacts[1].id; '+CoreDataTest.contacts[1].user__C);
            
/**System Assert Statements. Checking that Record has the correct value from insert statements*/

system.assertEquals(MKTRequest.Id, MJunction.sales_and_marketing__c); //Check that Sales& MKT Id is same as MKTRequest.Id
system.assertEquals(MRecords.Id, MJunction.Material_Records__c ); //Check that MaterialRecordsID is same as MRecords.Id

  
// Testing the VFpage: SalesMarketingNew  
ApexPages.StandardController mktnewcontroller= new ApexPages.StandardController(MKTRequest);
NewMKtMaterialsRequest extension = new NewMKtMaterialsRequest(mktnewcontroller); // controller extensionPageReference NewMKT= extension.RedirectToMKTRequest(); 
          

/***Wrapper */
        Test.StartTest();
        ApexPages.StandardController sc = new ApexPages.StandardController(MJunction);

        SalesMarketing controller = new SalesMarketing(sc);
        controller.searchString = 'Test Name';
        controller.getProductOrItemData();
        System.assertEquals(controller.save().getUrl(), '/'+MKTRequest.id);
        SalesMarketing.materialWrapper wrapper= new SalesMarketing.materialWrapper();
        Test.StopTest();
    }
}

 

I have created a dynamic SOSL Query for existing SOQL query.But I am not getting all the records which I am getting 
form SOQL query.

When I compared the records which are missing from the SOSL then I found that those missing records where Created 5 Years ago from now.
So can this be the reason for not showing the records in SOSL?
I am new to SOSL.Please guide me.

Hi SalesForce Community. 

I am hoping you can help,I have encountered different issues with my email template, and i have searched different forums and getting my self more and more confused.

To give some context I am trying to Create a VF email template that returns fields from the related list on the sales_and_marketing__c object.

I have three objects in question (See Two images attached)
sales_and_marketing__c, 
Material_Records__c, 
Materials_Junction__c

When on the sales_and_marketing__c object there is a related list.
When you scroll down to the related list and click on new it opens up a pop up box which is the Materials_Junction__c. (See image below)
User-added image
Materials_Junction__c object has three fields. 

 

Material_Records__c Data Type Master-Detail(Material Records)
Quantity__c  Data Type Number(18, 0)
sales_and_marketing__c Data Type Master-Detail(Sales & Marketing)

When you click on the magifning class on "Materal record" fields you are presenting with the following.
User-added image

Which is this object 

 

Material Records Object

after selecting your materials you will return to this screen(See below) you add in a quanity amount and press save.
User-added image
Once you push "save" the materials you have selected along with quantity will be presented on the  sales_marketing object (as seen below)

User-added image

On my email template i should see .

Name of "Sales and Marketing" Record ( so example above it would be "Test")
Then 5 lines to show the products, item , quantity  

Products and Item comes from the Material_Records__c object, and quantity  from the Materials_Junction__c object

This is my attempt at my VF page 

<messaging:emailTemplate recipientType="Contact"
relatedToType="sales_and_marketing__c"
subject="Testing VF page: {!relatedTo.name}">

<messaging:htmlEmailBody >  
<html>
    <body>
    <STYLE type="text/css">
        TH {font-size: 11px; font-face: arial;background: #CCCCCC; border-width: 1;  text-align: center } 
        TD  {font-size: 11px; font-face: verdana } 
        TABLE {border: solid #CCCCCC; border-width: 1}
        TR {border: solid #CCCCCC; border-width: 1}
     </STYLE>
     <font face="arial" size="2"> 

<p>Dear {!recipient.name},</p>
<p>Below is a list of materials related to : {!relatedTo.name}.</p>

<table border="0" >
    <tr > 
        <th>Action</th><th>Case Number</th><th>Subject</th><th>Creator Email</th>
    </tr>
    <apex:repeat var="cx" value="{!relatedTo.Materials_Junction__r}">
        <tr>
            <td><a href="https://na1.salesforce.com/{!cx.Materials_Record__c}">View</a> |
            <a href="https://na1.salesforce.com/{!cx.Materials_Record__c}/e">Edit</a></td>
              <td>{!cx.Materials_Record__r.Product__c}</td>
        <td>{!cx.Materials_Record__r.Active__c}</td>
        <td>{!cx.Materials_Record__r.Item__c}</td>
            </tr>
    </apex:repeat>                 
</table>
<p />
     </font>
        </body>
    </html>
</messaging:htmlEmailBody> 

<messaging:plainTextEmailBody>

Dear {!recipient.name},

Below is a list of cases related to Account: {!relatedTo.name}

[ product ] - [ active ] - [ Itemss] 

<apex:repeat var="cx" value="{!relatedTo.Materials_Junction__r}">
[ {!cx.Materials_Record__r.Product__c} ] - [ {!cx.Materials_Record__r.Active__c} ] - [{!cx.Materials_Record__r.Item__c} ]  
</apex:repeat>

For more information login to http://www.salesforce.com
</messaging:plainTextEmailBody>    
</messaging:emailTemplate>

 
Hi All , 

I am hoping you can help me.

Requirements; 
Once the Obligiations is  complete, the ‘Complete Obligiation’ button should be clicked by the User and the following should happen:
  1. The "Obligation Next Due" field should never fall on a weekend or any date which is referenced in the "business hours"
  2. The "Obligation Next Due" field  should calculate the next "date value" based on the Frequency and
    Deadline Date 
  3. Update the ‘Obligation Last Completed on" with the data of the button execution. 


Object Name    Client_Obligations
API Name    Client_Obligations__c

field: frequency
api : Frequency__c
data type : picklist 
value : Monthly_BD

Business hours name : Client Obligations
id : https://emea.salesforce.com/01m200000000VjK

Expected out come : 

frequency : Monthly_BD
Deadline Date 9/16/2016 (12th business day of september)
User pushes the button "Complete Obligiation’ the "Obligation Next Due" should be "10/17/2016" (12th business day of october)

Really appreciate your help and advice 

Hope all is well.

I am a newbie to visual force and apex and have looked at various documentation online. (Especially this pdf https://www.developerforce.com/guides/Visualforce_in_Practice.pdf, however i really need some SF expertise from the community to help me get this over the line, as i dont know how to proceed.

Required outcome : User goes to the sales_and_marketing__c object, scrolls to the related list called Materials_Junction__c. Upon clicking the"new" button the following visual page below should be presented. The user would then select the appropriate products (using the tickbox) and adding an quantity number. Upon pressing save, the values selected should be mapped back to the sales_and_marketing__c object,

Visual Force page 
<apex:page controller="testWrapper">
<script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++){
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
    <apex:form >
        <apex:pageBlock title="Select Product">

            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
         
            <apex:pageBlockTable value="{!materialWrapperList}" var="MKT"> <!-- for loop of contact in Materials -->
                <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
                        <apex:inputCheckbox value="{!MKT.selectB}" id="inputId"/>
                    </apex:column>
               <!-- <apex:column value="{!MKT.selectB}"/>-->
         
                <apex:column value="{!MKT.name}"/>       
                <apex:column value="{!MKT.Product}"/>
                <apex:column value="{!MKT.Item}"/>
                <apex:column headerValue="Quantity">
                    <apex:inputText value="{!MKT.quantity}"/>
                </apex:column>

            </apex:pageBlockTable>

        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Class
 
public with sharing class testWrapper
{
    public List<Materials__c> Materials {get;set;} 
    public List<materialWrapper> materialWrapperList {get;set;} 
    
    public testWrapper()
    {   
        materialWrapperList = new List<materialWrapper>();
        Materials = [select ID,name,Product__c, Item__c,Quanity__c, Active__c from Materials__c where Active__c =true limit 10];
        for(Materials__c obj : Materials)
        {
            materialWrapper tempObj= new materialWrapper();
            tempObj.recordId = obj.id;
            tempObj.name = obj.name;
            tempObj.product = obj.Product__c;
            tempObj.item = obj.Item__c;
            tempObj.quantity = obj.Quanity__c;
            tempObj.selectB = false;
            materialWrapperList.add(tempObj);
        }
    }

    //save method
    public void save()
    {
        list<Materials_Junction__c> recordToInsert = new list<Materials_Junction__c>();
        
        for(materialWrapper obj : materialWrapperList)
        {
         Materials_Junction__c temp ;
            if(obj.selectB == true)
            {
                temp = new Materials_Junction__c();
                temp.sales_and_marketing__c = 'a032000000VQaRT';
                temp.Materials__C= obj.recordId;
                temp.quantity__C = obj.quantity; 
                recordToInsert.add(temp);
            }
            //recordToInsert.add(temp); you are adding element outside the if condition that the reason for save button error
        }
        insert recordToInsert;        
    }
    
    
    public class materialWrapper
    {
        public string recordId {get; set;}
        public string name {get; set;}
        public string product {get; set;}
        public string item {get; set;}
        public Decimal quantity {get; set;}
        public boolean selectB {get; set;}
        
        public void materialWrapper()
        {
            recordId = '';
            name = '';
            product = '';
            item = '';
            quantity = 0.0;
            selectB = false;
        }
    }
}

 

Afternoon All, 

I am trying to save my VF page but i am getting the following error "Error: Unknown property 'testWrapper.materialWrapper.select' ". 

Aim - The user will go to the sales_and_marketing__c object ,scroll down to the Materials_Junction related list. click "new", this should then call the VF page listed below. and return all the records from the Materials object which are active (Crtieria in Class). The user then selects the Materials, fills in quantity. When the User Saves this should then be mapped back to the sales_and_marketing__c object

Really appreciate your help 

I have the following Controller : 

public with sharing class testWrapper
{
    public List<Materials__c> Materials {get;set;} 
    public List<materialWrapper> materialWrapperList {get;set;} 
    
    public testWrapper()
    {
        Materials = [select ID,name,Product__c, Item__c,Quanity__c, Active__c from Materials__c where Active__c =true limit 10];
        for(Materials__c obj : Materials)
        {
            materialWrapper tempObj= new materialWrapper();
            tempObj.recordId = obj.id;
            tempObj.name = obj.name;
            tempObj.product = obj.Product__c;
            tempObj.item = obj.Item__c;
            tempObj.quantity = obj.Quanity__c;
            tempObj.selectB = false;
            materialWrapperList.add(tempObj);
        }
    }

    //save method
    public void save()
    {
        list<Materials_Junction__c> recordToInsert = new list<Materials_Junction__c>();
        
        for(materialWrapper obj : materialWrapperList)
        {
         Materials_Junction__c temp ;
            if(obj.selectB == true)
            {
                temp = new Materials_Junction__c();
                temp.sales_and_marketing__c = '01I20000000rV6V';
                temp.Materials__C= obj.recordId;
                temp.quantity__C = obj.quantity; 
            }
            recordToInsert.add(temp);
        }
        insert recordToInsert;
    }
    
    
    public class materialWrapper
    {
        public string recordId {get; set;}
        public string name {get; set;}
        public string product {get; set;}
        public string item {get; set;}
        public Decimal quantity {get; set;}
        public boolean selectB {get; set;}
        
        public void materialWrapper()
        {
            recordId = '';
            name = '';
            product = '';
            item = '';
            quantity = 0.0;
            selectB = false;
        }
    }
}

Visual Force Page :

apex:page controller="testWrapper">
<apex:form >
    <apex:pageBlock title="Select Product">

        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlockButtons>

        <apex:pageBlockTable value="{!materialWrapperList}" var="MKT"> 
            <apex:column value="{!MKT.select}"/>
            <apex:column value="{!MKT.name}"/>       
            <apex:column value="{!MKT.Product}"/>
            <apex:column value="{!MKT.Item}"/>
            <apex:column headerValue="Quanity">
                <apex:inputField value="{!MKT.Quanity}"/>
            </apex:column>

        </apex:pageBlockTable>

    </apex:pageBlock>
</apex:form>

Hi All, 

I am hoping you can help me.

This is my Controller, however when i am saving i am getting the the following error message "Error: Compile Error: Invalid field Materials for SObject Materials_Junction__c at line 33 column 17"

i have looked through the relevant examples on wrapper classes however i am a now stuck. 

Really appreciated you help 

public with sharing class testWrapper
{
    public List<Materials__c> Materials {get;set;} 
    public List<materialWrapper> materialWrapperList {get;set;} 
    
    public testWrapper()
    {
        Materials = [select ID,name,Product__c, Item__c,Quanity__c, Active__c from Materials__c where Active__c =true limit 10];
        for(Materials__c obj : Materials)
        {
            materialWrapper tempObj= new materialWrapper();
            tempObj.recordId = obj.id;
            tempObj.name = obj.name;
            tempObj.product = obj.Product__c;
            tempObj.item = obj.Item__c;
            tempObj.quantity = obj.Quanity__c;
            tempObj.selectB = false;
            materialWrapperList.add(tempObj);
        }
    }

    //save method
    public void save()
    {
        list<Materials_Junction__c> recordToInsert = new list<Materials_Junction__c>();
        
        for(materialWrapper obj : materialWrapperList)
        {
            if(obj.selectB == true)
            {
                Materials_Junction__c temp = new Materials_Junction__c();
                temp.sales_and_marketing__c = '01I20000000rV6V';
                temp.Materials= obj.recordIdId;
                temp.quantity = obj.quantity; 
            }
            recordToInsert.add(obj);
        }
        insert recordToInsert;
    }
    
    
    public class materialWrapper
    {
        public string recordId {get; set;}
        public string name {get; set;}
        public string product {get; set;}
        public string item {get; set;}
        public Decimal quantity {get; set;}
        public boolean selectB {get; set;}
        
        public void materialWrapper()
        {
            recordId = '';
            name = '';
            product = '';
            item = '';
            quantity = 0.0;
            selectB = false;
        }
    }
}

Materials Object API 

Materials Object API

Materials Object Fields 

Materials Object Fields

Materials_Junction API 

Materials Junction Object API

Materials_Junction Fields 
Materials Junction Object Fields