• woodmanzee
  • NEWBIE
  • 0 Points
  • Member since 2011
  • GitHub

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 21
    Questions
  • 15
    Replies
I have a custom button that currently checks the value in a field on a custom object and either displays a javascript alert if the field isn't what we want or redirects to a new page if the field is valid. I'd rather do it within salesforce rather than with an alert box - is there a way to add an Apex Error message at the top of the page? Or a smiliar method?

In my visualforce page, I'm using javascript to connect to an external server and need to play back audio coming from the server. The problem is that when I try to play back sound through the audio channel, salesforce already has control of that channel and I can't play sounds through it. Has anyone run into this or have any suggestions? It seems like whichever calls access to the audio gets it first, and salesforce does that (not sure why they need it) before I can run my code.

 

I logged a case with support, but their oh so helpful india call centers took a week and said they didn't know. Suggesions? 

I'm running this code in a schedulable class and expecting it to return at least 50. I had it filtering by a RecordTYpeId, but took it out to just query all contacts and am still only getting one contact returned. Any explanation for why or have any suggestions? Here is the code in question:

 

public void execute(SchedulableContext SC) {
        Date today = date.today();
        Integer numberDays = date.daysInMonth(today.year(), today.month());
        
        Id careProvider = [SELECT Id FROM RecordType WHERE Name = 'Care Provider'].Id;
        
        if (today.day() == 2 || today.day() == (numberDays-1)) {
            System.debug('Update scheduled.');
            // get all care providers
            List<Contact> careproviders = [SELECT Name, RecordTypeId, Email_Trigger__c FROM Contact];
            
            System.debug('Contact list size: ' + careproviders.size());                                  
            List<Contact> updateList = new List<Contact>();
            for (Contact c : careproviders) {
                System.debug('Added new care provider to update list.');
                c.Email_Trigger__c = true;
                updateList.add(c);
            }
            System.debug('Size of list to be updated: ' + updateList.size());
            update updateList;
            System.debug('Update List: ' + updateList);
        }
    }    

 

Thanks!

Don't know what the issue is, i've checked other sources and everything looks like it should be just fine but my code is throwing an exception rather than sending the email. I've kind of reached my limit and can't figure it out. 

 

public PageReference Send() {
    
        List<Opportunity> opps = [SELECT Id, Name, Client_Name__c, Responsible_Party__c, Email_for_Survey__c, First_Name_of_Survey_Recipient__c FROM Opportunity WHERE Id =: ApexPages.currentPage().getParameters().get('id')];
        Opportunity opp = opps[0];

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 

        EmailTemplate et = [SELECT id, Name FROM EmailTemplate WHERE Name = 'HH Survey Invitation'];
        mail.setTemplateID(et.Id);
        
        String[] toAddresses = new String[] {email};
        mail.setToAddresses(toAddresses);
        
        mail.setSaveAsActivity(false);
        mail.setTargetObjectId(opp.Id);
 
        try {
            //mail.setWhatId(opp.Id);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
            //createLog(opp.Id);
        } catch(Exception e) {
            error = toAddresses[0] + ' ' + et.Name + ' ' + opp.Name;
            return null;
        }
        
        PageReference detail = new PageReference('/' + opp.Id);
        detail.setRedirect(true);
        return detail;
        
    }

 

I know the template is valid, the opportunity is valid, and so is the email address. Anything I'm missing? Thanks in advance

So I am trying to call a simple string method to remove a specified set of characters from an existing string, and I keep getting an error message that says: 

 

Error: Compile Error: Method does not exist or incorrect signature: [String].remove(String) at line 10 column 30

 

So my code is fairly simple so far, all I have is this

trigger updateTextEmail on Contact (before insert, before update) {

    List<String> contactNames = new List<String>{};

    for(Contact c: Trigger.new){

        if (c.MobilePhone != '') {
            
           String phone = c.MobilePhone;
           String numPhone = phone.remove('()- ');
            
        }

    }

}

 

So why doesn't the remove method work? I have copied and pasted the method example straight from the documentation, and even that throws an error. Is there something I have to import/include? 

 

Thanks in advance

So I've written a Visualforce page that acts as a to-do list, but currently it serves as one to-do list for the entire company that is using the salesforce instance. I want to make it so that each user that logs in has their own to-do list that is only visible to them, AS WELL as having one to-do list for the company. 

 

What would be the best way to do this? Any ideas or examples would be useful. Thanks in advance

So I know that Salesforce creates a standard controller for custom objects, and I'm trying to use that to make a visualforce page to display all of the custom object records of that type. Problem is, I can't figure out how to display or get the records since Salesforce has NO documentation showing what methods I can use for the custom object. 

 

For example, I have:

 

<apex:page standardController="Custom_Item__c">
      
        <apex:form>
            <apex:pageBlock >
                <div id="itemListing">
                    
                    <apex:repeat value="{!Custom_Item__c}" var="item" id="itemList">
                        {!item.Name}
                    </apex:repeat>
                  
                </div>
            </apex:pageBlock>
        </apex:form>
  
</apex:page>

 

But this doesn't return anything when I look at the VF page. Any help?
Does anybody know what methods I can call for the custom object? I just don't know how to access any of the records.

Thanks 

I need to write an apex trigger that takes information from some of the Contact fields and uses them to generate a value for a custom field. 

 

For example, say I have a custom field called "Area Code." When I create a new contact, after filling out the Mobile field and click save, the trigger should fire and (using apex code i would write) populate the Area Code field with the first three numbers from the Mobile field. 

 

The problem is that the triggers I write don't seem to fire correctly - when the record is saved, nothing happens, or I have to edit the Mobile field and save it again in order for the trigger to work. I don't really need to know how to make an area code field, but I do need to do something similar. How can I make a trigger that fires correctly when a record is created or edited?

I'm trying to query information from a pre-made report  but having issues. I need to get a specific folder (already figured out) and then cycle through the reports in that folder (also figured out) and then be able to get all of the contacts listed in each individual report. Is there a way to query that info? Or get it any other way?

So I have a visualforce page that displays something like this (very generalized)

 

<apex:repeat>// repeats the "Item" Object

<apex:repeat>// repeats the "Activity" Object, a child of "Item"

</apex:repeat>

<apex:pageBlock>

<apex:pageBlockButtons>

<apex:commandButton action="{!newActivity}">

<apex:param name="ItemId" value="{!item.id}"/>

</apex:commandButton>

</apex:pageBlockButtons>

<apex:pageBlockSection>

<apex:inputField value="{!activity.Name}">

<apex:inputField value="{!activity.Date}">

</apex:pageBlockSection>

<apex:pageBlock>

</apex:repeat>

 

All the syntax is right, the page shows fine, but the problem is when I try to create a new Activity, it only works on the first iteration of the repeat. I.E., if I try to create an activity for Item 1, it works fine, but on any other Item it creates a record as if nothing was entered in the inputField. Any ideas why this is? How can I get it to save the correct values on every iteration? 

 

 

So I have a visualforce page that kind of displays a to do list, and I have two objects - Items and Activities. Activities are the children of the Items, and have a few custom fields. I want to display all the existing items and their activities and then be able to create new items or activities on each item. I can't figure out how to create activities for the specific Item they're under... any help would be nice. Here's my code: 

 

Visualforce Page:

<body>
    <div id="pageBlock" class="container_12">
        <div id="Header">
            <div class="grid_12">
                <p id="title">Whiteboard</p>
                <p id="newWBItem">New Whiteboard Item</p>
            </div>
            <apex:form >
                <apex:pageBlock >
                      <apex:pageBlockButtons location="bottom" styleClass="save_button">
                          <apex:commandButton action="{!save}" value="Save" rerender="Items"/>
                      </apex:pageBlockButtons>
                      <apex:pageBlockSection showHeader="false" id="wb_item_input">
                          <apex:inputField value="{!wbitem.Name}"/>
                      </apex:pageBlockSection>
                  </apex:pageBlock>
            </apex:form>
        </div>
        <div id="Items">
        <apex:form >
        <apex:pageBlock >
            <div id="itemSpec" class="container_12">
            <apex:repeat value="{!whiteboard}" var="item" id="itemList">
                <div id="ItemHeading">
                    <div class="grid_8">
                        <apex:outputText value="{!item.Name}" id="itemName"/><br/>
                    </div>
                    <div class="grid_3">
                        <apex:commandLink value="New Activity" id="newAct"/>   |   
                        <apex:commandLink action="{!deleteItem}" value="Delete Item" id="theCommandLink">
                            <apex:param name="ItemId" value="{!item.Id}"/>
                        </apex:commandLink>
                    </div>
                </div>
                <apex:repeat value="{!item.Whiteboard_Item_Activities__r}" var="act" id="actList">
                    <div id="Item Activities">
                        <div class="grid_9">
                             <apex:outputText value="{!act.Name}" id="actSub"/><br/>
                        </div>
                        <div class="grid_3">
                            <apex:outputText value="{!act.Due_Date__c}" id="actDue"/><br/>
                        </div>
                        <div class="grid_9">
                            <apex:outputText value="{!act.Activity_Description__c}" id="actDes"/><br/>
                        </div>
                    </div>
                </apex:repeat>
                <div class="grid_12">
                <apex:pageBlock >
                      <apex:pageBlockButtons location="bottom" styleClass="save_button_act">
                          <apex:commandButton action="{!newAct}" value="Save" rerender="Items">
                              <apex:param name="ItemId" value="{!item.Id}"/>
                          </apex:commandButton>
                      </apex:pageBlockButtons>
                      <apex:pageBlockSection showHeader="false" id="wb_item_act_input">
                          <apex:inputField value="{!wbitemAct.Name}"/>
                          <apex:inputField value="{!wbitemAct.Due_Date__c}"/>
                          <apex:inputField value="{!wbitemAct.Activity_Description__c}"/>
                      </apex:pageBlockSection>
                </apex:pageBlock>
                </div>
            </apex:repeat>
            </div>
        </apex:pageBlock>
        </apex:form>
        </div>
    </div>
</body>

 

 

Controller:

public class WhiteboardCtrl {

    private List<Whiteboard_Item__c> wboard {get; private set;}

    public WhiteboardCtrl() {
        wboard = [SELECT Name, Id,
                     (SELECT Name, Due_Date__c, Activity_Description__c
                      FROM Whiteboard_Item_Activities__r ORDER BY CreatedDate)
                  FROM Whiteboard_Item__c 
                  ORDER BY CreatedDate];
    }
    
    public Whiteboard_Item__c wbitem {
        get{
            if (wbitem == null)
                wbitem = new Whiteboard_Item__c();
            return wbitem;
        }
        set;
    }
    
    public Whiteboard_Item_Activity__c wbitemAct {
        get{
            if (wbitemAct == null)
                wbitemAct = new Whiteboard_Item_Activity__c();
                
            return wbitemAct;
        }
        set;
    }
    
    public PageReference deleteItem() {
        Whiteboard_Item__c goner = [SELECT id, name from Whiteboard_Item__c where id = :ApexPages.currentpage().getparameters().get('ItemId')];
        
        try {
            delete goner;
        } catch (DmlException e) {
        }
        PageReference curPage = ApexPages.currentPage();
        curPage.setRedirect(true);
        return null;
    }
    
    public Whiteboard_Item__c[] getWhiteboard() {
        return wboard;
    }

    public PageReference save() {
        try {
            insert wbitem;
        } catch(DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
      return null;
    }

    public PageReference newAct() {
    
       Whiteboard_Item__c item = [SELECT Name, Id,
                     (SELECT Name, Due_Date__c, Activity_Description__c
                      FROM Whiteboard_Item_Activities__r ORDER BY CreatedDate)
                  FROM Whiteboard_Item__c 
                  WHERE id = :ApexPages.currentpage().getparameters().get('ItemId')
                  ORDER BY CreatedDate];
                  
        List <Whiteboard_Item_Activity__c> acts = item.Whiteboard_Item_Activities__r;
        acts.add(wbitemAct);
        try{upsert item;} catch(DMLException e) {ApexPages.addMessages(e); return null;}
        return null;

    }

}

 

I just cant figure out how to save the Activities to the right item, at least when I try to do it nothing shows up on the refresh. Maybe I'm just not showing the values correctly? Not sure. Thanks in advance

I'm trying to total Referrals given for each Contact in my organization, and I'm coming up with a problem. Theres a field in my Opportunity that is a lookup to the Contacts to specify who gave the referral, and that's the only place where who the "Referrer" was is stored. I decided to create a field on the Contacts called "Referrals Given" and create a trigger on the Contact to query all the Opportunities to see which have the given Contact Name as the Referrer and then get the size of that list and fill the Referrals Given with that number. However, it's not returning the right value, it always says 0 even though I know there are several Opportunities that have the Contact name I'm testing as the Referrer. My code is this: 

 

trigger getNumReferrals on Contact (before update) {
    for (Contact c : Trigger.new) 
    {
        String nameR = c.Name;
        List<Opportunity> oppList = [SELECT j.Name FROM Opportunity j WHERE j.Referrer__c =: c.Name];
        Integer count = oppList.size();
        
        c.Referrals_Given__c = count;
    }
}

   

 So I need to know what's wrong with the trigger, or is there a better way to do what I'm trying to get done? 

 

Thanks

So I have a "Contact Us" box on a webpage I'm building, and I need to take the inputs and create a lead from them. Does anyone know how to create a lead? I can save all the info but it wont let me fully create the new Lead, I think I have to give it a new ID somehow. 

 

    var updated = [];
                
                    var cform = new sforce.SObject("Lead");
                    cform.Name = n;
                    cform.Company = c;
                    cform.Email = e;
                    cform.Description = r;
                    
                    updated.push(cform);
                    
                    result = sforce.connection.insert(updated);
                    alert(result);

 

so I'm trying to set the cfrom lead object as a new lead and insert it into our salesforce database, but it's not working. I also tried 

 

result = sforce.connection.update(updated);

 

but no go. Any help would be appreciated

I am having a (hopefully easy) problem creating new child objects.  I have a custom object called Product Interest that has a master-detail relationship to Contact.  In my trigger I simply want to create several new Product Interests and add them to the Contact's related list.  However, when I call add on contact.Product_Interests__r, nothing is added (i.e. contact.Product_Interests__r.size() == 0).  Can someone help me understand what is going on?

 

Thanks.  Here is the code for the "test" case I started to write (currenlty it makes no assertions).

static testMethod void CreateContact() {
        
        Contact c = new Contact();
		c.FirstName = 'Cameron';
		c.LastName = 'Woodmansee';
		c.MailingCity = 'Provo';
		c.MailingCountry = 'USA';
		c.MailingPostalCode = '84606';
		c.MailingState = 'UT';
		c.MailingStreet = '541 E 500 N';
		c.Lead_Product_Interest__c = 'ELx50; ELx808; Eon; Epoch';
		insert c;
    }

And here's the trigger code.

trigger CreateProductInterests on Contact (after insert) {

	Contact[] contacts = [
		SELECT Id, Name, Account.Id, Lead_Campaign_Source__c, LeadSource, Lead_Product_Interest__c,
			   Product_Interest_Notes__c, 
			   (SELECT Id, Name FROM Product_Interests__r)
		FROM Contact
		WHERE Id IN :Trigger.new
	];
	
	for(Contact c : contacts) {
		system.debug(c.Product_Interests__r);
		
		if(c.Product_Interests__r.size() == 0) {
			string[] interests = c.Lead_Product_Interest__c.split(';',0);
			
			if(interests.size() == 0)
				break;
				
			for(string interest : interests) {
				Product_Interest__c p = new Product_Interest__c();
				p.Account__c = c.Account.Id;
				p.Campaign__c = (Id) c.Lead_Campaign_Source__c;
				p.Contact__c = c.Id;
				p.Product_Interest_Notes__c = c.Product_Interest_Notes__c;
				p.Product_Interest_Source__c = c.LeadSource;
				p.Contact__c = c.Id;
				try {
					insert p;
					c.Product_Interests__r.add(p);
					system.debug(c.Product_Interests__r.size());
					
				}
				catch(DMLException e) {
					system.debug(e);
				}
			}
			//c.Product_Interests__r = pi;
			
			update c;
		}
		system.debug(c.Product_Interests__r.size());
	}

 Thanks again.

 

So I have a trigger that takes two fields in a contact (one custom and one standard) and combines them to fill out a custom field in the same contact. The problem is, I can't use it because the trigger has to run before/after update/insert and all that. This gives me a recursive call, because once the contact is saved, the trigger tries to update it, which calls the trigger again, and so on. Any way I can fix that? All ideas would be helpful. Thanks!!

Is it possible to create a custom button on the Contact page that checks a checkbox (a custom field)?  I'm having trouble writing some javascript that would accomplish that.  Any help?

I am having a few issues with this trigger I am writing.  I thought it would be pretty simple, but apparently I'm not good enough at apex.  I'm trying to update a custom date field (Last_Campaign_Date__c) in the Contact standard object that holds the date of the most recent campaign they were a member of.  When I run the test, my debug statements say that the date was updated, but my assertion still fails.  I don't really know why it isn't saving.  Anyone have ideas?

 

Trigger Code:

trigger addLastCampaignDateForMembers on Campaign (before insert, before update) {

    // do this for each camapign in the set affected by trigger
    for(Campaign current : Trigger.new) {
    
        // only update contacts in the campaign
        if(current.NumberOfContacts > 0) {
            ID campaign_id = current.Id;
            
            // get all contacts for this campaign
            Contact[] members = [
                select id, firstname, lastname, Last_Campaign_Date__c
                from contact 
                for update
            ];
                
            // update the Last Campaign Date for each contact
            for(Contact c : members) {
                //system.debug(c.Last_Campaign_Date__c);
                c.Last_Campaign_Date__c = current.StartDate;
                //system.debug(c.Last_Campaign_Date__c);
                try {
                    update c;
                    system.debug(current.StartDate);
                    system.debug(c.Last_Campaign_Date__c);
                }
                catch(DMLException e) {
                    system.debug(e);
                }
            }
           
        }
    }
}

And here is my test code:

 

@isTest
private class TestLastCampaignDateUpdate {
    
    static testMethod void testDateChange() {
        Campaign[] campaign = [
            select id, name
            from Campaign
            where parentid = '701S00000009Qkq'
        ];
        
        CampaignMember[] cmembers = [
            select id, contactid, campaignid
            from CampaignMember
            where campaignid in :campaign
        ];
        
        Contact[] members = [
            select id, firstname, lastname, Last_Campaign_Date__c
            from contact 
            where id in (select contactId from campaignMember where campaignId in :campaign)
        ];
        
        system.debug(members[0].lastname);
        
        update campaign;
        system.debug(members[0].Last_Campaign_Date__c);
        system.assert(members[0].Last_Campaign_Date__c != null);
    }

}

 Thanks!

 

 

 

Can you use change sets to move changes from the development edition to a sandbox?  In my development edition under "Deploy" the only option is Monitor Deployments.

I've created a secondary email field for my contacts that I want to use with the Mass Email option (under the Contacts tab) instead of the default email, but seeing as how salesforce doesnt let you edit those sending options it looks like I need to somehow recreate something that will follow the same steps as the mass email. Any ideas/suggestions? Thanks

I am writing a class that sends an email everytime a record is submitted.  I want the email to actually be sent as a text.  I found that texts can be sent from email by sending the message to (the phone #)@maildomain.com (for example, 8012345823@vtext.colm).  

 

However, when I run the code, it shows that it was successful, but the message never arrives.  I tried the same code with a normal email address and it worked fine.  Why would it be that these email to text messagesg don't send?  Thanks.

I have a custom button that currently checks the value in a field on a custom object and either displays a javascript alert if the field isn't what we want or redirects to a new page if the field is valid. I'd rather do it within salesforce rather than with an alert box - is there a way to add an Apex Error message at the top of the page? Or a smiliar method?

In my visualforce page, I'm using javascript to connect to an external server and need to play back audio coming from the server. The problem is that when I try to play back sound through the audio channel, salesforce already has control of that channel and I can't play sounds through it. Has anyone run into this or have any suggestions? It seems like whichever calls access to the audio gets it first, and salesforce does that (not sure why they need it) before I can run my code.

 

I logged a case with support, but their oh so helpful india call centers took a week and said they didn't know. Suggesions? 

I'm running this code in a schedulable class and expecting it to return at least 50. I had it filtering by a RecordTYpeId, but took it out to just query all contacts and am still only getting one contact returned. Any explanation for why or have any suggestions? Here is the code in question:

 

public void execute(SchedulableContext SC) {
        Date today = date.today();
        Integer numberDays = date.daysInMonth(today.year(), today.month());
        
        Id careProvider = [SELECT Id FROM RecordType WHERE Name = 'Care Provider'].Id;
        
        if (today.day() == 2 || today.day() == (numberDays-1)) {
            System.debug('Update scheduled.');
            // get all care providers
            List<Contact> careproviders = [SELECT Name, RecordTypeId, Email_Trigger__c FROM Contact];
            
            System.debug('Contact list size: ' + careproviders.size());                                  
            List<Contact> updateList = new List<Contact>();
            for (Contact c : careproviders) {
                System.debug('Added new care provider to update list.');
                c.Email_Trigger__c = true;
                updateList.add(c);
            }
            System.debug('Size of list to be updated: ' + updateList.size());
            update updateList;
            System.debug('Update List: ' + updateList);
        }
    }    

 

Thanks!

Don't know what the issue is, i've checked other sources and everything looks like it should be just fine but my code is throwing an exception rather than sending the email. I've kind of reached my limit and can't figure it out. 

 

public PageReference Send() {
    
        List<Opportunity> opps = [SELECT Id, Name, Client_Name__c, Responsible_Party__c, Email_for_Survey__c, First_Name_of_Survey_Recipient__c FROM Opportunity WHERE Id =: ApexPages.currentPage().getParameters().get('id')];
        Opportunity opp = opps[0];

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 

        EmailTemplate et = [SELECT id, Name FROM EmailTemplate WHERE Name = 'HH Survey Invitation'];
        mail.setTemplateID(et.Id);
        
        String[] toAddresses = new String[] {email};
        mail.setToAddresses(toAddresses);
        
        mail.setSaveAsActivity(false);
        mail.setTargetObjectId(opp.Id);
 
        try {
            //mail.setWhatId(opp.Id);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
            //createLog(opp.Id);
        } catch(Exception e) {
            error = toAddresses[0] + ' ' + et.Name + ' ' + opp.Name;
            return null;
        }
        
        PageReference detail = new PageReference('/' + opp.Id);
        detail.setRedirect(true);
        return detail;
        
    }

 

I know the template is valid, the opportunity is valid, and so is the email address. Anything I'm missing? Thanks in advance

So I've written a Visualforce page that acts as a to-do list, but currently it serves as one to-do list for the entire company that is using the salesforce instance. I want to make it so that each user that logs in has their own to-do list that is only visible to them, AS WELL as having one to-do list for the company. 

 

What would be the best way to do this? Any ideas or examples would be useful. Thanks in advance

So I know that Salesforce creates a standard controller for custom objects, and I'm trying to use that to make a visualforce page to display all of the custom object records of that type. Problem is, I can't figure out how to display or get the records since Salesforce has NO documentation showing what methods I can use for the custom object. 

 

For example, I have:

 

<apex:page standardController="Custom_Item__c">
      
        <apex:form>
            <apex:pageBlock >
                <div id="itemListing">
                    
                    <apex:repeat value="{!Custom_Item__c}" var="item" id="itemList">
                        {!item.Name}
                    </apex:repeat>
                  
                </div>
            </apex:pageBlock>
        </apex:form>
  
</apex:page>

 

But this doesn't return anything when I look at the VF page. Any help?
Does anybody know what methods I can call for the custom object? I just don't know how to access any of the records.

Thanks 

I need to write an apex trigger that takes information from some of the Contact fields and uses them to generate a value for a custom field. 

 

For example, say I have a custom field called "Area Code." When I create a new contact, after filling out the Mobile field and click save, the trigger should fire and (using apex code i would write) populate the Area Code field with the first three numbers from the Mobile field. 

 

The problem is that the triggers I write don't seem to fire correctly - when the record is saved, nothing happens, or I have to edit the Mobile field and save it again in order for the trigger to work. I don't really need to know how to make an area code field, but I do need to do something similar. How can I make a trigger that fires correctly when a record is created or edited?

So I have a visualforce page that displays something like this (very generalized)

 

<apex:repeat>// repeats the "Item" Object

<apex:repeat>// repeats the "Activity" Object, a child of "Item"

</apex:repeat>

<apex:pageBlock>

<apex:pageBlockButtons>

<apex:commandButton action="{!newActivity}">

<apex:param name="ItemId" value="{!item.id}"/>

</apex:commandButton>

</apex:pageBlockButtons>

<apex:pageBlockSection>

<apex:inputField value="{!activity.Name}">

<apex:inputField value="{!activity.Date}">

</apex:pageBlockSection>

<apex:pageBlock>

</apex:repeat>

 

All the syntax is right, the page shows fine, but the problem is when I try to create a new Activity, it only works on the first iteration of the repeat. I.E., if I try to create an activity for Item 1, it works fine, but on any other Item it creates a record as if nothing was entered in the inputField. Any ideas why this is? How can I get it to save the correct values on every iteration? 

 

 

So I have a visualforce page that kind of displays a to do list, and I have two objects - Items and Activities. Activities are the children of the Items, and have a few custom fields. I want to display all the existing items and their activities and then be able to create new items or activities on each item. I can't figure out how to create activities for the specific Item they're under... any help would be nice. Here's my code: 

 

Visualforce Page:

<body>
    <div id="pageBlock" class="container_12">
        <div id="Header">
            <div class="grid_12">
                <p id="title">Whiteboard</p>
                <p id="newWBItem">New Whiteboard Item</p>
            </div>
            <apex:form >
                <apex:pageBlock >
                      <apex:pageBlockButtons location="bottom" styleClass="save_button">
                          <apex:commandButton action="{!save}" value="Save" rerender="Items"/>
                      </apex:pageBlockButtons>
                      <apex:pageBlockSection showHeader="false" id="wb_item_input">
                          <apex:inputField value="{!wbitem.Name}"/>
                      </apex:pageBlockSection>
                  </apex:pageBlock>
            </apex:form>
        </div>
        <div id="Items">
        <apex:form >
        <apex:pageBlock >
            <div id="itemSpec" class="container_12">
            <apex:repeat value="{!whiteboard}" var="item" id="itemList">
                <div id="ItemHeading">
                    <div class="grid_8">
                        <apex:outputText value="{!item.Name}" id="itemName"/><br/>
                    </div>
                    <div class="grid_3">
                        <apex:commandLink value="New Activity" id="newAct"/>   |   
                        <apex:commandLink action="{!deleteItem}" value="Delete Item" id="theCommandLink">
                            <apex:param name="ItemId" value="{!item.Id}"/>
                        </apex:commandLink>
                    </div>
                </div>
                <apex:repeat value="{!item.Whiteboard_Item_Activities__r}" var="act" id="actList">
                    <div id="Item Activities">
                        <div class="grid_9">
                             <apex:outputText value="{!act.Name}" id="actSub"/><br/>
                        </div>
                        <div class="grid_3">
                            <apex:outputText value="{!act.Due_Date__c}" id="actDue"/><br/>
                        </div>
                        <div class="grid_9">
                            <apex:outputText value="{!act.Activity_Description__c}" id="actDes"/><br/>
                        </div>
                    </div>
                </apex:repeat>
                <div class="grid_12">
                <apex:pageBlock >
                      <apex:pageBlockButtons location="bottom" styleClass="save_button_act">
                          <apex:commandButton action="{!newAct}" value="Save" rerender="Items">
                              <apex:param name="ItemId" value="{!item.Id}"/>
                          </apex:commandButton>
                      </apex:pageBlockButtons>
                      <apex:pageBlockSection showHeader="false" id="wb_item_act_input">
                          <apex:inputField value="{!wbitemAct.Name}"/>
                          <apex:inputField value="{!wbitemAct.Due_Date__c}"/>
                          <apex:inputField value="{!wbitemAct.Activity_Description__c}"/>
                      </apex:pageBlockSection>
                </apex:pageBlock>
                </div>
            </apex:repeat>
            </div>
        </apex:pageBlock>
        </apex:form>
        </div>
    </div>
</body>

 

 

Controller:

public class WhiteboardCtrl {

    private List<Whiteboard_Item__c> wboard {get; private set;}

    public WhiteboardCtrl() {
        wboard = [SELECT Name, Id,
                     (SELECT Name, Due_Date__c, Activity_Description__c
                      FROM Whiteboard_Item_Activities__r ORDER BY CreatedDate)
                  FROM Whiteboard_Item__c 
                  ORDER BY CreatedDate];
    }
    
    public Whiteboard_Item__c wbitem {
        get{
            if (wbitem == null)
                wbitem = new Whiteboard_Item__c();
            return wbitem;
        }
        set;
    }
    
    public Whiteboard_Item_Activity__c wbitemAct {
        get{
            if (wbitemAct == null)
                wbitemAct = new Whiteboard_Item_Activity__c();
                
            return wbitemAct;
        }
        set;
    }
    
    public PageReference deleteItem() {
        Whiteboard_Item__c goner = [SELECT id, name from Whiteboard_Item__c where id = :ApexPages.currentpage().getparameters().get('ItemId')];
        
        try {
            delete goner;
        } catch (DmlException e) {
        }
        PageReference curPage = ApexPages.currentPage();
        curPage.setRedirect(true);
        return null;
    }
    
    public Whiteboard_Item__c[] getWhiteboard() {
        return wboard;
    }

    public PageReference save() {
        try {
            insert wbitem;
        } catch(DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
      return null;
    }

    public PageReference newAct() {
    
       Whiteboard_Item__c item = [SELECT Name, Id,
                     (SELECT Name, Due_Date__c, Activity_Description__c
                      FROM Whiteboard_Item_Activities__r ORDER BY CreatedDate)
                  FROM Whiteboard_Item__c 
                  WHERE id = :ApexPages.currentpage().getparameters().get('ItemId')
                  ORDER BY CreatedDate];
                  
        List <Whiteboard_Item_Activity__c> acts = item.Whiteboard_Item_Activities__r;
        acts.add(wbitemAct);
        try{upsert item;} catch(DMLException e) {ApexPages.addMessages(e); return null;}
        return null;

    }

}

 

I just cant figure out how to save the Activities to the right item, at least when I try to do it nothing shows up on the refresh. Maybe I'm just not showing the values correctly? Not sure. Thanks in advance

So I have a "Contact Us" box on a webpage I'm building, and I need to take the inputs and create a lead from them. Does anyone know how to create a lead? I can save all the info but it wont let me fully create the new Lead, I think I have to give it a new ID somehow. 

 

    var updated = [];
                
                    var cform = new sforce.SObject("Lead");
                    cform.Name = n;
                    cform.Company = c;
                    cform.Email = e;
                    cform.Description = r;
                    
                    updated.push(cform);
                    
                    result = sforce.connection.insert(updated);
                    alert(result);

 

so I'm trying to set the cfrom lead object as a new lead and insert it into our salesforce database, but it's not working. I also tried 

 

result = sforce.connection.update(updated);

 

but no go. Any help would be appreciated

I am having a (hopefully easy) problem creating new child objects.  I have a custom object called Product Interest that has a master-detail relationship to Contact.  In my trigger I simply want to create several new Product Interests and add them to the Contact's related list.  However, when I call add on contact.Product_Interests__r, nothing is added (i.e. contact.Product_Interests__r.size() == 0).  Can someone help me understand what is going on?

 

Thanks.  Here is the code for the "test" case I started to write (currenlty it makes no assertions).

static testMethod void CreateContact() {
        
        Contact c = new Contact();
		c.FirstName = 'Cameron';
		c.LastName = 'Woodmansee';
		c.MailingCity = 'Provo';
		c.MailingCountry = 'USA';
		c.MailingPostalCode = '84606';
		c.MailingState = 'UT';
		c.MailingStreet = '541 E 500 N';
		c.Lead_Product_Interest__c = 'ELx50; ELx808; Eon; Epoch';
		insert c;
    }

And here's the trigger code.

trigger CreateProductInterests on Contact (after insert) {

	Contact[] contacts = [
		SELECT Id, Name, Account.Id, Lead_Campaign_Source__c, LeadSource, Lead_Product_Interest__c,
			   Product_Interest_Notes__c, 
			   (SELECT Id, Name FROM Product_Interests__r)
		FROM Contact
		WHERE Id IN :Trigger.new
	];
	
	for(Contact c : contacts) {
		system.debug(c.Product_Interests__r);
		
		if(c.Product_Interests__r.size() == 0) {
			string[] interests = c.Lead_Product_Interest__c.split(';',0);
			
			if(interests.size() == 0)
				break;
				
			for(string interest : interests) {
				Product_Interest__c p = new Product_Interest__c();
				p.Account__c = c.Account.Id;
				p.Campaign__c = (Id) c.Lead_Campaign_Source__c;
				p.Contact__c = c.Id;
				p.Product_Interest_Notes__c = c.Product_Interest_Notes__c;
				p.Product_Interest_Source__c = c.LeadSource;
				p.Contact__c = c.Id;
				try {
					insert p;
					c.Product_Interests__r.add(p);
					system.debug(c.Product_Interests__r.size());
					
				}
				catch(DMLException e) {
					system.debug(e);
				}
			}
			//c.Product_Interests__r = pi;
			
			update c;
		}
		system.debug(c.Product_Interests__r.size());
	}

 Thanks again.

 

So I'm trying to create a pop up page that lets me generate a table of all the contacts in the system and lets me select which ones I want to perform a certain action, but I can't figure out how to generate the table. When you go to the normal contacts tab and click "go" to view all contacts it generates a neat little table with two buttons for "New Contact" and "Add to Campain." How do they generate that table? I essentially want that same page but to be able to manipulate the buttons to do different things.

 

I at least want to know how to generate that table for a different visualforce page. Any help? Thanks!

Hi,

 

I'm developing apex class to send mass emails from selected records, when i select records and click on send button it show runtime error.

 

I'm getting this error message

 

System.NullPointerException: Attempt to de-reference a null object

Class.wrapperClassController3.send: line 128, column 22 External entry point

 

Wat may be the problem? Please help me to rectify this.

 

Apex Class code:

public class wrapperClassController3 {
public String aMessage {
get; set;
}
public List<ID> studentids;
public List<string> studentList1=new List<string>();
//public String[] studentList1 = new List<String>();
//Our collection of the class/wrapper objects cStudent
public List<cStudent> studentList {get; set;}

//This method uses a simple SOQL query to return a List of Students
public List<cStudent> getStudents(){
if(studentList == null){
studentList = new List<cStudent>();

for(Student__c c : [select Id, First_Name__c,Last_Name__c, Email__c from Student__c limit 10]){

studentList.add(new cStudent(c));
}
}
return studentList;
}

public PageReference processSelected(){
/*We create a new list of Student that we be populated only with Students
if they are selected*/
List<Student__c> selectedStudents = new List<Student__c>();
this.aMessage = '';
/*We will cycle through our list of cStudents and will check to see if the
selected property is set to true, if it is we add the Contact to the
selectedStudentss list. */
for(cStudent cCon : getStudents()){
if(cCon.selected == true){
selectedStudents.add(cCon.con);
}
}

/* Now we have our list of selected contacts and can perform any type of
logic we want, sending emails, updating a field on the Contact, etc */
System.debug('These are the selected Students...');
Integer numselectedStudents = selectedStudents.size();
Integer counter = 0;
System.Debug(selectedStudents);
for(Student__c con : selectedStudents){
counter++;
//system.debug(con);

if(counter==numselectedStudents) {
this.aMessage += con.Id + ','+ con.First_Name__c+',' + con.Email__c;
studentList1.add(con.Id);
} else {
this.aMessage += con.Id + ','+con.First_Name__c+','+ con.Email__c+', ';
}

}
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. In this example a wrapper class contains both the standard salesforce
object Contact and a Boolean value */
public class cStudent
{
public Student__c con {get; set;}
public Boolean selected {get; set;}

/*This is the contructor method. When we create a new cContact object we pass a
Contact that is set to the con property. We also set the selected value to false*/
public cStudent(Student__c c){
con = c;
selected = false;

}
}

// public class mail
//{
// public String subject { get; set; }

// public String body{ get; set; }

public PageReference send()
{

Messaging.MassEmailMessage email = new Messaging.MassEmailMessage();
// String[] toAddresses = new String[] {};
List<String> TargetObjectIds = new List<String>();
//for(String s:studentList1)
//{
// String[] toAddresses = new String[] {s};
// TargetObjectIds.add(s);
//}
// ID s;

for(ID s:studentids)
{
TargetObjectIds.add(s);
}
email.setSubject( 'subject' );

//String[] toMassTargetObjects = new String[]{toMassTargetObjects};
email.setTargetObjectIds(TargetObjectIds);
//email.setPlainTextBody( body );
email.setReplyTo('chiranjeevi@datasisar.com');
email.setSenderDisplayName('Customer Support');
try{
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.MassEmailMessage[] {email});
PageReference Page = new PageReference('/mailinfo');
Page.setRedirect(true);
return Page;
// return null;
}
catch(Exception e)
{
return null;
}




}

//}
}

 

 

 

Visualforce Code.

 

 

<apex:page controller="wrapperClassController3">
<apex:outputPanel id="selected"><b>Selected: {!aMessage}</b></apex:outputPanel>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Process Selected" action="{!processSelected}" rerender="selected"/>
<apex:commandButton value="Send" action="{!send}"/>
</apex:pageBlockButtons>
<!-- In our table we are displaying the cStudent records -->
<apex:pageBlockTable value="{!students}" var="c" id="table">
<apex:column >
<!-- This is our selected Boolean property in our wrapper class -->
<apex:inputCheckbox value="{!c.selected}"/>
</apex:column>
<!-- This is how we access the student values within our cStudent container/wrapper -->
<apex:column value="{!c.con.First_Name__c}" />
<apex:column value="{!c.con.Last_Name__c}" />
<apex:column value="{!c.con.Email__c}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

 

 

 

 

Thank you.

 

 

Message Edited by Coder on 12-19-2009 03:24 AM
Message Edited by Coder on 12-20-2009 08:17 PM
Message Edited by Coder on 12-20-2009 08:22 PM
  • December 19, 2009
  • Like
  • 0