• Kevin Swiggum
  • NEWBIE
  • 250 Points
  • Member since 2008


  • Chatter
    Feed
  • 10
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 48
    Replies

I would like to tweak the apex class in the link below to only count activities with a type of "Call". How can I do that?

 

Link: http://www.radialweb.com/2010/08/summarizing_salesforce_fields_with_triggers/#comments

Hey all,

I feel dumb even posting this, becuase I'm sure it's just a typo or some goofy thing, but I feel like I've wasted enough time tracking it down. Time to let the big guns help me out ;)

 

Pretty simple thing. I have a pageBlockTable. One of the links in it, lets me delete that row. After the row is deleted the table should be rerendered so you can see that it has been removed. Currently the record DOES get deleted, but the table is not rerendered. I tried putting it in an output panel and no luck there. I was wondering if maybe the table is reloading before the record is actually deleteed, causing a 'race' condition type of situation? Anyway, below is the code. Feel free to point out what I am doing wrong, and then laugh at me for being such a newb :P

Page (unneccary crap removed)

<apex:form id="form">
    <apex:actionFunction action="{!deleteFile}" name="removeAttachment" reRender="attachmentsTable" status="working" >
        <apex:param name="aId" value="" />
    </apex:actionFunction>
	
    <apex:actionstatus id="working">
		Deleting....
	</apex:actionstatus>
    
    
        <apex:pageBlock title="Existing Attachments" rendered="{!showExisting}" id="attachmentsTable">
            <apex:pageBlockTable value="{!attachments}" var="attachment">
                <apex:column headerValue="Action">
                    <apex:outputLink value="{!URLFOR($Action.Attachment.Download, attachment.Id)}" target="_blank">View</apex:outputLink>
                    |
                    <apex:outputText> <a id="{!attachment.id}" class="deleteLink">Del</a> </apex:outputText>
                </apex:column>
                <apex:column value="{!attachment.Name}"/>
                <apex:column value="{!attachment.Description}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
 
</apex:form>

 controller

 

   public static void deleteFile()
    {
        string attachmentId = Apexpages.currentPage().getParameters().get('aId');
        Attachment thisAttachment = new Attachment(id=attachmentId);
        delete thisAttachment;        
    }

 

Hi folks,

      I have a small trigger and my test class is not giving coverage for me to deploy to prod.

 

Trigger:

 

trigger UserLead on Lead (after insert)
{
Campaign C = [Select Id,Name from Campaign where Name = 'Campaign' limit 1];
List<CampaignMember> CM = new List<CampaignMember>();
for(Lead L : Trigger.New)
{
    if(L.ConnectionReceivedId != null)
    {
        CampaignMember Cmp = new CampaignMember();
        Cmp.LeadId = L.Id;
        Cmp.CampaignId = C.Id;
        Cmp.Status = 'Sent';
        CM.add(Cmp);
    }
}
    
    insert CM;
}

 

 

Test Class:

 

@isTest
private class UserRegion {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
         List<CampaignMember> CM = new List<CampaignMember>();

 

Campaign c = new Campaign(Name = 'Universal', Campaign_Objective__c = 'Marketing', Type = 'Blog', StartDate =  Date.newInstance(2010,02,01),EndDate = Date.newInstance(2011,02,01), Status = 'New');
 insert c;
 Lead l1 = new Lead (LeadType__c = 'New', Company = 'xyz', Status = 'New', Region__c = 'CAN', LastName = 'mytest');
 insert l1;
 CampaignMember cmp = new CampaignMember( CampaignId = c.Id, LeadId = l1.Id, Status = 'Sent');
  insert cmp;
    
    }
}

 

when i run this test class, the below part is not covered and it only gives me 50%

 

        CampaignMember Cmp = new CampaignMember();
        Cmp.LeadId = L.Id;
        Cmp.CampaignId = C.Id;
        Cmp.Status = 'Sent';
        CM.add(Cmp);

 

Any help is most Appreciated.

 

TIA!

 

I have an issue that I cant seem to resolve.  I have a Force.com Free Edition org an I am building some Pages in the Sandbox.  I have a simple custom object that is acting sort of like a Hit counter.  It's just got a couple of text fields and a timestamp field right now.

 

My controller is working fine.  The page is rendered and pulls/displays data from another custom object just fine.  The problem occurs when I try to insert a record to this Hit Counter object.  I am routed to the "Required Login" screen.  If I comment out the insert statement, the page is fine.  I am well aware of the permissions that need to be available to the guest user under Sites -> Public Access Settings.  Here is what I know so far...

 

 

  • The object in question has read, create, and edit checked for the guest user
  • The field level security is set to visible for everything and nothing is checked to be read only for the guest user (except for the system fields that you cant change)
  • The guest user has access to all VF Pages
  • The guest user has access to all Apex classes
  • There are no triggers on the custom object
  • There are no validation rules on the custom object.
  • There are no relationship fields on the custom object
  • Sharing rules on the object are public R/W
  • The Controller is not using "with sharing" modifier
The only thing I can think of at this point is that it has something to do with the org being a Free Edition, or the fact that its in the sandbox.
Here is my controller, but I dont think its the problem.
public class LandingPageController {
		
	private String pid;
	
	public Landing_Page__c page {get; private set;}
	public String errormsg {get; private set;}
	private PageReference pageRef = ApexPages.currentPage();
	private Map<String, String> headers = pageRef.getHeaders();
	private Map<String, String> getParams =PageRef.getParameters();		
    
    public LandingPageController() {
        
        pid = getParams.get('pid');
                
        if(pid != null) {
	        page = [SELECT Id, Name FROM Landing_Page__c WHERE LPN__c = :pid];
        }
        
        if(page == null) {
        	errormsg = 'No page returned!';
        } else {
        	        	
        	Hit__c hit = new Hit__c();
				
			hit.IP_Address__c = headers.get('True-Client-IP');
			hit.LPN__c = getParams.get('pid');
			hit.Timestamp__c = System.now();
			
			insert hit; // <- THIS IS THE PROBLEM   
			   	
        }        

        
    }

}

 

Any ideas?  Thanks in advance.
Also, thanks to my Tweeps for helping me to try to troubleshoot this yesterday!

 

Hi,

I have a component and a componentcontroller.

I am calculating a value in controller and using the value in component.

 

Page has a command button:

<apex:commandButton action="{!calculateSelectedIdNamePairs}" onClick="initMe();"
            value="Button" reRender="initDownload" />

 

and a div that contains script

 

<div id="initDownload">
 <script>       
       // some javascript that opens an applet with parameters

       function initMe()

       {

            var popup = window.open("AppletPage?selectedIdNamePairs={!selectedIdNamePairs}", "downloadManager", "width=610,height=410");

       }
 </script>
  </div>

 

But when i inspect the page i saw that, it is trying to open a page "AppletPage?selectedIdNamePairs=" So selectedIdNamePairs is blank. I checked the component controller using System.debugs and it is returning values correctly.

 

I am not sure this code is updating the page partially to use my selectedIdNamePairs value in onClick or onComplete.

 

How can I achieve this?

 

Thanks,

John

I am attempting to write a trigger to add contacts that meet the qualifications, to a campaign as a campaign member.  I keep getting an error that I cannot seem to fix that says "AND operator can only be applied to Boolean expressions".  The line of code presenting the error is:

 

 

       if (account.RecordTypeId = '012800000007aDe' && contact.Email_Opt_In__c = 'true' && contact.CampaignMember.CampaignID != '70180000000jlhi' ) 

 

 

The rest of the code is posted below.  I appreciate any recommendations or explanations of this error.  Thanks!

 

 

trigger triggerContactCreateCampMember on Contact (after insert, after update) {

   List<CampaignMember> CampaignMember = new List<CampaignMember>();
   List<Contact> ContactsToAdd = new List<Contact>();
	
    Set<Id> conIds = new Set<Id>();
	 if(Trigger.isInsert || Trigger.isUpdate)
    //Store Contact ID
    for(Contact contact: Trigger.new)
    {
       if (account.RecordTypeId = '012800000007aDe' && contact.Email_Opt_In__c = 'true' && contact.CampaignMember.CampaignID != '70180000000jlhi' ) 
       conIds.add(contact.ID);
    }
		List<Contact> c = new List<Contact> ([SELECT c.Id,c.AccountId From Contact c
		WHERE Id IN :conIds]);

		for (Contact con : c) {

	if(conIds.size() > 0)
	
	{CampaignMember.add(new CampaignMember
		(      
                
                ContactId = c.Id,
                CampaignId = '70180000000jlhi'));

             
              insert CampaignMember;
        }
        }
}

 

 

Hi,

 

         All My test classes average  code coverage is 84%, But i am always getting Average test coverage across all Apex Classes and Triggers is 73%, at least 75% test coverage is required error while deploying into Production.

What Might be the Problem with this.

 

 

Thanks

 

Mahesh....

I'm currently trying to add this Apex class:
public with sharing class FileUploadController {
	
	public Document document {
		get {
			if (document == null)
			document = new Document(); 
			return document;
		}
		set;
	}
	public PageReference upload() {
		document.AuthorId = UserInfo.getUserId();
		document.FolderId = UserInfo.getUserId(); // put it in running user's folder
		
		try {
			insert document;
			}catch (DMLException e) {
				ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file'));
				return null;
			}finally {
				document.body = null; // clears the viewstate 
				document = new Document(); 
			}
			ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'File uploaded successfully')); 
			return null;
	}
}

 

 

When I try to test the class, it will say that it's skipped 17 of the 27 lines. I'm obviously a little new to this. What could I have done wrong?

I'm trying to create an upload button based on this helpful tool here: http://developer.force.com/cookbook/recipe/uploading-a-document-using-visualforce-and-a-custom-controller
What I hope to do in the end is add an upload button on a "contacts'" page.
Again, any help would be greatly appreciated.

I'm very new at this so bear with me.

I'm creating a Visualforce page that shows data in a table.  Not in the traditional apex:table sense, but rather one field per cell.

How do I get just the value in the cell?  I don't want the field label (apex:outputfield isn't working).  I've tried the cheat sheet and the component library and nothing looks like it'll get me what I need.  What am I missing?

Thanks,

Amber

I'm not sure what I'm missing on this code.  Any suggestions? Thanks in advance for your assistance. 

 

I keep getting this error (Save error: Non-void method might not return a value or might have statement after a return statement. ) on the update opptysToUpdate; line the end of this method:

 

public with sharing class CurrentPumpASP {

	Date currentDate = date.today();
 	Integer currentYearDate = currentDate.year();
	String currentYear = String.valueof(currentYearDate);

 Opportunity writePumpASP(){
	
	List<Opportunity> opptysToUpdate = [SELECT o.id, o.name, o.ASP__c, o.Product_Product_Group__c,
			        o.Account.Primary_GPO__c
				FROM Opportunity o
				WHERE o.Type = 'MMS' 
				AND o.ASP__c = NULL];
				
	  for(Opportunity pumpOpptys : opptysToUpdate ){
					
				pumpOpptys.ASP__c = [SELECT Year__c, Pump_ASP__c, Primary_GPO__c, DTS_Pump_Type__c, CreatedDate 
						   	 			 FROM PumpASP__c 
							 			 WHERE Year__c = :currentYear 
							 			 AND DTS_Pump_Type__c = : pumpOpptys.Product_Product_Group__c
							 			 AND Primary_GPO__c = : pumpOpptys.Account.Primary_GPO__c].Pump_ASP__c;
				opptysToUpdate.add(pumpOpptys);
				}
				
		if(!opptysToUpdate.isEmpty()){		
		update opptysToUpdate;
		}
	 }
  }	

 

 Description Resource Path Location Type

I would like to tweak the apex class in the link below to only count activities with a type of "Call". How can I do that?

 

Link: http://www.radialweb.com/2010/08/summarizing_salesforce_fields_with_triggers/#comments

I created a new apex trigger in Account object.

    The trigger checks the Account's OwnerId is Active or not.
    If active then It will go to before insert & after insert events as per the below trigger code.
    
    Once I check with active users ITs worked fine . but,
    
    I created a new csv file called Account.csv consists 250 Active User's records and 250 Inactive user's records.
    
    So Once I ran via data loader, I am getting 3 debug log files.
    
    The every debug logs shows the 2 time of before insert operation and 2 times of after insert operation.
    
    Why It happened?
    
    Anything I missed in the code?

trigger AccountTrigger on Account (before insert, before update, after insert, after update) {

    if(Trigger.IsInsert) {
        List<Account> AccountList = new List<Account>();
        Map<Id,List<Account>> AccountListMap = new Map<Id,List<Account>>();
        Map<Id, Boolean> UsersActiveMap = new Map<Id, Boolean>();
        
        for(Account AccountNew : Trigger.New) {
        	List<Account> ListAccount = AccountListMap.get(AccountNew.OwnerId);
        	if(ListAccount == null) {
        		ListAccount = new List<Account>();
        		AccountListMap.put(AccountNew.OwnerId, ListAccount);
        	}
        	ListAccount.add(AccountNew);
        }
        system.debug('AccountListMap Values '+ AccountListMap);
        system.debug('AccountListMap SIZE Values '+ AccountListMap.size());
        
        List<User> UserList = [SELECT Id, name, Username, IsActive FROM user WHERE Id IN : AccountListMap.Keyset()];
        for(User Users : UserList) {
            UsersActiveMap.put(Users.Id, Users.IsActive);
        }
        system.debug('UsersActiveMap Values '+ UsersActiveMap);
        
        for(Id OwnerId : AccountListMap.Keyset()) {
        	if(UsersActiveMap.get(OwnerId)) {
        		AccountList.addall(AccountListMap.get(OwnerId));
            	system.debug('AccountList' + AccountList.size());	
            } 
                
        }
        system.debug('AccountList Values '+ AccountList);
        
        if(Trigger.IsBefore) {
        	system.debug('SSS AccountList Size() BEFORE INSERT ' + AccountList.size());
        	AccountTriggerClass.UpdateCallFrequency(AccountList);
        }

        if(Trigger.IsAfter) {
        	system.debug('SSS AccountList Size() AFTER INSERT ' + AccountList.size());
            AccountTriggerClass.CreateTaskOnAccount(AccountList, false);            
        }
    }

    if(Trigger.IsUpdate) {
    
       if(Trigger.IsBefore) {
            Map<Id, Account> AccountMapNew = new Map<Id, Account>();
            Map<Id, string> AccountMapOld = new Map<Id, string>();
            
            //List<Account> AccountList = new List<Account>();
	        Map<Id,List<Account>> AccountListMap = new Map<Id,List<Account>>();
	        Map<Id, Boolean> UsersActiveMap = new Map<Id, Boolean>();
	        
	        for(Account AccountNew : Trigger.New) {
	        	List<Account> ListAccount = AccountListMap.get(AccountNew.OwnerId);
	        	if(ListAccount == null) {
	        		ListAccount = new List<Account>();
	        		AccountListMap.put(AccountNew.OwnerId, ListAccount);
	        	}
	        	ListAccount.add(AccountNew);
	        }
	        system.debug('AccountListMap Values '+ AccountListMap);
        	system.debug('AccountListMap SIZE Values '+ AccountListMap.size());
        
        	List<User> UserList = [SELECT Id, name, Username, IsActive FROM user WHERE Id IN : AccountListMap.Keyset()];
	        for(User Users : UserList) {
	            UsersActiveMap.put(Users.Id, Users.IsActive);
	        }
	        system.debug('UsersActiveMap Values '+ UsersActiveMap);
        
	        for(Id OwnerId : AccountListMap.Keyset()) {
	        	if(UsersActiveMap.get(OwnerId)) {
	        		List<Account> AccList = new List<Account>();
	        		AccList = AccountListMap.get(OwnerId);
	        		for(Account Acc : AccList) {
	        			AccountMapNew.put(Acc.Id, Acc);
	        		}
	            } 
	        }
        	system.debug('AccountMapNew Values '+ AccountMapNew);
        
            for(Account AccountOld : Trigger.Old) {
                AccountMapOld.put(AccountOld.id, AccountOld.Name);
            }
			system.debug('AccountMapOld Values '+ AccountMapOld);
			
            AccountTriggerClass.UpdateAccount(AccountMapNew, AccountMapOld);
       }
         
       if(Trigger.IsAfter) {
            List<Account> AccountsMarkedDeleted = new List<Account>();
            Map<Id, Account> OldAccountMap = new Map<Id, Account>();
            Map<Id, Account> NewAccountMap = new Map<Id, Account>();            
            
            //List<Account> AccountList = new List<Account>();
	        Map<Id,List<Account>> AccountListMap = new Map<Id,List<Account>>();
	        Map<Id, Boolean> UsersActiveMap = new Map<Id, Boolean>();
	        
	        for(Account AccountNew : Trigger.New) {
	        	List<Account> ListAccount = AccountListMap.get(AccountNew.OwnerId);
	        	if(ListAccount == null) {
	        		ListAccount = new List<Account>();
	        		AccountListMap.put(AccountNew.OwnerId, ListAccount);
	        	}
	        	ListAccount.add(AccountNew);
	        }
	        system.debug('AccountListMap Values '+ AccountListMap);
        	system.debug('AccountListMap SIZE Values '+ AccountListMap.size());
        
        	List<User> UserList = [SELECT Id, name, Username, IsActive FROM user WHERE Id IN : AccountListMap.Keyset()];
	        for(User Users : UserList) {
	            UsersActiveMap.put(Users.Id, Users.IsActive);
	        }
	        system.debug('UsersActiveMap Values '+ UsersActiveMap);
        	
        	for(Account AccountOld : Trigger.Old) {
                OldAccountMap.put(AccountOld.Id, AccountOld);
            }
            system.debug('OldAccountMap Values '+ OldAccountMap);
            
            for(Id OwnerId : AccountListMap.Keyset()) {
	        	if(UsersActiveMap.get(OwnerId)) {
	        		List<Account> AccList = new List<Account>();
	        		AccList = AccountListMap.get(OwnerId);
	        		for(Account Acc : AccList) {
	        			//AccountMapNew.put(Acc.Id, Acc);
	        			if(!Acc.Active_Dealer__c)
                    		AccountsMarkedDeleted.add(Acc); 
                		else {
                    		//if(UsersActiveMap.get(AccountNew.OwnerId))
                        	NewAccountMap.put(Acc.Id, Acc);                                                       
                		}
	        		}
	            } 
	        }
        	system.debug('AccountsMarkedDeleted Values '+ AccountsMarkedDeleted);
        	system.debug('NewAccountMap Values '+ NewAccountMap);
            
            AccountTriggerClass.UpdateContactForActiveDealers(AccountsMarkedDeleted);
            AccountTriggerClass.UpdateTaskOnAccount(NewAccountMap, OldAccountMap);
       } 
    }
}

 

I've got a visualforce page rendering as a PDF that is pulling in some contact details from a junction object, including Email address.

 

It looks like this:

 

screen capture

 

I'd like to strip the formatting of the text - no hyperlink, no 'Gmail' text.

 

My code looks like this:

 

          <apex:column >

              <apex:facet name="header">Email</apex:facet>
              <apex:outputField value="{!c.role.Contact_Name__r.Email}" />

          </apex:column>

 

 

Any tips?

Hi,

 

      I have an Object called Event. In that, we have a field called "Navigation Link" which is used to store the URL Address.

For this field, i used Text field. Based on this, we developed a Page showing the details from the Object. In that page,there we need to give a link for image. when clicking on that image, the result is to open the corresponding url page.

 

      In my page design, i used <apex:repeat> to display the contents of the Object based on the Date by select Query.

 

     Actually, all the details are coming except the link details. Hyperlink is working. But, when we click on it, an blank page is opening.

   

    Friends, pls help me to solve this, how to provide url dynamically in VF Pages.

 

Regards,

Phanikumar

Hi,

I have Created a Radio Button with options 'YES' & 'NO' .   and created a Multi select picklist field below.

Now my requirement is
1. In Radio button, If YES is selected then picklist values on below has to be enable and give choice to select from the  multi picklist
2. In radio Button, If NO is selected then Picklist values has to be disable. 

Can any one help me to do this functionality. If so it would be helpfull to me.

Thanks,
Suresh Goud

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

 I have a save button in Vf page and when the reRender tag is given the button doesnt seem to work. It would nt perform the save operation. When i remove the reRender tag it works fine.

 

I want a pageblock to be rerendered after the record is saved.

 

Any ideas?

  • September 28, 2011
  • Like
  • 0

I need to write a SOQL query that returns opportunities based on the Stage field. I could do that easily, however, it's not the name or label of the picklist value I need to filter, it's the type. The Stage field could have many different values, some of which have a Type 'Closed/Won' and I want to return opportunities with a stage of type 'Closed/Won', how would I write a Where clause for that?

I am working on a visualforce list where I have rendered a list of records and will be changing status field and updating the actual records that have changed. Below is the wrapper class I have thus far.

public class wrapperUpdateClass {

    public wrapperUpdateClass(ApexPages.StandardController controller) {

    }

    //Our collection of the class/wrapper objects cmList
    public List<cCampaignMemberStatus> cmList {get; set;}
    
    //This method uses a simple SOQL query to return a List of CampaignMembers
    public List<cCampaignMemberStatus> getCampaignMemberStatus(){
        if(cmList == null) {
           cmList = new list<cCampaignMemberStatus>();
           for(CampaignMemberStatus cm : [select id, Label from
               CampaignMemberStatus limit 10]) {
                   cmlist.add(new cCampaignMemberStatus(cm));
               }
        }
        return cmList;
    }

    public PageReference UpdateAll() {
    List<CampaignMember> campmem = new List<CampaignMember>();
    
   // for(CampaignMember    
    
    return null;
    }
    
    // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances 
    // are collections of other objects, will contain the standard CampaignMember object
    public class cCampaignMemberStatus {
        public CampaignMemberStatus ccm {get; set;}
        
    //This is the constructor method. When we create a new cCampaignMember object we pass a CampaignMemberthat is set to the ccm property.

        public cCampaignMemberStatus (CampaignMemberStatus cm) {
            ccm = cm;
    }
    }


}

 Here is the code for the button i have thus far:

    public PageReference UpdateAll() {
    List<CampaignMember> campmem = new List<CampaignMember>();
    
 
    
    return null;
    }

 

Based on the wrapper class example (http://wiki.developerforce.com/index.php/Wrapper_Class) I need to write a for loop to capture all of the records where I have changed the campaignmemberstatus. i cannot figure that out. How doi I complete the page reference for UpdateAll?

 

Thank you,

ckellie

  • September 27, 2011
  • Like
  • 0

Hey all,

I feel dumb even posting this, becuase I'm sure it's just a typo or some goofy thing, but I feel like I've wasted enough time tracking it down. Time to let the big guns help me out ;)

 

Pretty simple thing. I have a pageBlockTable. One of the links in it, lets me delete that row. After the row is deleted the table should be rerendered so you can see that it has been removed. Currently the record DOES get deleted, but the table is not rerendered. I tried putting it in an output panel and no luck there. I was wondering if maybe the table is reloading before the record is actually deleteed, causing a 'race' condition type of situation? Anyway, below is the code. Feel free to point out what I am doing wrong, and then laugh at me for being such a newb :P

Page (unneccary crap removed)

<apex:form id="form">
    <apex:actionFunction action="{!deleteFile}" name="removeAttachment" reRender="attachmentsTable" status="working" >
        <apex:param name="aId" value="" />
    </apex:actionFunction>
	
    <apex:actionstatus id="working">
		Deleting....
	</apex:actionstatus>
    
    
        <apex:pageBlock title="Existing Attachments" rendered="{!showExisting}" id="attachmentsTable">
            <apex:pageBlockTable value="{!attachments}" var="attachment">
                <apex:column headerValue="Action">
                    <apex:outputLink value="{!URLFOR($Action.Attachment.Download, attachment.Id)}" target="_blank">View</apex:outputLink>
                    |
                    <apex:outputText> <a id="{!attachment.id}" class="deleteLink">Del</a> </apex:outputText>
                </apex:column>
                <apex:column value="{!attachment.Name}"/>
                <apex:column value="{!attachment.Description}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
 
</apex:form>

 controller

 

   public static void deleteFile()
    {
        string attachmentId = Apexpages.currentPage().getParameters().get('aId');
        Attachment thisAttachment = new Attachment(id=attachmentId);
        delete thisAttachment;        
    }

 

I have custom objects that I'm rendering in a vf page using a custom controller. I'm making tentative steps towards a wrapper class as I've found that nothing else is going to work.

 

I'm trying to render all the 'content' objects that are details of 'content_item' objects, that are referenced in the 'page_layout object ... via a page_element object - which is a detail of page_layout and a child of content_item.  I've seperately proven the SOQL to give the required set of content records.

 

Here's my class and getter:

 

// Wrapper Class for contents
    public list<cWrapper> contents {get;set;}
    
    public class cWrapper {
        public list<Content__c> content {get;set;}
        // constructor method    
        public cWrapper(list<Content__c> c) {
            content = c;
        }
    }
// End Wrapper
    
    public list<cWrapper> getContents() {
        String pgId = ValidatePageName();
        contents = new list<cWrapper>();    // Initialise wrapper class variable

        for (Content_Item__c c: [select Id,
            (select Name, Content_Item__c, URL_Link__c, Image__c, Description_Text__c from Contents__r order by name)
            From Content_Item__c
            where Id in (Select Content_Item__c From Page_Element__c where Page_Layout__c = :pgId)
            order by Release_Date__c desc]) {
            // Add each set of contents records to the wrapper class variable
            contents.add(new cWrapper(c.contents__r));
            
        }
        return contents;
    }


But the problem is that I can't seem to access any of the results in the vf page.

 

<apex:repeat var="c" value="{!contents}" >

    {!c.content.Content_Item_c}

</apex:repeat>

 

gives

Save error: Unknown property 'VisualforceArrayList.Content_Item__c'

 

and

 

{!contents[0].content.Content_Item__c}

 

renders as a blank on the vf page.

 

Any suggestions as to what I'm doing wrong?

 

Hi,

 

Want to create an apex trigger that when an opportunity is saved it overwrites what a user has entered and puts the account name + a custom field. Can anyone help or give suggestions. Can this be applied to only certain opportunity types?

  • March 28, 2011
  • Like
  • 0

Hi folks,

      I have a small trigger and my test class is not giving coverage for me to deploy to prod.

 

Trigger:

 

trigger UserLead on Lead (after insert)
{
Campaign C = [Select Id,Name from Campaign where Name = 'Campaign' limit 1];
List<CampaignMember> CM = new List<CampaignMember>();
for(Lead L : Trigger.New)
{
    if(L.ConnectionReceivedId != null)
    {
        CampaignMember Cmp = new CampaignMember();
        Cmp.LeadId = L.Id;
        Cmp.CampaignId = C.Id;
        Cmp.Status = 'Sent';
        CM.add(Cmp);
    }
}
    
    insert CM;
}

 

 

Test Class:

 

@isTest
private class UserRegion {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
         List<CampaignMember> CM = new List<CampaignMember>();

 

Campaign c = new Campaign(Name = 'Universal', Campaign_Objective__c = 'Marketing', Type = 'Blog', StartDate =  Date.newInstance(2010,02,01),EndDate = Date.newInstance(2011,02,01), Status = 'New');
 insert c;
 Lead l1 = new Lead (LeadType__c = 'New', Company = 'xyz', Status = 'New', Region__c = 'CAN', LastName = 'mytest');
 insert l1;
 CampaignMember cmp = new CampaignMember( CampaignId = c.Id, LeadId = l1.Id, Status = 'Sent');
  insert cmp;
    
    }
}

 

when i run this test class, the below part is not covered and it only gives me 50%

 

        CampaignMember Cmp = new CampaignMember();
        Cmp.LeadId = L.Id;
        Cmp.CampaignId = C.Id;
        Cmp.Status = 'Sent';
        CM.add(Cmp);

 

Any help is most Appreciated.

 

TIA!