• sml9099
  • NEWBIE
  • 55 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 22
    Questions
  • 32
    Replies
hey Guys,

I have written an Apex class and Visual Force page which searches the records from custom object. There is a field which is a multi pick list and it is a filter field. User selets the value in that field and all the records meeting the critiriea appear in the 'Results' section. This page has 3 buttons "Search", "Cancel" and "Export to CSV". I am stuck in achieveing desired code coverage. I have written a test class but it's giving me error and code coverage is only 29%. Can someone pleae help me out ? Any help will be appreciated

Here is the error message:
System.NullPointerException: Attempt to de-reference a null object
Stack Trace Class.Fetchsiteplacement.FillAggregates: line 77, column 1
Class.TestFetchsiteplacement.myUnitTest: line 49, column 1


Multi picklist filed - Device__c (It can be PC, Tablet, Mobile). Here is Apex class:

public class Fetchsiteplacement{
String devicetype;
 
   public Site_Placements__c  sp{get;set;}
    public List<Site_Placements__c > spRec{get;set;}
    public List<Site_Placements__c > spRec1{get;set;}
    public List<siteplacementwrapper> spwrapper{get;set;}
    public List<siteplacementwrapper> spwrapperexcel{get;set;}    

    public class siteplacementwrapper{
            
           
            public String Name {get;set;}
           }
        public Fetchsiteplacement(){
        sp=new Site_Placements__c ();
        spRec = new List<Site_Placements__c>();
        
        }
        
         public void FillAggregates(){
          String devicetype= '';
         string[] lststr1=sp.Device_Type__c.split(';');
            
 for (String s1: lststr1) {
                            devicetype+= '\'' + s1 + '\',';
                                }
                   devicetype= devicetype.substring (0,devicetype.length() -1);

            spwrapper=new List<siteplacementwrapper>();
            spwrapperexcel=new List<siteplacementwrapper>();
                   
             String sitePlacementQuery ='SELECT Id,Name from Site_Placements__c WHERE Device_Type__c INCLUDES (' + devicetype + ')  ';
            spRec=database.query(sitePlacementQuery);
            
            String sitePlacementQuery1 ='SELECT Id,Name  from Site_Placements__c WHERE Device_Type__c INCLUDES (' + devicetype + ')  ';
            spRec1=database.query(sitePlacementQuery1);
            
             if(spRec.size() == 0)
                {
                        Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No records match your criteria'));
                } 
             else {
             
              for(Site_Placements__c sitePlacement:spRec){
              
               siteplacementwrapper spr=new siteplacementwrapper();
               
               
              spr.Name=sitePlacement.Name;
              spwrapper.add(spr);
              }  
             
             for(Site_Placements__c sitePlacement:spRec1){
              
              siteplacementwrapper spr=new siteplacementwrapper();
               
              spr.Name=sitePlacement.Name;
             
              spwrapperexcel.add(spr);
             
             
              }
             
             }
         }  
                
                
        public PageReference FetchExcelReport() {
        PageReference nextpage = new PageReference('/apex/RFP_Excel_Page');
return nextpage;
}
         
         public pagereference CancelSPRec(){
     
    PageReference page = new PageReference('https://c.cs30.visual.force.com/apex/SiteListPage');
    page.SetRedirect(true);
    return page;
    }}


Apex Test class:

@isTest(seeAllData=true)
private class TestFetchsiteplacement {
    
 static testMethod void myUnitTest() {
        // TO DO: implement unit test
        Account a = new Account(Name='Test Account');
      insert a;

      Publisher_Deal_Types__c pubdeal = new Publisher_Deal_Types__c ( Name = 'Test Publisher deal type', Account_Name__c = a.Id);
        
        insert pubdeal;
        
        Site_Placements__c sp = new Site_Placements__c ();
        sp.Name = 'Test site placement';
        sp.Publisher_Account_Name_clickable__c = a.Id;
        sp.Publisher_or_Vendor_Deal_Type_Name__c = pubdeal.Id;
        sp.Device_Type__c = 'PC';
        
        insert sp;
      
      PageReference ref = new PageReference('/apex/SiteListPage');
      
      Test.setCurrentPage(ref);
      
      PageReference nextpage = new PageReference('/apex/RFP_Excel_Page');
      Test.setCurrentPage(nextpage);
 
    Test.startTest();
    Fetchsiteplacement myController = new Fetchsiteplacement();
    myController.FillAggregates();
    myController.FetchExcelReport();
    myController.CancelSPRec();
    Test.stopTest();

     Site_Placements__c selectedSP = [SELECT Device_Type__c FROM Site_Placements__c WHERE Id = :sp.Id];
     System.assertEquals('PC', selectedSP.Device_Type__c);
     
 }
}
Hey, 

I have written an Apex class and Visual Force page which searches the records from custom object. There is a field which is a multi pick list and it is a fielter field. User seletcs the value in that field and all the records meeting the critiriea appear in the 'Results' section. This page has 3 buttons "Search", "Cancel" and "Export to CSV". I am not good in writing a test class but I tried to write some and it is not giving my desired code coverage. Can someone pleae help me out ? Any help will be appreciated

Apex class:
public class Fetchsiteplacement{
String devicetype;
 
   public Site_Placements__c  sp{get;set;}
    public List<Site_Placements__c > spRec{get;set;}
    public List<Site_Placements__c > spRec1{get;set;}
    public List<siteplacementwrapper> spwrapper{get;set;}
    public List<siteplacementwrapper> spwrapperexcel{get;set;}    

    public class siteplacementwrapper{
            
           
            public String Name {get;set;}
           }
        public Fetchsiteplacement(){
        sp=new Site_Placements__c ();
        spRec = new List<Site_Placements__c>();
        
        }
        
         public void FillAggregates(){
          String devicetype= '';
         string[] lststr1=sp.Device_Type__c.split(';');
            
 for (String s1: lststr1) {
                            devicetype+= '\'' + s1 + '\',';
                                }
                   devicetype= devicetype.substring (0,devicetype.length() -1);

            spwrapper=new List<siteplacementwrapper>();
            spwrapperexcel=new List<siteplacementwrapper>();
                   
             String sitePlacementQuery ='SELECT Id,Name from Site_Placements__c WHERE Device_Type__c INCLUDES (' + devicetype + ')  ';
            spRec=database.query(sitePlacementQuery);
            
            String sitePlacementQuery1 ='SELECT Id,Name  from Site_Placements__c WHERE Device_Type__c INCLUDES (' + devicetype + ')  ';
            spRec1=database.query(sitePlacementQuery1);
            
             if(spRec.size() == 0)
                {
                        Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No records match your criteria'));
                } 
             else {
             
              for(Site_Placements__c sitePlacement:spRec){
              
               siteplacementwrapper spr=new siteplacementwrapper();
               
               
              spr.Name=sitePlacement.Name;
              spwrapper.add(spr);
              }  
             
             for(Site_Placements__c sitePlacement:spRec1){
              
              siteplacementwrapper spr=new siteplacementwrapper();
               
              spr.Name=sitePlacement.Name;
             
              spwrapperexcel.add(spr);
             
             
             
             }
             
             }
         }  
                
                
        public PageReference FetchExcelReport() {
        PageReference nextpage = new PageReference('/apex/RFP_Excel_Page');
return nextpage;
}
         
         public pagereference CancelSPRec(){
     
    PageReference page = new PageReference('https://c.cs30.visual.force.com/apex/SiteListPage');
    page.SetRedirect(true);
    return page;
    }}

Visual Force Page:

<apex:page controller="Fetchsiteplacement" tabStyle="Site_Placements__c" sidebar="false">
<apex:form >
     
     <apex:pageBlock >
        <apex:messages layout="table" styleClass="exceptionText"/>
             <apex:pageBlockButtons location="Bottom">
          
            <apex:commandButton value="Search" action="{!FillAggregates}"/>
            <apex:commandButton value="Reset" action="{!CancelSPRec}"/>
            <apex:commandButton value="Export to CSV" action="{!FetchExcelReport}" id="theButton" />
            </apex:pageBlockButtons>
           
           <apex:pageBlockSection title="Select your filter criteria" collapsible="False">
             <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Player - Device Type" for="Devicetype"/>
                    <apex:inputField value="{!sp.Device_Type__c}" id="Devicetype"/>
                    
                </apex:pageBlockSectionItem>
                
                <apex:pageBlock >
            <apex:pageBlockSection title="Site List Results" collapsible="False">
            <apex:pageBlockSectionItem >
            
                <apex:pageblockTable value="{!spwrapper}" var="site" style="width:150%">
                   <apex:column style="width:650px"> <apex:facet name="header">Name</apex:facet>{!site.Name}</apex:column>
                   
                  </apex:pageBlockTable>
                 </apex:pageBlockSectionItem>
                 
           </apex:pageBlockSection>
           
</apex:pageblock> 
                 
                 </apex:form>
</apex:page>

Test Class:

@isTest(seeAllData=true)
private class TestFetchsiteplacement {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        Account a = new Account(Name='Test Account');
      insert a;

Publisher_Deal_Types__c pubdeal = new Publisher_Deal_Types__c ( Name = 'Test Publisher deal type', Account_Name__c = a.Id);
        
        insert pubdeal;
        
        
        Site_Placements__c sp = new Site_Placements__c ();
        sp.Name = 'Test site placement';
        insert sp;
      
      PageReference ref = new PageReference('/apex/SiteListPage');
      
      
    Test.setCurrentPage(ref);
 
    Test.startTest();
    Fetchsiteplacement myController = new Fetchsiteplacement();
    Test.stopTest();
 }
}
Hi All, 
I am using split function and new line character to split the long text area field and show them in different lines. It is working fine but it is also adding parentheses around every text in new line. I don't want them to add parentheses around every text. Below is my code.

rEntry.Publisher_URLs__c += ' ' + rC.publisher_Site_Placement_URL__r.Name.split('\n') + ';';

Output:
(sportsgroundgames.com); (womenshealthbase.com); (wwe.com);

Desired Output:
sportsgroundgames.com; womenshealthbase.com; wwe.com;

Can someone help me in removing parentheses. Thanks is advance.
 
Hey Guys, 

We just enabled email -to-case functionlaity in our company. Everytime someone sends email to routing address , it creates a case in salesforce. But if the emai is CC 'ed to someone else and he replies to that email , it creates a duplicate case in salesforce. We dont want any duplicates to be created everytime someone replies. I know if we can enable auto response notification and include Thread Id then we can avoid duplicates. And, I tried to send auto response email to everyone including CCed emails. But I was not able to set up that. So I was just wondering , is there a way send auto response email notification to all users including CCed one so that I can include Thread ID and avoid getting duplicates created ??? Or is there any other way to avoid duplicates ? Please help.

Thanks
Hey  
I have a multipicklist on VF page  which has 4 values. Is there a way to set all the 4 values as default values in the multipicklist whenever anyone opens the VF page. I know we can set only one value as default value but I want all 4 values to be default.

Thanks
Hey, 
I have Custom object "site_placement__c" . It's child object is "site_placement_audience__c". I have created a VF page which fetch the records from "site_placement__c" object based on a "device_type__c" field. It displays the records in a table. I also want to display the "impression_share__c" field from "site_placement_audience__c" along side in the table. I have read online that I need to create wrapper class for this . But I could not understand wrapper class. Can someone help me in understanding wrapper class and how to solve this. Below is my apex class and Page

Apex class

public class Fetchsiteplacementmulti{

String devicetype;

public Site_Placements__c  sp{get;set;}
 public List<Site_Placements__c > spRec{get;set;}
   
  
public Fetchsiteplacementmulti()
{
        sp=new Site_Placements__c ();
        spRec = new List<Site_Placements__c>();
        
}
       
         public void FillAggregates(){
        
         String devicetype= '';
         string[] lststr=sp.New_Device_Type__c.split(';');
             for (String s: lststr) {
                            devicetype+= '\'' + s + '\',';
                                }
                   devicetype= devicetype.substring (0,devicetype.length() -1);
                  
            
            String sitePlacementQuery ='SELECT Id,Name,Site_Level_Max_Impressions__c , Site_Placement_ID__c from Site_Placements__c WHERE  New_Device_Type__c INCLUDES (' + devicetype + ')  ORDER BY Site_Level_Max_Impressions__c DESC limit 10';
           
spRec=database.query(sitePlacementQuery);
           
            }
     
 }

Visualforce Page:

<apex:page controller="Fetchsiteplacementmulti" tabStyle="Site_Placements__c" sidebar="True">
<apex:form >
       
        <apex:pageBlock >
        <apex:messages />
            <apex:pageBlockButtons location="Both">
         
            <apex:commandButton value="Fetch" action="{!FillAggregates}"/>
            
            </apex:pageBlockButtons>
            <apex:pageBlockSection >
           
           
                </apex:pageBlockSection>
            <apex:pageBlockSection title="Please select the Critirea">
            
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="device" for="autoplay"/>
                    <apex:inputField value="{!sp.New_Device_Type__c}" id="autoplay"/>
                </apex:pageBlockSectionItem>
               
              </apex:pageBlockSection>
             
 <apex:pageBlockSection title="Results">
            <apex:pageBlockSectionItem >
                <apex:pageBlockTable value="{!spRec}" var="site" columnsWidth="500px, 500px" >
                    <apex:column value="{!site.Name}"/>
                    <apex:column value="{!site.Site_Placement_ID__c}"/>
                    <apex:column value="{!site.Site_Level_Max_Impressions__c}"/>
                   
                 </apex:pageBlockTable>
                 </apex:pageBlockSectionItem>
                
           </apex:pageBlockSection>
          
</apex:pageblock>
                
               </apex:form>
</apex:page>
Hey 
I have a custom button on opportunity Line Item called "TRAFFIC" . User can select any number of products in opportunity can press TRAFFIC button. When they press TRAFIC button , it changes the status of TRAFFICKED__c checkbox from false to true.  Trafficked__c checkbox is a field on opportunity products. I want to add a functionality in my existing code where it shuold also check status__c field condition in opportunity . Its like checking two conditions. Trafficked__c field on OLI and Status__c field on Opportunity and gives an alert message ( ARE YOU SURE ?)Below is my code.

{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')}

var opportunityRecord= {!GETRECORDIDS($ObjectType.OpportunityLineItem)};

if (opportunityRecord[0] == null) {
alert("Please select at least one product to traffic.") }
else {

var oppLineItemsIds = "";
//fetch opportunity Line items Ids
for(var rowNum in opportunityRecord){
oppLineItemsIds += "'"+ opportunityRecord[rowNum] + "',";
}

//remove last comma
oppLineItemsIds = oppLineItemsIds.slice(0, oppLineItemsIds.length - 1);

//Enclose the ids in round brackets
if(oppLineItemsIds.length > 1){
oppLineItemsIds = "(" + oppLineItemsIds + ")";
}


var result = sforce.connection.query("SELECT id,Trafficked__c FROM OpportunityLineItem WHERE ID in "+oppLineItemsIds);

var records = result.getArray("records");
if(records.Trafficked__c == 'false'){ 
alert("all set");
}
for(var i=0;i<records.length;i++)
{
if(records[i].Trafficked__c == 'false'){
records[i].Trafficked__c = true;
}

}

var resultoli = sforce.connection.update(records);
if(resultoli[0].success=='true'){
window.location.reload(); }
}
Hey, 
SO, I have an Apex trigger on opportunity Team Member which copies the team member with user role = ' Campaign Manager' to "Active_Campaign_Manager__c" field at opportunity. This trigger works fine when I individually add team members but it does NOT work when I click "ADD DEFAULT TEAM". It just does not fire . Below is my code. Please take a look and guide me.

trigger InsertOppTeam2ACM on OpportunityTeamMember (after insert, after update) {
//Using set to be able to work with setOpp and setOTM SETS

    set<Id> setOpp = new set<Id>();

    set<Id> setOTM = new set<Id>();
    

        for (OpportunityTeamMember oppTeam : trigger.new) {
         
          setOpp.add(oppTeam.OpportunityId);
          setOTM.add(oppTeam.id);
          }
//Loop through opportunity team members and grab Users who have these roles 'Campaign Manager'.

    list<OpportunityTeamMember> listOTM  = new list<OpportunityTeamMember>    
        ([
            SELECT Id, UserId, OpportunityId,  TeamMemberRole, User.Name FROM OpportunityTeamMember WHERE Id IN :setOTM AND
            (TeamMemberRole ='Campaign Manager') ]);

                                                   
// Create a map that grabs the Opportunity Id being worked with
      Map<Id,Opportunity> mapOpps = new map<Id, Opportunity>([SELECT Id FROM Opportunity Where Id = :setOpp ]) ;
 
        Opportunity tempOpp;

  
//Load the ID's
            for(OpportunityTeamMember otm : listOTM ){
                tempOpp = mapOpps.get(otm.OpportunityId);
        
            if(otm.TeamMemberRole == 'Campaign Manager') {
                tempOpp.Active_Campaign_Manager__c =  otm.User.Name;
              }


         }     
 
// Load values
 
update mapOpps.values();
}
Hey , 
By any means, can we add formula or workflow rule to store yesterday's target in field and today's target  in different field? both these fields will change there values everyday everytime we refresh the records ?

Thanks
Hey all, 
I am trying to generate a pop up alert message whenever a checkbox(Programmatic__c) is TRUE on Opportunity. The checkbox is getting updated by means of workflow. Below is the javascript embedded on VF page which gives an alert message. But, it gives error message everytime I refresh the checkbox. I want after giving error message once, the checkbox should be FALSE. or , if there is any other workround to display the error message only once.Below is my code:

<apex:page StandardController="Opportunity">

<script>

window.document.onload = new function(e)
{
  if({!Opportunity.Programmatic__c})
  {
    alert("Please enter value.");
  }
 
}
</script>


Need Help: Child Object :-   Test_site_audience__c
                      Master Object :-  Site_Placement__c
Demo__c is multi picklist field on child object. Demo__c has three values 'all', 'Male 12-23','Female 12-23'. There is one more field on chiled object called Impression_share__c. Based on each Demo__c value , Impression_Share__c has some value. i have created a visual force page. I am trying to sum the IMPRESSION_SHARE__C based on whatever user selects in Multi select picklist field. Below is the SOQL query. It is working if user selects one value in multipicklist field. But it is not working if user selects more than one value . Below is SOQL query.


Sumofimpressionshare = (Decimal)([ SELECT sum(Impression__share__c) FROM
             Test_site_audience__c Where (demo__c includes (:test.demo__c)) AND  site_placement_lookup__c in (select id FROM Site_Placements__c WHERE((Ad_Positioning__c like :matchString3)AND (Inventory_Type__c like :matchString4)AND (Language__c like :matchString5)AND (Flagged__c like :matchString6) ) )][0].get('expr0'));
Hey  Guys, 

I have created a visualforce page which displays the list of records which meet the critiriea on the page. Along with this , there are some fields  which are performaing some calculations. I am trying to display error message when it doesn't mee the critirea. It is working fine when there is no calculation field but when I include the calculation field , it gives me this error. In short, If I remove the Highlighted line in apex code it works fine but I do want to include that line also. Please help.
Attempt to de-reference a null object
Error is in expression '{!FetchSPRec}' in component <apex:commandButton> in page trial_rfp_page


Calculation field :- MaxImpression

Apex code:

public class Fetchsiteplacement12{
public Site_Placements__c  sp{get;set;}
    public List<Site_Placements__c > spRec{get;set;}
    String matchString;
    String matchString1;
    public integer NumberOfSitePlacements {get;set;}
    public decimal SumOfImpressions{get;set;}
    public decimal MaxImpressions{get;set;}
   
    public Fetchsiteplacement12(){
        sp=new Site_Placements__c ();
        spRec = new List<Site_Placements__c>();
        matchString = '';
        matchString1 ='';
        }
       
            public void FillAggregates()
                 {
                       NumberOfSitePlacements = [ Select count()
                       FROM Site_Placements__c where ((Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1))];
          
                       SumOfImpressions = (decimal)([ SELECT sum(Total_Impresions__c)
                       FROM Site_Placements__c Where ((Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1))][0].get('expr0'));
                      
                       MaxImpressions = SumOfImpressions/NumberOfSitePlacements ;
                 }
  
 
        public void FetchSPRec(){
        matchString = '%'+sp.Device_Type__c+'%';
        matchString1 = '%'+sp.Auto_Play__c+ '%';
      
      
      
        spRec=[select Name, Site_Placement_ID__c, Site_Level_Max_Impressions__c from Site_Placements__c where
        ((Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1) ) ORDER BY Site_Level_Max_Impressions__c DESC limit 10];
      
       if(spRec.size() == 0)
                  {
                   Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No records to Display"'));
                  }
                  FillAggregates();
                  }
      
       public pagereference CancelSPRec(){
    
    PageReference page = new PageReference('https://cs1.salesforce.com/a36/o');
    page.SetRedirect(true);
    return page;
    }}

VisualForce page:-

<apex:page controller="Fetchsiteplacement12" tabStyle="Site_Placements__c" sidebar="True">
    <apex:form >
        <apex:pageBlock >
        <apex:messages />
            <apex:pageBlockButtons location="Both">
         
            <apex:commandButton value="Fetch" action="{!FetchSPRec}"/>
            <apex:commandButton value="Cancel" action="{!CancelSPRec}"/>
            </apex:pageBlockButtons>
           
            <apex:pageBlockSection title="Please select the Critirea">
            
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Auto Play" for="autoplay"/>
                    <apex:inputField value="{!sp.Auto_Play__c}" id="autoplay"/>
                </apex:pageBlockSectionItem>
               
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Device Type" for="devicetype"/>
                    <apex:inputField value="{!sp.Device_Type__c}" id="devicetype"/>
                </apex:pageBlockSectionItem>
               
              
              <apex:pageBlockSection Title="Calculations">
          
                 <apex:pageBlockSectionItem > Number of site placements : {!NumberOfSitePlacements}<br/></apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem > Max Impressions : {!Maximpressions}<br/></apex:pageBlockSectionItem>
                 </apex:pageBlockSection>
            
              <apex:pageBlockSection title="Results">
            <apex:pageBlockSectionItem >
                <apex:pageBlockTable value="{!spRec}" var="site" >
                    <apex:column value="{!site.Name}"/>
                    <apex:column value="{!site.Site_Placement_ID__c}"/>
                    <apex:column value="{!site.Site_Level_Max_Impressions__c}"/>
                   
                 </apex:pageBlockTable>
                 </apex:pageBlockSectionItem>
                
           </apex:pageBlockSection>
         </apex:pageblock>
                
</apex:form>
</apex:page>

Hey Guys, 

I have written a VF page and apex class . Users have to enter certain information. Based on the critirea , code filters out the records and display the selected records on VF page which meet the critirea. It is able to fetch the records. But there are is Count() and Sum () aggregate functions which are also used in apex class. I am not able to print the those values on VF page. I have seen previous posts also and i cannot figure out what to do.Kindly tale a look at the code and please help.  In short I want to display the values of sum(impressions) , sum(requests) and count() on VF page.

Apex class:

public class siteplacementFetch{
public Site_Placements__c  sp{get;set;}
    public List<Site_Placements__c > spRec{get;set;}
    String matchString;
    String matchString1;
    String matchString2;
    public siteplacementFetch(){
        sp=new Site_Placements__c ();
        spRec = new List<Site_Placements__c>();
        matchString = '';
        matchString1 ='';
        matchString2 ='';
    }
  
    public void FetchSPRec(){
        matchString = '%'+sp.Device_Type__c+'%';
        matchString1 = '%'+sp.Auto_Play__c+ '%';
       matchString2 = '%'+sp.Number_of_Strikes_Given__c+ '%';
        spRec=[select Name, total_Impressions__c from Site_Placements__c where
        ((Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1) AND (Number_of_Strikes_Given__c like :matchString2)) ];}
       
     
                public integer total_values(){
      
       Integer counter = [ Select count()
                    FROM Site_Placements__c where ((Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1) AND (Number_of_Strikes_Given__c like :matchString2)) ];
   
    List<AggregateResult> results= [ SELECT sum(impressions__c)
            FROM site_placement_data__c
            WHERE site_placement__c in (select id FROM Site_Placements__c Where ((Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1) AND (Number_of_Strikes_Given__c like :matchString2))) ];
               
            List<AggregateResult> results1= [ SELECT sum(requests__c)
            FROM site_placement_data__c
            WHERE site_placement__c in (select id FROM Site_Placements__c Where ((Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1) AND (Number_of_Strikes_Given__c like :matchString2))
) GROUP BY site_placement__c];
return counter;}               
                   
     public pagereference CancelSPRec(){
    
    PageReference page = new PageReference('https://cs1.salesforce.com/a36/o');
    page.SetRedirect(true);
    return page;
    }}

Visual force page:

<apex:page controller="siteplacementFetch" tabStyle="Site_Placements__c">
  
    <apex:form >
        <apex:pageMessages />
        <apex:pageBlock >
            <apex:pageBlockButtons location="Top">
           
            <apex:commandButton value="Fetch" action="{!FetchSPRec}"/>

            </apex:pageBlockButtons>

             <apex:pageBlockSection title="Please select the Critirea">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Auto Play" for="autoplay"/>
                    <apex:inputText value="{!sp.Auto_Play__c}" id="autoplay"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Number of Strikes" for="numberofstrikes"/>
                    <apex:inputField value="{!sp.Number_of_Strikes_Given__c}" id="numberofstrikes"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Device Type" for="devicetype"/>
                    <apex:inputField value="{!sp.Device_Type__c}" id="devicetype"/>
                </apex:pageBlockSectionItem>
               
               
             </apex:pageBlockSection>
            <apex:pageBlockSection title="Results">
                <apex:pageBlockTable value="{!spRec}" var="site" >
                    <apex:column value="{!site.Name}"/>
                    <apex:column value="{!site.total_Impressions__c}"/>
                    

                 </apex:pageBlockTable>
               
           
       
            </apex:pageBlockSection>
            </apex:pageblock>    
           
        </apex:form>
</apex:page>
Hi, 

I am creating a basic VF page in which user will enter something in EDUCATIONAL_REQUIREMENTS__c field and it will fetch the records from POSITION__c object which matches the field critirea. It is not giving me any error but it is also not fetching the reocrds based on the critirea. Kindly take a look . I believe, I am doing something wrong in SOQL query. Below is my VF page and APEX class.


public class positionFetch{

    public String sp { get; set; }
public POSITION__c  p{get;set;}
    public List<POSITION__c > pRec{get;set;}
    String matchString;
    /
   
    public positionFetch(){
        p=new POSITION__c ();
        pRec = new List<POSITION__c>();
        matchString = '';
       
    }
   
    public void FetchPRec(){
        matchString = '%'+p.EDUCATIONAL_REQUIREMENTS__c+'%';
       
        pRec=[select Name from POSITION__c WHERE (Name like :matchString) ];
        }}


VF page:

<apex:page controller="positionFetch" >
  
    <apex:form >
        <apex:pageMessages />
        <apex:pageBlock >
            <apex:pageBlockButtons location="Top">
           
            <apex:commandButton value="Fetch" action="{!FetchPRec}"/>
           

            </apex:pageBlockButtons>

             <apex:pageBlockSection title="Please select the Critirea">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Requirement" for="autoplay"/>
                    <apex:inputText value="{!p.EDUCATIONAL_REQUIREMENTS__c}" id="autoplay"/>
                </apex:pageBlockSectionItem>
                </apex:pageBlockSection>
            <apex:pageBlockSection title="Results" rendered="{!pRec.size>0}">
                <apex:pageBlockTable value="{!pRec}" var="site" >
                    <apex:column value="{!site.Name}"/>
                    

                 </apex:pageBlockTable>
               
           
       
            </apex:pageBlockSection>
            </apex:pageblock>    
           
           
              
               
           
    </apex:form>
</apex:page>
Hey Guys, 

I am new to Apex development. I am trying to write a VF page in which user will enter values in certain fields. And, then they will click the FETCH button. Based on the information entered in the fields the FETCH button will get the records from cutom object which meet the the critirea. I know it looks simple but I cannot figure out the logic. In general I can fetch the records but not those records which meet the critirea. I am posting the work I have done. I would really appreciate if some can help. I am getting this error.

List has no rows for assignment to SObject

VF page:

<apex:page controller="newsiteplacement1" tabStyle="Site_Placements__c">
   <apex:form >
    <apex:pageMessages />
        <apex:pageBlock >
                <center>
                <apex:pageBlockButtons location="top">
                <apex:commandButton action="{!Fetch}" value="Fetch"/>
               
                </apex:pageBlockButtons>
                </center>
                <apex:pageBlockSection title="Initial Input Information"
collapsible="false">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Passed CPM Floor" />
                    <apex:inputField value="{!splace.Passed_CPM_Floor__c}"/>
                </apex:pageBlockSectionItem>
               
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Auto Play" />
                    <apex:inputField value="{!splace.Auto_Play__c}"/>
                </apex:pageBlockSectionItem>
               </apex:pageBlockSection>
        </apex:pageBlock>
   </apex:form>
</apex:page>

Apex Class:

public class newsiteplacement1
{
    private final Site_Placements__c splace;
    //public List<Site_Placements__c> splace {get; set;}
   
        public newsiteplacement1()
           
            {
              
                splace=[SELECT Id,Name FROM Site_Placements__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
               
            }
           
            public Site_Placements__c getsplace() {
        return splace;
    }
    public PageReference Fetch() {
        //update splace;
        return null;
    }
           
}
Hi All , 

I have wriiten a very simple trigger which will update the field value based on the start date. This startd date is custom date field (start_date__c). The trigger is below. I want to hard code the date field value in IF condition, I cannot hard code that field or i dont know how to hard code date field.Can you please help me ?

trigger convertedamountGBP on Schedules_and_Actuals__c (before insert,before update) {

        for ( Schedules_and_Actuals__c sch : trigger.new)
            {
          
               if (sch.Start_Date__c  = '2014-01-01')
                   {
                   sch.Converted_Amount_GBP__c = sch.Converted_currency_USD__c*2 ;
                   }
                  
             }

}
Hi , 

I have created a button on opportunity called clone1. This button works same like CLONE button. It clones the opportunity along with the opportunity line items. I want to control the behiour of cstom field (xyz__c) which is a checkbox on the opportunty line item. whenever user clones the opportunity with product , the xyz__c field on opportunity line item should always be set to False.  Below is the custom button. But for some reason , I am not able to set the status of this field to FALSE.

{!URLFOR($Action.Opportunity.Clone, Opportunity.Id,
[
cloneli=1],
true)}&00N70000003JOPM=False
Hi All,

I have created a custom button executing javascript on Opprtunity product related list of opportunity. This button just mass updates the checkbox (Trafficked__c) to true on selected opportunity line items of opportunity. Business users just have to select the number of line items and click the button and the checkbox will be set to TRUE. I want with the second click on the button , the ckeckbox should be set to FALSE.  Below is the javascript which sets the cjeckbos to TRUE. Kindly help.

{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')}

var opportunityRecord= {!GETRECORDIDS($ObjectType.OpportunityLineItem)};

if (opportunityRecord[0] == null) {
alert("Please select at least one product to traffic.") }
else {

var oppLineItemsIds = "";
//fetch opportunity Line items Ids
for(var rowNum in opportunityRecord){
oppLineItemsIds += "'"+ opportunityRecord[rowNum] + "',";
}

//remove last comma
oppLineItemsIds = oppLineItemsIds.slice(0, oppLineItemsIds.length - 1);

//Enclose the ids in round brackets
if(oppLineItemsIds.length > 1){
oppLineItemsIds = "(" + oppLineItemsIds + ")";
}


var result = sforce.connection.query("SELECT id,Trafficked__c FROM OpportunityLineItem WHERE ID in "+oppLineItemsIds);

var records = result.getArray("records");

for(var i=0;i<records.length;i++)
{

records[i].Trafficked__c = true;

}

var resultoli = sforce.connection.update(records);
if(resultoli[0].success=='true'){
window.location.reload(); }
}

Hey Guys,

 

I am trying to create a custom button executing javascript. This button is same like DELETE button . it will also delete records only when certain checkbox is  NOT checked off. If that checkbox is checked off , it should not delete records rather it should give an alert message. Below is the javascript. But Everytime , I click the button on record , I get this error: Please help me in fixing the code.

 

A problem with the OnClick JavaScript for this button or link was encountered:

Unexpected token '{'

 


Javascript&colon;

 

{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')} 

var oppty = new sforce.SObject('OpportunityLineItem'); 
oppty.Id = '{!OpportunityLineItem.Id}'; 

If ( oppty.Trafficked__c = 'False'){ 
var resultoppty = sforce.connection.delete([oppty]); 

else 

alert('cannot delete.please retry again'); 
location.reload(); 
}

Hey Guys, 

 

I have an OPPORTUNITY LINE ITEM object. On this, I have a lookup field to SCHEDULE_HEADER__c object. Name of look up field on Opportunity line item is SCHEDULE_HEADER__c. we have one field on schedule_header__c object called SCH_ACTUAL_UNITS__C. we want whatever value is present in sch_actual_units__c, it should be copied to TOTALPRICE field on opportunity line item object. I have written a code , But i am getting this error. Please help.

 

Compile Error: Invalid foreign key relationship: Schedule_Header__c.OpportunityLineItem__c at line 9 column 23

 

trigger OppStatus on Schedule_Header__c (after insert, after update) {


List<ID> schID = New List<ID> ();


for(Schedule_Header__c sch : Trigger.new){
if(sch.Sch_Actuals_Total__c != NULL){
schID.add(sch.OpportunityLineItem__c.Id);
}
}

List<OpportunityLineItem> OppLineUpdateList = [SELECT Id,TotalPrice FROM OpportunityLineItem WHERE id in: schID];
for(integer i = 0; i < OppLineUpdateList.size(); i++){
OppLineUpdateList[i].TotalPrice = schID;
}

update OppLineUpdateList;
}

 

Hey, 
SO, I have an Apex trigger on opportunity Team Member which copies the team member with user role = ' Campaign Manager' to "Active_Campaign_Manager__c" field at opportunity. This trigger works fine when I individually add team members but it does NOT work when I click "ADD DEFAULT TEAM". It just does not fire . Below is my code. Please take a look and guide me.

trigger InsertOppTeam2ACM on OpportunityTeamMember (after insert, after update) {
//Using set to be able to work with setOpp and setOTM SETS

    set<Id> setOpp = new set<Id>();

    set<Id> setOTM = new set<Id>();
    

        for (OpportunityTeamMember oppTeam : trigger.new) {
         
          setOpp.add(oppTeam.OpportunityId);
          setOTM.add(oppTeam.id);
          }
//Loop through opportunity team members and grab Users who have these roles 'Campaign Manager'.

    list<OpportunityTeamMember> listOTM  = new list<OpportunityTeamMember>    
        ([
            SELECT Id, UserId, OpportunityId,  TeamMemberRole, User.Name FROM OpportunityTeamMember WHERE Id IN :setOTM AND
            (TeamMemberRole ='Campaign Manager') ]);

                                                   
// Create a map that grabs the Opportunity Id being worked with
      Map<Id,Opportunity> mapOpps = new map<Id, Opportunity>([SELECT Id FROM Opportunity Where Id = :setOpp ]) ;
 
        Opportunity tempOpp;

  
//Load the ID's
            for(OpportunityTeamMember otm : listOTM ){
                tempOpp = mapOpps.get(otm.OpportunityId);
        
            if(otm.TeamMemberRole == 'Campaign Manager') {
                tempOpp.Active_Campaign_Manager__c =  otm.User.Name;
              }


         }     
 
// Load values
 
update mapOpps.values();
}
Hey, 

I have written an Apex class and Visual Force page which searches the records from custom object. There is a field which is a multi pick list and it is a fielter field. User seletcs the value in that field and all the records meeting the critiriea appear in the 'Results' section. This page has 3 buttons "Search", "Cancel" and "Export to CSV". I am not good in writing a test class but I tried to write some and it is not giving my desired code coverage. Can someone pleae help me out ? Any help will be appreciated

Apex class:
public class Fetchsiteplacement{
String devicetype;
 
   public Site_Placements__c  sp{get;set;}
    public List<Site_Placements__c > spRec{get;set;}
    public List<Site_Placements__c > spRec1{get;set;}
    public List<siteplacementwrapper> spwrapper{get;set;}
    public List<siteplacementwrapper> spwrapperexcel{get;set;}    

    public class siteplacementwrapper{
            
           
            public String Name {get;set;}
           }
        public Fetchsiteplacement(){
        sp=new Site_Placements__c ();
        spRec = new List<Site_Placements__c>();
        
        }
        
         public void FillAggregates(){
          String devicetype= '';
         string[] lststr1=sp.Device_Type__c.split(';');
            
 for (String s1: lststr1) {
                            devicetype+= '\'' + s1 + '\',';
                                }
                   devicetype= devicetype.substring (0,devicetype.length() -1);

            spwrapper=new List<siteplacementwrapper>();
            spwrapperexcel=new List<siteplacementwrapper>();
                   
             String sitePlacementQuery ='SELECT Id,Name from Site_Placements__c WHERE Device_Type__c INCLUDES (' + devicetype + ')  ';
            spRec=database.query(sitePlacementQuery);
            
            String sitePlacementQuery1 ='SELECT Id,Name  from Site_Placements__c WHERE Device_Type__c INCLUDES (' + devicetype + ')  ';
            spRec1=database.query(sitePlacementQuery1);
            
             if(spRec.size() == 0)
                {
                        Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No records match your criteria'));
                } 
             else {
             
              for(Site_Placements__c sitePlacement:spRec){
              
               siteplacementwrapper spr=new siteplacementwrapper();
               
               
              spr.Name=sitePlacement.Name;
              spwrapper.add(spr);
              }  
             
             for(Site_Placements__c sitePlacement:spRec1){
              
              siteplacementwrapper spr=new siteplacementwrapper();
               
              spr.Name=sitePlacement.Name;
             
              spwrapperexcel.add(spr);
             
             
             
             }
             
             }
         }  
                
                
        public PageReference FetchExcelReport() {
        PageReference nextpage = new PageReference('/apex/RFP_Excel_Page');
return nextpage;
}
         
         public pagereference CancelSPRec(){
     
    PageReference page = new PageReference('https://c.cs30.visual.force.com/apex/SiteListPage');
    page.SetRedirect(true);
    return page;
    }}

Visual Force Page:

<apex:page controller="Fetchsiteplacement" tabStyle="Site_Placements__c" sidebar="false">
<apex:form >
     
     <apex:pageBlock >
        <apex:messages layout="table" styleClass="exceptionText"/>
             <apex:pageBlockButtons location="Bottom">
          
            <apex:commandButton value="Search" action="{!FillAggregates}"/>
            <apex:commandButton value="Reset" action="{!CancelSPRec}"/>
            <apex:commandButton value="Export to CSV" action="{!FetchExcelReport}" id="theButton" />
            </apex:pageBlockButtons>
           
           <apex:pageBlockSection title="Select your filter criteria" collapsible="False">
             <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Player - Device Type" for="Devicetype"/>
                    <apex:inputField value="{!sp.Device_Type__c}" id="Devicetype"/>
                    
                </apex:pageBlockSectionItem>
                
                <apex:pageBlock >
            <apex:pageBlockSection title="Site List Results" collapsible="False">
            <apex:pageBlockSectionItem >
            
                <apex:pageblockTable value="{!spwrapper}" var="site" style="width:150%">
                   <apex:column style="width:650px"> <apex:facet name="header">Name</apex:facet>{!site.Name}</apex:column>
                   
                  </apex:pageBlockTable>
                 </apex:pageBlockSectionItem>
                 
           </apex:pageBlockSection>
           
</apex:pageblock> 
                 
                 </apex:form>
</apex:page>

Test Class:

@isTest(seeAllData=true)
private class TestFetchsiteplacement {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        Account a = new Account(Name='Test Account');
      insert a;

Publisher_Deal_Types__c pubdeal = new Publisher_Deal_Types__c ( Name = 'Test Publisher deal type', Account_Name__c = a.Id);
        
        insert pubdeal;
        
        
        Site_Placements__c sp = new Site_Placements__c ();
        sp.Name = 'Test site placement';
        insert sp;
      
      PageReference ref = new PageReference('/apex/SiteListPage');
      
      
    Test.setCurrentPage(ref);
 
    Test.startTest();
    Fetchsiteplacement myController = new Fetchsiteplacement();
    Test.stopTest();
 }
}
Hi All, 
I am using split function and new line character to split the long text area field and show them in different lines. It is working fine but it is also adding parentheses around every text in new line. I don't want them to add parentheses around every text. Below is my code.

rEntry.Publisher_URLs__c += ' ' + rC.publisher_Site_Placement_URL__r.Name.split('\n') + ';';

Output:
(sportsgroundgames.com); (womenshealthbase.com); (wwe.com);

Desired Output:
sportsgroundgames.com; womenshealthbase.com; wwe.com;

Can someone help me in removing parentheses. Thanks is advance.
 
Hey 
I have a custom button on opportunity Line Item called "TRAFFIC" . User can select any number of products in opportunity can press TRAFFIC button. When they press TRAFIC button , it changes the status of TRAFFICKED__c checkbox from false to true.  Trafficked__c checkbox is a field on opportunity products. I want to add a functionality in my existing code where it shuold also check status__c field condition in opportunity . Its like checking two conditions. Trafficked__c field on OLI and Status__c field on Opportunity and gives an alert message ( ARE YOU SURE ?)Below is my code.

{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')}

var opportunityRecord= {!GETRECORDIDS($ObjectType.OpportunityLineItem)};

if (opportunityRecord[0] == null) {
alert("Please select at least one product to traffic.") }
else {

var oppLineItemsIds = "";
//fetch opportunity Line items Ids
for(var rowNum in opportunityRecord){
oppLineItemsIds += "'"+ opportunityRecord[rowNum] + "',";
}

//remove last comma
oppLineItemsIds = oppLineItemsIds.slice(0, oppLineItemsIds.length - 1);

//Enclose the ids in round brackets
if(oppLineItemsIds.length > 1){
oppLineItemsIds = "(" + oppLineItemsIds + ")";
}


var result = sforce.connection.query("SELECT id,Trafficked__c FROM OpportunityLineItem WHERE ID in "+oppLineItemsIds);

var records = result.getArray("records");
if(records.Trafficked__c == 'false'){ 
alert("all set");
}
for(var i=0;i<records.length;i++)
{
if(records[i].Trafficked__c == 'false'){
records[i].Trafficked__c = true;
}

}

var resultoli = sforce.connection.update(records);
if(resultoli[0].success=='true'){
window.location.reload(); }
}
Hey , 
By any means, can we add formula or workflow rule to store yesterday's target in field and today's target  in different field? both these fields will change there values everyday everytime we refresh the records ?

Thanks
Need Help: Child Object :-   Test_site_audience__c
                      Master Object :-  Site_Placement__c
Demo__c is multi picklist field on child object. Demo__c has three values 'all', 'Male 12-23','Female 12-23'. There is one more field on chiled object called Impression_share__c. Based on each Demo__c value , Impression_Share__c has some value. i have created a visual force page. I am trying to sum the IMPRESSION_SHARE__C based on whatever user selects in Multi select picklist field. Below is the SOQL query. It is working if user selects one value in multipicklist field. But it is not working if user selects more than one value . Below is SOQL query.


Sumofimpressionshare = (Decimal)([ SELECT sum(Impression__share__c) FROM
             Test_site_audience__c Where (demo__c includes (:test.demo__c)) AND  site_placement_lookup__c in (select id FROM Site_Placements__c WHERE((Ad_Positioning__c like :matchString3)AND (Inventory_Type__c like :matchString4)AND (Language__c like :matchString5)AND (Flagged__c like :matchString6) ) )][0].get('expr0'));
Hey  Guys, 

I have created a visualforce page which displays the list of records which meet the critiriea on the page. Along with this , there are some fields  which are performaing some calculations. I am trying to display error message when it doesn't mee the critirea. It is working fine when there is no calculation field but when I include the calculation field , it gives me this error. In short, If I remove the Highlighted line in apex code it works fine but I do want to include that line also. Please help.
Attempt to de-reference a null object
Error is in expression '{!FetchSPRec}' in component <apex:commandButton> in page trial_rfp_page


Calculation field :- MaxImpression

Apex code:

public class Fetchsiteplacement12{
public Site_Placements__c  sp{get;set;}
    public List<Site_Placements__c > spRec{get;set;}
    String matchString;
    String matchString1;
    public integer NumberOfSitePlacements {get;set;}
    public decimal SumOfImpressions{get;set;}
    public decimal MaxImpressions{get;set;}
   
    public Fetchsiteplacement12(){
        sp=new Site_Placements__c ();
        spRec = new List<Site_Placements__c>();
        matchString = '';
        matchString1 ='';
        }
       
            public void FillAggregates()
                 {
                       NumberOfSitePlacements = [ Select count()
                       FROM Site_Placements__c where ((Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1))];
          
                       SumOfImpressions = (decimal)([ SELECT sum(Total_Impresions__c)
                       FROM Site_Placements__c Where ((Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1))][0].get('expr0'));
                      
                       MaxImpressions = SumOfImpressions/NumberOfSitePlacements ;
                 }
  
 
        public void FetchSPRec(){
        matchString = '%'+sp.Device_Type__c+'%';
        matchString1 = '%'+sp.Auto_Play__c+ '%';
      
      
      
        spRec=[select Name, Site_Placement_ID__c, Site_Level_Max_Impressions__c from Site_Placements__c where
        ((Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1) ) ORDER BY Site_Level_Max_Impressions__c DESC limit 10];
      
       if(spRec.size() == 0)
                  {
                   Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No records to Display"'));
                  }
                  FillAggregates();
                  }
      
       public pagereference CancelSPRec(){
    
    PageReference page = new PageReference('https://cs1.salesforce.com/a36/o');
    page.SetRedirect(true);
    return page;
    }}

VisualForce page:-

<apex:page controller="Fetchsiteplacement12" tabStyle="Site_Placements__c" sidebar="True">
    <apex:form >
        <apex:pageBlock >
        <apex:messages />
            <apex:pageBlockButtons location="Both">
         
            <apex:commandButton value="Fetch" action="{!FetchSPRec}"/>
            <apex:commandButton value="Cancel" action="{!CancelSPRec}"/>
            </apex:pageBlockButtons>
           
            <apex:pageBlockSection title="Please select the Critirea">
            
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Auto Play" for="autoplay"/>
                    <apex:inputField value="{!sp.Auto_Play__c}" id="autoplay"/>
                </apex:pageBlockSectionItem>
               
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Device Type" for="devicetype"/>
                    <apex:inputField value="{!sp.Device_Type__c}" id="devicetype"/>
                </apex:pageBlockSectionItem>
               
              
              <apex:pageBlockSection Title="Calculations">
          
                 <apex:pageBlockSectionItem > Number of site placements : {!NumberOfSitePlacements}<br/></apex:pageBlockSectionItem>
                 <apex:pageBlockSectionItem > Max Impressions : {!Maximpressions}<br/></apex:pageBlockSectionItem>
                 </apex:pageBlockSection>
            
              <apex:pageBlockSection title="Results">
            <apex:pageBlockSectionItem >
                <apex:pageBlockTable value="{!spRec}" var="site" >
                    <apex:column value="{!site.Name}"/>
                    <apex:column value="{!site.Site_Placement_ID__c}"/>
                    <apex:column value="{!site.Site_Level_Max_Impressions__c}"/>
                   
                 </apex:pageBlockTable>
                 </apex:pageBlockSectionItem>
                
           </apex:pageBlockSection>
         </apex:pageblock>
                
</apex:form>
</apex:page>

Hey Guys, 

I have written a VF page and apex class . Users have to enter certain information. Based on the critirea , code filters out the records and display the selected records on VF page which meet the critirea. It is able to fetch the records. But there are is Count() and Sum () aggregate functions which are also used in apex class. I am not able to print the those values on VF page. I have seen previous posts also and i cannot figure out what to do.Kindly tale a look at the code and please help.  In short I want to display the values of sum(impressions) , sum(requests) and count() on VF page.

Apex class:

public class siteplacementFetch{
public Site_Placements__c  sp{get;set;}
    public List<Site_Placements__c > spRec{get;set;}
    String matchString;
    String matchString1;
    String matchString2;
    public siteplacementFetch(){
        sp=new Site_Placements__c ();
        spRec = new List<Site_Placements__c>();
        matchString = '';
        matchString1 ='';
        matchString2 ='';
    }
  
    public void FetchSPRec(){
        matchString = '%'+sp.Device_Type__c+'%';
        matchString1 = '%'+sp.Auto_Play__c+ '%';
       matchString2 = '%'+sp.Number_of_Strikes_Given__c+ '%';
        spRec=[select Name, total_Impressions__c from Site_Placements__c where
        ((Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1) AND (Number_of_Strikes_Given__c like :matchString2)) ];}
       
     
                public integer total_values(){
      
       Integer counter = [ Select count()
                    FROM Site_Placements__c where ((Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1) AND (Number_of_Strikes_Given__c like :matchString2)) ];
   
    List<AggregateResult> results= [ SELECT sum(impressions__c)
            FROM site_placement_data__c
            WHERE site_placement__c in (select id FROM Site_Placements__c Where ((Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1) AND (Number_of_Strikes_Given__c like :matchString2))) ];
               
            List<AggregateResult> results1= [ SELECT sum(requests__c)
            FROM site_placement_data__c
            WHERE site_placement__c in (select id FROM Site_Placements__c Where ((Device_Type__c like :matchString) AND (Auto_Play__c like :matchString1) AND (Number_of_Strikes_Given__c like :matchString2))
) GROUP BY site_placement__c];
return counter;}               
                   
     public pagereference CancelSPRec(){
    
    PageReference page = new PageReference('https://cs1.salesforce.com/a36/o');
    page.SetRedirect(true);
    return page;
    }}

Visual force page:

<apex:page controller="siteplacementFetch" tabStyle="Site_Placements__c">
  
    <apex:form >
        <apex:pageMessages />
        <apex:pageBlock >
            <apex:pageBlockButtons location="Top">
           
            <apex:commandButton value="Fetch" action="{!FetchSPRec}"/>

            </apex:pageBlockButtons>

             <apex:pageBlockSection title="Please select the Critirea">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Auto Play" for="autoplay"/>
                    <apex:inputText value="{!sp.Auto_Play__c}" id="autoplay"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Number of Strikes" for="numberofstrikes"/>
                    <apex:inputField value="{!sp.Number_of_Strikes_Given__c}" id="numberofstrikes"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Device Type" for="devicetype"/>
                    <apex:inputField value="{!sp.Device_Type__c}" id="devicetype"/>
                </apex:pageBlockSectionItem>
               
               
             </apex:pageBlockSection>
            <apex:pageBlockSection title="Results">
                <apex:pageBlockTable value="{!spRec}" var="site" >
                    <apex:column value="{!site.Name}"/>
                    <apex:column value="{!site.total_Impressions__c}"/>
                    

                 </apex:pageBlockTable>
               
           
       
            </apex:pageBlockSection>
            </apex:pageblock>    
           
        </apex:form>
</apex:page>
Hi, 

I am creating a basic VF page in which user will enter something in EDUCATIONAL_REQUIREMENTS__c field and it will fetch the records from POSITION__c object which matches the field critirea. It is not giving me any error but it is also not fetching the reocrds based on the critirea. Kindly take a look . I believe, I am doing something wrong in SOQL query. Below is my VF page and APEX class.


public class positionFetch{

    public String sp { get; set; }
public POSITION__c  p{get;set;}
    public List<POSITION__c > pRec{get;set;}
    String matchString;
    /
   
    public positionFetch(){
        p=new POSITION__c ();
        pRec = new List<POSITION__c>();
        matchString = '';
       
    }
   
    public void FetchPRec(){
        matchString = '%'+p.EDUCATIONAL_REQUIREMENTS__c+'%';
       
        pRec=[select Name from POSITION__c WHERE (Name like :matchString) ];
        }}


VF page:

<apex:page controller="positionFetch" >
  
    <apex:form >
        <apex:pageMessages />
        <apex:pageBlock >
            <apex:pageBlockButtons location="Top">
           
            <apex:commandButton value="Fetch" action="{!FetchPRec}"/>
           

            </apex:pageBlockButtons>

             <apex:pageBlockSection title="Please select the Critirea">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Requirement" for="autoplay"/>
                    <apex:inputText value="{!p.EDUCATIONAL_REQUIREMENTS__c}" id="autoplay"/>
                </apex:pageBlockSectionItem>
                </apex:pageBlockSection>
            <apex:pageBlockSection title="Results" rendered="{!pRec.size>0}">
                <apex:pageBlockTable value="{!pRec}" var="site" >
                    <apex:column value="{!site.Name}"/>
                    

                 </apex:pageBlockTable>
               
           
       
            </apex:pageBlockSection>
            </apex:pageblock>    
           
           
              
               
           
    </apex:form>
</apex:page>
Hey Guys, 

I am new to Apex development. I am trying to write a VF page in which user will enter values in certain fields. And, then they will click the FETCH button. Based on the information entered in the fields the FETCH button will get the records from cutom object which meet the the critirea. I know it looks simple but I cannot figure out the logic. In general I can fetch the records but not those records which meet the critirea. I am posting the work I have done. I would really appreciate if some can help. I am getting this error.

List has no rows for assignment to SObject

VF page:

<apex:page controller="newsiteplacement1" tabStyle="Site_Placements__c">
   <apex:form >
    <apex:pageMessages />
        <apex:pageBlock >
                <center>
                <apex:pageBlockButtons location="top">
                <apex:commandButton action="{!Fetch}" value="Fetch"/>
               
                </apex:pageBlockButtons>
                </center>
                <apex:pageBlockSection title="Initial Input Information"
collapsible="false">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Passed CPM Floor" />
                    <apex:inputField value="{!splace.Passed_CPM_Floor__c}"/>
                </apex:pageBlockSectionItem>
               
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Auto Play" />
                    <apex:inputField value="{!splace.Auto_Play__c}"/>
                </apex:pageBlockSectionItem>
               </apex:pageBlockSection>
        </apex:pageBlock>
   </apex:form>
</apex:page>

Apex Class:

public class newsiteplacement1
{
    private final Site_Placements__c splace;
    //public List<Site_Placements__c> splace {get; set;}
   
        public newsiteplacement1()
           
            {
              
                splace=[SELECT Id,Name FROM Site_Placements__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
               
            }
           
            public Site_Placements__c getsplace() {
        return splace;
    }
    public PageReference Fetch() {
        //update splace;
        return null;
    }
           
}

Hey Guys,

 

I am trying to create a custom button executing javascript. This button is same like DELETE button . it will also delete records only when certain checkbox is  NOT checked off. If that checkbox is checked off , it should not delete records rather it should give an alert message. Below is the javascript. But Everytime , I click the button on record , I get this error: Please help me in fixing the code.

 

A problem with the OnClick JavaScript for this button or link was encountered:

Unexpected token '{'

 


Javascript&colon;

 

{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')} 

var oppty = new sforce.SObject('OpportunityLineItem'); 
oppty.Id = '{!OpportunityLineItem.Id}'; 

If ( oppty.Trafficked__c = 'False'){ 
var resultoppty = sforce.connection.delete([oppty]); 

else 

alert('cannot delete.please retry again'); 
location.reload(); 
}