• Ivar
  • NEWBIE
  • 124 Points
  • Member since 2006

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 25
    Questions
  • 41
    Replies

Hi guys,

 

When I use the following piece of code  I get the error "Field expression not allowed for generic SObject". Can you tell me why even after cast the generic sObject to the correct class I get the error? Is there any solution to get properties from a generic sObject after cast it to a specific sObject type (example an Account or Lead)?

 

    public static void setCode(sObject[] objs){

       
        for (sObject o:objs)
        {
            if (o.getSObjectType() == Account.sObjectType)
            {
                o = (Account) o;
            }
            else if (o.getSObjectType() == Lead.sObjectType)
            {
                o = (Lead) o;
            }

 

            tempCode = generateNewCode(o.Name);

            ...

 

 

Thanks in advance.

Hi all.

 

I am faced with a bit of a challenge, and was wondering if anybody had done something similar and could share how they solved it.

 

I have a large set of records of a custom object each of which has a number of image attachments associated with it. I am now being asked to somehow export all those images along with some way to associate them to the records they belonged to.

 

Has anyone done something similar?

 

Regards,

Ivar

  • June 09, 2011
  • Like
  • 0

Hi all.

 

I am creating a small test just to try to use Visualforce and Sites to generate an RSS feed of Ideas in our organization. Everything seems to be working well within the development organization and when I load up the visualforce page from within salesforce it renders properly.

 

When I access it through the site I created it only shows the rss header and description information but displays an empty list of Ideas.

 

I have gone through the Public Access Settings for the site and made sure the Site's profile has read access to Ideas, and additionally made sure through Field Level Security that it again has read access to all fields on Ideas.

 

Still nothing displays.

 

The output from within the visualforce page itself is something like this:

 

<?xml version="1.0" encoding="UTF-8"?> 
    <rss version="2.0"> 
        <channel> 
            <title>Ideas</title> 
            <description>The 5 most recent ideas</description> 
            <link>http://www.salesforce.com</link> 
                <item> 
                    <title>Test 1</title> 
                    <description>This is test number 1</description> 
                    <link>http://emea.salesforce.com/087P00000000GtoIAE</link> 
                </item> 
                <item> 
                    <title>Test 2</title> 
                    <description>This is test 2 </description> 
                    <link>http://emea.salesforce.com/087P00000000GttIAE</link> 
                </item> 
        </channel> 
    </rss>

but from the site it looks like this:

 

 

<?xml version="1.0" encoding="UTF-8"?> 
    <rss version="2.0"> 
        <channel> 
            <title>Ideas</title> 
            <description>The 5 most recent ideas</description> 
            <link>http://www.salesforce.com</link> 
        </channel> 
    </rss>

 

 

 Does anyone have a clue as to why this might be happening?

 

Regards,

Ivar

 

  • March 16, 2011
  • Like
  • 0

Hi everyone.

 

I am having some trouble with binary attachments in inbound emails and was hoping someone might have a solution.

 

I have an inbound email processor that accepts an email containing a .vcf file and a .jpeg file as attachments.  I create a lead and the idea is to attach the two incoming files to the lead as attachments.

 

The .vcf file works like a charm and appears on the lead record as expected, but the .jpeg doesn't. For some reason the email.binaryAttachments list is empty. I've also tried adding a bunch of other binary files to the inbound email and the sizes of the two attachment lists always stay at 1 and 0, respectively.

 

Does anyone have a clue?

 

 

		       	
        	//now add the attachments to the Lead
        	List<Attachment> attachments = new List<Attachment>();
        	
        	//add  binaries
        	try {
	        	for( Messaging.InboundEmail.BinaryAttachment bin: email.binaryAttachments){
	        		Attachment a = new Attachment();
	        		a.ParentId = l.Id;
	        		a.Name = bin.filename;
	        		a.Body = bin.body;
	        		attachments.add( a );
	        	}
        	}
        	catch( Exception e ){}
        	 
        	//add texts
        	try{
	        	for( Messaging.InboundEmail.TextAttachment txt: email.textAttachments){
	        		Attachment a = new Attachment();
	        		a.ParentId = l.Id;
	        		a.Name = txt.filename;
	        		a.Body = Blob.valueOf(txt.body);
	        		attachments.add( a );
	        	}
        	}
        	catch( Exception e ){}
        	 
        	try{
        		insert attachments;
        	}
        	catch( Exception e ){
        		throw e;
        	}
        	

 

 

  • March 10, 2011
  • Like
  • 0

Hi everyone.

 

I have been trying to find this in the System Log but have found nothing. Can anyone tell me if they know of a way for me to read/capture the outgoing SOAP message generated by an Apex Class?

 

Regards,

Ivar

  • March 04, 2011
  • Like
  • 0

Hi everybody.

 

I am hoping someone can give me a hint that pushes me in the right direction. What I am doing is creating a visualforce page that allows a client to register a lead and associate products the lead. On the page I am listing the products as checkboxes that are then processed by the controller. This was working properly when I displayed all products in a long list of checkboxes like this:

 

[ ] product 1

[ ] product 2

[ ] product ...n

 

Now I have a change request to break them down by families to display like this:

 

Category 1

  [ ] product 1

  [ ] product 2

Category 2

  [ ] product 3

  [ ] product 4

Category ...n

  [ ] product ...n

 

IInstead of delivering the products from the controller to the page as a List of Product2 I am now delivering it as a List of ProductCategory ( a custom class I wrote to encapsulate the name of each category and the products it contains).

 

My controller and page code for the relevant part are as follows:

 

 

public List<ProductCategory> getCategoryList(){
    	List<ProductCategory> finalList = new List<ProductCategory>();
    	//get all the products and put them into the list according to category
    	List<Product2> allProducts = getProductList();
    	
    	String lastCategoryName = '';
    	ProductCategory oneCategory = new ProductCategory();
    	oneCategory.strCategoryName = allProducts[0].Family;
    	
    	for( Product2 p: allProducts ){
    		if( p.Family != lastCategoryName ){
    			if( oneCategory.products.size() > 0 ) finalList.add(oneCategory);
    			//create new ProductCategory
    			oneCategory = new ProductCategory();
    			oneCategory.strCategoryName = p.Family;
    			oneCategory.products.add( new SelectOption(p.Id, p.Name));
    		}
    		else{
    			//add to existing
    			oneCategory.products.add( new SelectOption(p.Id, p.Name));
    		}
    		lastCategoryName = p.Family;
    	}
    	
    	return finalList;
    }
    
    public class ProductCategory{
    	public String strCategoryName {get;set;}
    	public List<SelectOption> products {get;set;}
    	
    	public ProductCategory(){
    		strCategoryName = 'noname';
    		products = new List<SelectOption>();
    		
    	}
    }

 

 

<apex:repeat value="{!categoryList}" var="category">
        <b>{!category.strCategoryName}</b>
         <apex:selectCheckboxes value="{!productsValues}" layout="pageDirection">
            <apex:selectOptions value="{!category.products}"/><br/>
         </apex:selectCheckboxes>
         <br/>
     </apex:repeat>

 

 

What I am trying to do is use an <apex:repeat> to cycle through each category, display it's name and then a series of checkboxes for each of the products it contains.

 

Now comes the problem.

 

This displays correctly but (perhaps understandably) each run of the <apex:repeat> overwrites the reference to productValues ( <apex:selectCheckboxes value="{!productsValues}" layout="pageDirection">) so that only the checked entries from the last iteration of repeat are delivered back to the controller.

 

Can anyone help me out here? Is there some way for me to accomplish this differently? How can I do this dynamically without having to hard-code a writeback variable for each category?

 

My thanks in advance,

Ivar

 

 

  • March 03, 2011
  • Like
  • 0

Hi all.

 

I am running into a problem that stumps me, and I was hoping someone was able to give me a hint as to what might be going on.

 

I have a Visualforce page and an Apex Controller for a custom lead capture form I am creating. I don't have any actual business logic in there yet as I am only trying to get a sanity test on the general flow of things. 

 

The problem I am running into is that I have a commandButton that is set to call a method called "createLead" but it just doesn't seem to do that. I have the method down to creating an instance of a very simple custom debug object called Nugget, but nothing is created when I click the button. Does anyone have a clue as to what might be missing?

 

Visualforce page:

 

<apex:page sidebar="false" showHeader="false" controller="VF_LeadCaptureFormController">
  {!Campaign.Name}
  <apex:pageBlock rendered="{!isValid}" id="MainBlock">
     <apex:form>
     <apex:actionFunction name="createLead" action="{!createLead}"/>
     
     Forming<br/>
     <apex:selectCheckboxes value="{!inLead.eq_Forming__c}">
         <apex:selectOptions value="{!formingList}"/>
     </apex:selectCheckboxes>
     
      Freezing<br/>
     <apex:selectCheckboxes value="{!inLead.eq_Freezing_and_Tempering__c}">
         <apex:selectOptions value="{!freezingList}"/>
     </apex:selectCheckboxes>
     <apex:commandButton action="{!createLead}" value="Save" id="SaveButton"/>
 
     </apex:form>
     
  </apex:pageBlock>

 

 

Controller section:

 

public PageReference createLead(){
    
    	Nugget__c n = new Nugget__c();
    	insert n;
    	return null;
}

 Any help would be greatly appreciated.

 

Regards,

Ivar

 

  • February 18, 2011
  • Like
  • 0

Does anyone know of a best practice/easy way of integrating to files on a local drive at my end from Apex/Salesforce? Any hints would be well appreciated.

 

Regards,

Ivar

  • February 14, 2011
  • Like
  • 0

Hi.

 

I was wondering if anyone had any experience on using Apex and the Metadata API.

 

The task I am faced with is creating a trigger on the User object that modifies the available values in a picklist on another object, and I was wondering if I could access such "metadata" from an apex trigger.

 

Regards,

Ivar

  • January 31, 2011
  • Like
  • 0

Hi all.

 

I am trying to connect from Apex to an external WebService that requires the use of ws-security. I have discovered that this is not directly supported by Apex, but a suggested solution was to manually edit the WDSL document to include the ws-security header information.

 

I have been trying to do this without much luck, and was wondering if anyone out there had a simple example of what I need to inject into the WSDL, and where?

 

My thanks in advance,

Ivar

  • December 21, 2010
  • Like
  • 0

Hi everybody.

 

I have been messing around with trying something and am not sure where I am doing this wrong, and was hoping someone might be able to point me in the right direction.

 

My very short visualforce code is included below. What I am trying to do is to create a visualforce page that contains an iframe that points to a salesforce dashboard. The page then also contains a small javascript segment that I want to eventually use to periodically refresh the dashboard presumably by firing off the click event on the dashboard's refresh button. I haven't created the periodical timeout loop, as I can't even reference the button.

 

My problem is that I am not able to reference the refresh button. I have tried many variations but I never seem to be able to find that button. Please if someone has an idea I would really appreciate a hint :)

 

Maybe I am using the wrong technology to reference the object, maybe I got the id wrong, at any rate, any help will be greatly appreciated :)

 

 

<apex:page sidebar="false" showHeader="false">
<div id="test">myText</div>
  
  <iframe id="box" src="https://emea.salesforce.com/01Z200000000kFc" width="100%" height="1000" />
 <script language="javascript">
     
     document.getElementById("box").document.getElementById("{!$Component.refreshButton}").click();
     
     
  </script>
</apex:page>

 

 

  • August 18, 2010
  • Like
  • 0

Hi everyone.

 

I have a bit of a problem that I have been trying to get around for quite awhile now. I wrote a previous post (http://community.salesforce.com/t5/Visualforce-Development/Problem-with-Component-in-javascript/m-p/190323#M25337) about a problem I had where I was trying to get around issues with one type of workaround I tried, but have been unable to resolve that.

 

Rather than focus on my current failed attempt at getting around this I am now presenting my problem as it is, in hope that someone out there might see this from another perspective and offer some insights.

 

What I have is a visualforce page with a controller extension that runs within an iframe in a custom object's page layout (see screenshot below). What this does is allow users to edit certain properties of a related object in-line on the current page layout, without having to open each line up. This is done by the user by clicking the "QuickEdit" link for each line, and then either "Save" or "Cancel".

 

visualforce page layout component

 

When the Save link is clicked (#3 on screenshot) I always want the controller to fire up, do some logic, including saving the record obviously, but then, based on the selection in one of the picklists (#4 on screenshot) I want the return to either just refresh the list (#2 on screenshot), or redirect the parent page (#1 on screenshot) to a different location.

 

I am able to easily hardcode this to always do one of the two by setting the "rerender" or "target" properties of the commandLink (#3), but I want this to change dynamically based on the selection in (#4).

 

Now the render properties are set in the attributes of the commandLink (#2) element and are thus already set when the controller receives the request making it impossible (I think) for me to manipulate the return target from the controller, so I have been trying to use javascript to do this, without much success. I have been trying to call a javascript function on the "onChange" event of the controlling element (#4), but the javascript can only access DOM elements and thus can only change the commandLink's "target" attribute, not it's VF-specific "rerender" property.

 

I hope I managed to describe what I am dealing with, and hopefully someone has a suggestion for me that might work.

 

Best regards,

Ivar

  • June 28, 2010
  • Like
  • 0

Hi all.

 

Hopefully someone can point me in the right direction. I have a visualforce page in which I am trying to change the properties of certain elements via javascript. I am trying to reference an object using this method:

 

var myObject = document.getElementById("{!$Component.objectId}");

 

But for some reason I am unable to fetch that Id. Here is the visualforce part where the elements are defined:

 

 

<td><apex:commandLink action="{!cancelEdit}" rerender="projectList">Cancel</apex:commandLink></td>
                <td><apex:commandLink action="{!saveEdit}"  rerender="projectList" target="_top" id="cmdLink">Save</apex:commandLink></td>
                <td><apex:inputField rendered="{!p.Id == editLine.Id}" value="{!editLine.plProductCategory__c}"/></td>
                <td><apex:inputField rendered="{!p.Id == editLine.Id}" value="{!editLine.plTransactionType__c}"/></td>
                <td><apex:inputField rendered="{!p.Id == editLine.Id}" value="{!editLine.plStatus__c}" id="statusField" onChange="setTarget()"/></td>

 

 

and here is the javascript function I am calling when the last field changes:

 

 

<script>     
  function setTarget(){
           alert( "{!$Component.cmdLink}" );
           var cmdLink = document.getElementById("{!$Component.cmdLink}");
           var statusField = document.getElementById("{!$Component.statusField}");
           
           if( statusField.value == "Unnin sala" ){
           	linkElement.target = "_top";
           	linkElement.rerender = "";
           }
           else{
           	linkElement.target = "";
           	linkElement.rerender = "projectList";
           }
        	
        }
    </script>

 

 

No objects are fetched via the getElmenentById calls and the variables cmdLink and statusField are null. Just to test further I added the alert at the top of the function to try and see what I get from the Component reference but that alert comes up empty.

 

Does anyone have an idea as to what I am doing wrong here?

 

Best regards,

Ivar

  • June 22, 2010
  • Like
  • 0

Hi all.

 

Can anyone tell me if I can reference or access the standard object icons (Account folder icon, Case bag icon, Contact card icon, etc.) from somewhere to use on a Visualforce page?

 

Edit: To explain further I am trying to build a Visualforce page that contains a mixed list of objects (Cases, Opportunities, etc.) and would like to be able to display the appropriate icon in front of each one, to visually specify their type.

 

Regards,

Ivar

  • June 16, 2010
  • Like
  • 0

Hi all.

 

Does anyone know how the new field dependency availability (Summer '10) in Visualforce Pages is supposed to work? I am able to implement the feature when I use a standard controller (as per the example in the release notes), but as soon as the object I want to utilize the dependencies on is delivered to the page through a controller extension it doesn't seem to work.

 

Anybody know if this is intended behavior, or if there is a way around this?

 

Regards,

Ivar Gunnarsson

  • June 14, 2010
  • Like
  • 0

Hi.

 

Can anyone tell me where/how I can send a notification to the initial submitter of an approval request upon final Approval/Rejection. If I add an email message action to either Final Approval or Final Rejection I am unable to select an appropriate recipient. The closest I get is "Creator", but that is the creator of the record to be approved, which is not good enough for me.

 

Any thoughts?

 

Regards,

Ivar

  • June 07, 2010
  • Like
  • 0

I am at a loss, and am unable to find how I change this.

 

I have a visualforce page and an ajax controller feeding it data. Whenever the list of items fetched by the apex page exceeds 5 the visualforce page only displays the 5 latest, and cuts off the rest.

 

Can anyone tell me how I change this?

 

Best regards,

Ivar

  • May 31, 2010
  • Like
  • 0

Hi all.

 

I am running into a bit of a problem that I haven't been able to find a solution to and was hoping someone here might be able to nudge me in the right direction with it.

 

The thing is that I am running a small visualforce page with a custom controller. On that page I have a commandLink. What I would like to do is pass a salesforce-style DateTime field along with that link.

 

Can anyone give me a hint as to how this might be accomplished? 

  • January 12, 2010
  • Like
  • 0
Hi there.

I have been browsing around and searching for a solution but have found none.

My problem is that I am creating an Apex Web Service for internal use within my company and we are having some problems with the WSDL. According to the developers I am working with they cannot process the current WSDL because it contains anonymous complexType elements that their tools thus cannot reference:

example: <xsd:complexType>

Does anyone know if there is any way for me to manipulate this so that a name is assigned to the elements in question?

Something like this: <xsd:complexType name="CreateOrder">

My web service code, still only a test, looks like this:

global class WSCreateWorkOrder {
webService static string CreateOrder( string strOrderId ){

FieldServicesB2B__c wo = new FieldServicesB2B__c();

try{
insert wo;

}
catch( Exception e ){
return 'Error: ' + e.getMessage();
}

return wo.Id;

}

}

Best regards,
Ivar

Message Edited by Ivar on 01-14-2009 07:31 AM

Message Edited by Ivar on 01-14-2009 07:33 AM
  • January 14, 2009
  • Like
  • 0
Hi everybody. I am having trouble trying to deploy a small project into our salesforce instance. I have been working with this in Eclipse against our sandbox org, and am trying to deploy to production.

I have tried numerous times but am always getting a timeout. I have also been working at a sister company doing similar work and there I have no trouble. The difference between the two is that at the sister company I am working with an Enterprise edition with some minor customizations, but here I have an Unlimited edition which has been heavily customized and expanded, so I fear that has something to do with the problem.

The error I get in eclipse is the following:
"Unable to generate deployment plan against destination organization. Reason: ServiceException: Operation time out - polling limit (600000 milliseconds) reached".

Does anyone have an idea as how I might get around this problem?

Best regards,
Ivar
  • October 13, 2008
  • Like
  • 0
Hi everyone. I have been searching the boards for a solution for something similar, have found several but none have seemed to fix my problem. Can anyone shed a light on why the following code segment (run within an Inbound Email Processor) keeps creating new Contacts each run around, instead of creating one the first time and then subsequently finding an already created one?

Contact contact = new Contact();
try{
contact = [SELECT Id, Name FROM Contact Where Name = :txtContactName AND AccountId = :account.Id limit 1];
}
catch( Exception e ){
contact.LastName = txtContactName;
contact.AccountId = account.Id;
insert contact;
}
  • September 29, 2008
  • Like
  • 0

Hi everyone.

 

I am having some trouble with binary attachments in inbound emails and was hoping someone might have a solution.

 

I have an inbound email processor that accepts an email containing a .vcf file and a .jpeg file as attachments.  I create a lead and the idea is to attach the two incoming files to the lead as attachments.

 

The .vcf file works like a charm and appears on the lead record as expected, but the .jpeg doesn't. For some reason the email.binaryAttachments list is empty. I've also tried adding a bunch of other binary files to the inbound email and the sizes of the two attachment lists always stay at 1 and 0, respectively.

 

Does anyone have a clue?

 

 

		       	
        	//now add the attachments to the Lead
        	List<Attachment> attachments = new List<Attachment>();
        	
        	//add  binaries
        	try {
	        	for( Messaging.InboundEmail.BinaryAttachment bin: email.binaryAttachments){
	        		Attachment a = new Attachment();
	        		a.ParentId = l.Id;
	        		a.Name = bin.filename;
	        		a.Body = bin.body;
	        		attachments.add( a );
	        	}
        	}
        	catch( Exception e ){}
        	 
        	//add texts
        	try{
	        	for( Messaging.InboundEmail.TextAttachment txt: email.textAttachments){
	        		Attachment a = new Attachment();
	        		a.ParentId = l.Id;
	        		a.Name = txt.filename;
	        		a.Body = Blob.valueOf(txt.body);
	        		attachments.add( a );
	        	}
        	}
        	catch( Exception e ){}
        	 
        	try{
        		insert attachments;
        	}
        	catch( Exception e ){
        		throw e;
        	}
        	

 

 

  • March 10, 2011
  • Like
  • 0

Hi Folks,

 

I am unable to cover the parts which is marked in red in test coverage. Please help me in covering these parts. It is very urgernt.

 

 

public PageReference EmailQuote(){

try
{

PageReference pcd = Page.esc_Quote;
pcd.getParameters().put('id',Oppr.id);
Blob pdfBlob = pcd.getContent();

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String [] toAddresses = new String[] {SearchTo};
String [] toCC = new String[] {SearchCC};
String [] toBCC = new String[] {SearchBCC};
str1=SearchBody.replaceAll('\n','<br/>');

if(Acc.RecordTypeId=='0122000000058UW' || Acc.RecordTypeId=='01220000000HS25'){
Contact cc=[select id,name,Email from contact where id=:oppr.contact__c];
if(cc.Email != null){
email.setTargetObjectId(cc.Id);
email.setSubject(SearchSubject);
email.setHtmlBody(str1);

if(SearchCC!=''){
email.setCcAddresses(toCC);
}
if(SearchBCC!=''){
email.setBccAddresses(toBCC);
}
email.setSaveAsActivity(true);

// Create an email attachment
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('ES_'+ Oppr.Quote_Number__c+'-'+ Oppr.Quote_Version__c + '.pdf');
efa.setBody(pdfBlob); //attach the PDF
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});

//Create an event.
Task myTask = new Task();
myTask.WhatId = Oppr.Id;
myTask.WhoId = cc.Id;
myTask.IsReminderSet = true;
myTask.ReminderDateTime = System.Today();
myTask.ActivityDate = System.Today();
myTask.Description = SearchBody;
myTask.Subject = SearchSubject;
myTask.OwnerId = Usr.Id;
myTask.Status = 'Completed';

Insert myTask;
}

else{
email.setSaveAsActivity(false);
email.setTargetObjectId(usr.Id);
email.setSubject('No Email to send the Quotation');
email.setHtmlBody('Dear '+usr.Name+', No Email ID found into the Contact to send the Quotation.');
}

}

if(Acc.RecordTypeId=='0122000000058cV'){

//email.setTargetObjectId(Con.Id);
email.setSubject(SearchSubject);
email.setHtmlBody(str1);

email.setToAddresses(toAddresses);

if(SearchCC!=''){
email.setCcAddresses(toCC);
}
if(SearchBCC!=''){
email.setBccAddresses(toBCC);
}
email.setSaveAsActivity(true);

//Create an email attachment
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('ES_'+ Oppr.Quote_Number__c+'-'+ Oppr.Quote_Version__c + '.pdf');
efa.setBody(pdfBlob); //attach the PDF
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});

//Create an event.
Task myTask = new Task();
myTask.WhatId = Oppr.Id;
myTask.WhoId = con.Id;
myTask.IsReminderSet = true;
myTask.ReminderDateTime = System.Today();
myTask.ActivityDate = System.Today();
myTask.Description = SearchBody;
myTask.Subject = SearchSubject;
myTask.OwnerId = Usr.Id;
myTask.Status = 'Completed';

Insert myTask;

}

Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

Pagereference OppPage = new ApexPages.StandardController(Oppr).view();
opppage.setredirect(true);
return OppPage;
}
catch(Exception e){
System.debug('ERROR:' + e);
return null;
}

}

 

 

 

Hi everyone.

 

I have been trying to find this in the System Log but have found nothing. Can anyone tell me if they know of a way for me to read/capture the outgoing SOAP message generated by an Apex Class?

 

Regards,

Ivar

  • March 04, 2011
  • Like
  • 0

 

How can i pass values form a string to multipicklist field.

I need to update a multipicklist field.

 

I have concatenated a list of values to a string as:

 

string str = '1; 2; 3; 4';

 

I thought of passing these values directly to the field but the field is not being updated.

Please let me know what needs to be done.

 

Hi everybody.

 

I am hoping someone can give me a hint that pushes me in the right direction. What I am doing is creating a visualforce page that allows a client to register a lead and associate products the lead. On the page I am listing the products as checkboxes that are then processed by the controller. This was working properly when I displayed all products in a long list of checkboxes like this:

 

[ ] product 1

[ ] product 2

[ ] product ...n

 

Now I have a change request to break them down by families to display like this:

 

Category 1

  [ ] product 1

  [ ] product 2

Category 2

  [ ] product 3

  [ ] product 4

Category ...n

  [ ] product ...n

 

IInstead of delivering the products from the controller to the page as a List of Product2 I am now delivering it as a List of ProductCategory ( a custom class I wrote to encapsulate the name of each category and the products it contains).

 

My controller and page code for the relevant part are as follows:

 

 

public List<ProductCategory> getCategoryList(){
    	List<ProductCategory> finalList = new List<ProductCategory>();
    	//get all the products and put them into the list according to category
    	List<Product2> allProducts = getProductList();
    	
    	String lastCategoryName = '';
    	ProductCategory oneCategory = new ProductCategory();
    	oneCategory.strCategoryName = allProducts[0].Family;
    	
    	for( Product2 p: allProducts ){
    		if( p.Family != lastCategoryName ){
    			if( oneCategory.products.size() > 0 ) finalList.add(oneCategory);
    			//create new ProductCategory
    			oneCategory = new ProductCategory();
    			oneCategory.strCategoryName = p.Family;
    			oneCategory.products.add( new SelectOption(p.Id, p.Name));
    		}
    		else{
    			//add to existing
    			oneCategory.products.add( new SelectOption(p.Id, p.Name));
    		}
    		lastCategoryName = p.Family;
    	}
    	
    	return finalList;
    }
    
    public class ProductCategory{
    	public String strCategoryName {get;set;}
    	public List<SelectOption> products {get;set;}
    	
    	public ProductCategory(){
    		strCategoryName = 'noname';
    		products = new List<SelectOption>();
    		
    	}
    }

 

 

<apex:repeat value="{!categoryList}" var="category">
        <b>{!category.strCategoryName}</b>
         <apex:selectCheckboxes value="{!productsValues}" layout="pageDirection">
            <apex:selectOptions value="{!category.products}"/><br/>
         </apex:selectCheckboxes>
         <br/>
     </apex:repeat>

 

 

What I am trying to do is use an <apex:repeat> to cycle through each category, display it's name and then a series of checkboxes for each of the products it contains.

 

Now comes the problem.

 

This displays correctly but (perhaps understandably) each run of the <apex:repeat> overwrites the reference to productValues ( <apex:selectCheckboxes value="{!productsValues}" layout="pageDirection">) so that only the checked entries from the last iteration of repeat are delivered back to the controller.

 

Can anyone help me out here? Is there some way for me to accomplish this differently? How can I do this dynamically without having to hard-code a writeback variable for each category?

 

My thanks in advance,

Ivar

 

 

  • March 03, 2011
  • Like
  • 0

Hi,

 

I am trying to create  an Email to lead.i mean when i use the email service link to send the mail to SF, a lead is generated.As this is working ,but when i am trying to attach a file with the Email.The file is not comin as attachments.My code is under.Can any one try to solve my problem.

Global class unsubscribe implements Messaging.inboundEmailHandler{

    Global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,Messaging.InboundEnvelope env )
    {

    // Create an inboundEmailResult object for returning
    //the result of the Apex Email Service
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
    
 
    String strEmailId = email.fromAddress;
    String strSubject = email.subject;
    String myText=email.plainTextBody;
    String myFromName = email.fromName;
    Lead l;
    
       

    //Create a new test Lead and insert it in the Test Method 
    integer iCount;
    iCount = [select count() from Lead where Email=:email.fromAddress];
    if (iCount==0)
    {   
        l = new Lead(
        lastName= myFromName, //strEmailId,
        Company=myFromName,
        Email=strEmailId,
        LeadSource='OnlineEnquiry',
        Description=strSubject+'\n'+myText,
        OwnerId='00590000000OJ0w'); //Change this id with user's id to whome you want to assign this lead.
        insert l;    
       
    }
   
   
    result.success = true;
    return result;
    for (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {
     Attachment attachment = new Attachment();
     
    attachment.Name = tAttachment.fileName;
     attachment.Body = Blob.valueOf(tAttachment.body);
     attachment.ParentId = l.Id;
     insert attachment;
    }
    for (Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
     Attachment attachment = new Attachment();
     
    attachment.Name = bAttachment.fileName;
     attachment.Body = bAttachment.body;
      attachment.ParentId =l.Id;
     insert attachment;
   
    }
     result.success = true;
    return result;
    }  


    /* Only for test case */

    // Test method to ensure you have enough code coverage
    // Have created two methods, one that does the testing
    // with a valid "unsubcribe" in the subject line
    // and one the does not contain "unsubscribe" in the
    // subject line
   static testMethod void testUnsubscribe() {

   // Create a new email and envelope object
        Messaging.InboundEmail email = new Messaging.InboundEmail() ;
        Messaging.InboundEnvelope env    = new Messaging.InboundEnvelope();
      
        // Create a new test Lead and insert it in the Test Method       
       Lead l = new lead(firstName='Rasmus',
                lastName='abc',
                Company='Salesforce',
                Email='rmencke@salesforce.com',LeadSource='OnlineEnquiry',Description='dsdfdgf'
                );
       insert l;
    
    // Create a new test Contact and insert it in the Test Method 
       Contact c = new Contact(firstName='Rasmus',
                    lastName='Mencke',
                    Email='rmencke@salesforce.com');
       insert c;
      
       // test with subject that matches the unsubscribe statement
       email.subject = 'test unsubscribe test';
       email.fromName = 'abhi k';
       email.fromAddress = 'abhilash@rixyncs.co.in';
        email.subject='test';
       email.plainTextBody='zsdzdf';
        
       
       
  
       // call the class and test it with the data in the testMethod
       unsubscribe unsubscribeObj = new unsubscribe();
       unsubscribeObj.handleInboundEmail(email, env );
                           
       }
       
      /* static testMethod void testTrigger() {
        Lead l = new Lead(lastName='testTrigger',Status='Qualified',Email='abhi@rixyncs.co.in',
                          Company='Rixyncs',MobilePhone='919901379361');
        insert l;
      //  SMS__c s = new SMS__c(To_Lead__c=l.Id,Message__c='Test');
      //  insert s; 
        
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(l.Id);
        lc.setConvertedStatus('Qualified');
        Database.LeadConvertResult lcr = Database.convertLead(lc);
    }*/

}

 Please help me.

 

Thanks

 

Nasir

 

  • February 24, 2011
  • Like
  • 0

Hi all.

 

I am running into a problem that stumps me, and I was hoping someone was able to give me a hint as to what might be going on.

 

I have a Visualforce page and an Apex Controller for a custom lead capture form I am creating. I don't have any actual business logic in there yet as I am only trying to get a sanity test on the general flow of things. 

 

The problem I am running into is that I have a commandButton that is set to call a method called "createLead" but it just doesn't seem to do that. I have the method down to creating an instance of a very simple custom debug object called Nugget, but nothing is created when I click the button. Does anyone have a clue as to what might be missing?

 

Visualforce page:

 

<apex:page sidebar="false" showHeader="false" controller="VF_LeadCaptureFormController">
  {!Campaign.Name}
  <apex:pageBlock rendered="{!isValid}" id="MainBlock">
     <apex:form>
     <apex:actionFunction name="createLead" action="{!createLead}"/>
     
     Forming<br/>
     <apex:selectCheckboxes value="{!inLead.eq_Forming__c}">
         <apex:selectOptions value="{!formingList}"/>
     </apex:selectCheckboxes>
     
      Freezing<br/>
     <apex:selectCheckboxes value="{!inLead.eq_Freezing_and_Tempering__c}">
         <apex:selectOptions value="{!freezingList}"/>
     </apex:selectCheckboxes>
     <apex:commandButton action="{!createLead}" value="Save" id="SaveButton"/>
 
     </apex:form>
     
  </apex:pageBlock>

 

 

Controller section:

 

public PageReference createLead(){
    
    	Nugget__c n = new Nugget__c();
    	insert n;
    	return null;
}

 Any help would be greatly appreciated.

 

Regards,

Ivar

 

  • February 18, 2011
  • Like
  • 0

Hi.

 

I was wondering if anyone had any experience on using Apex and the Metadata API.

 

The task I am faced with is creating a trigger on the User object that modifies the available values in a picklist on another object, and I was wondering if I could access such "metadata" from an apex trigger.

 

Regards,

Ivar

  • January 31, 2011
  • Like
  • 0

Hi everybody.

 

I have been messing around with trying something and am not sure where I am doing this wrong, and was hoping someone might be able to point me in the right direction.

 

My very short visualforce code is included below. What I am trying to do is to create a visualforce page that contains an iframe that points to a salesforce dashboard. The page then also contains a small javascript segment that I want to eventually use to periodically refresh the dashboard presumably by firing off the click event on the dashboard's refresh button. I haven't created the periodical timeout loop, as I can't even reference the button.

 

My problem is that I am not able to reference the refresh button. I have tried many variations but I never seem to be able to find that button. Please if someone has an idea I would really appreciate a hint :)

 

Maybe I am using the wrong technology to reference the object, maybe I got the id wrong, at any rate, any help will be greatly appreciated :)

 

 

<apex:page sidebar="false" showHeader="false">
<div id="test">myText</div>
  
  <iframe id="box" src="https://emea.salesforce.com/01Z200000000kFc" width="100%" height="1000" />
 <script language="javascript">
     
     document.getElementById("box").document.getElementById("{!$Component.refreshButton}").click();
     
     
  </script>
</apex:page>

 

 

  • August 18, 2010
  • Like
  • 0

Hello Salesforce gurus,

 

I am new to SFDC and I am running into a roadblock with the following WSDL which I am trying to generate APEX code.

 

The WSDL successfully got parsed but the APEX code generation failed fatally.

 

The error message while generating the APEX code is

 

Error: Unsupported WSDL. Found more than one part for message CostaAuthenticatorInput

 

Any workaround to solve this would be awesome. Your help is hightly appreciated.

 

Thanks in advance.

 

Sk_rk

 

The actual WSDL is below

 

<?xml version = '1.0' encoding = 'UTF-8'?>
<definitions name="CostaFinder" targetNamespace="http://xmlns.costamesa.com/module/" xmlns:tns="http://xmlns.costamesa.com/module/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns1="http://xmlns.costamesa.com/module/test/">
   <types>
<schema targetNamespace="http://xmlns.costamesa.com/module/test/" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:db="http://xmlns.costamesa.com/module/test/" elementFormDefault="qualified">
   <element name="CostaIn">
      <complexType>
         <sequence>
            <element name="Param1" type="string" db:index="1" db:type="VARCHAR2" minOccurs="0" nillable="true"/>
            <element name="Param2" type="string" db:index="2" db:type="VARCHAR2" minOccurs="0" nillable="true"/>
         </sequence>
      </complexType>
   </element>
   <element name="CostaOut">
      <complexType>
         <sequence>
            <element name="CostaAuthenticator" type="string" db:index="0" db:type="VARCHAR2" minOccurs="0" nillable="true"/>
         </sequence>
      </complexType>
   </element>
         <element name="MyHeader">
            <complexType>
               <sequence>
                  <element name="Param3" minOccurs="0" type="string"/>
                  <element name="Param4" minOccurs="0" type="string"/>
               </sequence>
            </complexType>
         </element>

</schema>
   </types>
   <message name="CostaAuthenticatorInput">
      <part name="header" element="tns1:MyHeader"/>
      <part name="body" element="tns1:CostaIn"/>
   </message>
   <message name="CostaAuthenticatorOutput">
      <part name="body" element="tns1:CostaOut"/>
   </message>
   <portType name="CostaFinder_PortType">
      <operation name="CostaAuthenticator">
         <input message="tns:CostaAuthenticatorInput"/>
         <output message="tns:CostaAuthenticatorOutput"/>
      </operation>
   </portType>
   <binding name="CostaFinder_Binding" type="tns:CostaFinder_PortType">
      <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
      <operation name="CostaAuthenticator">
         <soap:operation soapAction="http://costamesa:8076/webservices/server"/>
         <input>
            <soap:header message="tns:CostaAuthenticatorInput" part="header" use="literal"/>
            <soap:body parts="body" use="literal"/>
         </input>
         <output>
            <soap:body use="literal"/>
         </output>
      </operation>
   </binding>
   <service name="CostaFinder_Service">
      <port name="CostaFinder_Port" binding="tns:CostaFinder_Binding">
         <soap:address location="http://costamesa:8076/webservices/server"/>
      </port>
   </service>
</definitions>

  • July 30, 2010
  • Like
  • 0

Hi everyone.

 

I have a bit of a problem that I have been trying to get around for quite awhile now. I wrote a previous post (http://community.salesforce.com/t5/Visualforce-Development/Problem-with-Component-in-javascript/m-p/190323#M25337) about a problem I had where I was trying to get around issues with one type of workaround I tried, but have been unable to resolve that.

 

Rather than focus on my current failed attempt at getting around this I am now presenting my problem as it is, in hope that someone out there might see this from another perspective and offer some insights.

 

What I have is a visualforce page with a controller extension that runs within an iframe in a custom object's page layout (see screenshot below). What this does is allow users to edit certain properties of a related object in-line on the current page layout, without having to open each line up. This is done by the user by clicking the "QuickEdit" link for each line, and then either "Save" or "Cancel".

 

visualforce page layout component

 

When the Save link is clicked (#3 on screenshot) I always want the controller to fire up, do some logic, including saving the record obviously, but then, based on the selection in one of the picklists (#4 on screenshot) I want the return to either just refresh the list (#2 on screenshot), or redirect the parent page (#1 on screenshot) to a different location.

 

I am able to easily hardcode this to always do one of the two by setting the "rerender" or "target" properties of the commandLink (#3), but I want this to change dynamically based on the selection in (#4).

 

Now the render properties are set in the attributes of the commandLink (#2) element and are thus already set when the controller receives the request making it impossible (I think) for me to manipulate the return target from the controller, so I have been trying to use javascript to do this, without much success. I have been trying to call a javascript function on the "onChange" event of the controlling element (#4), but the javascript can only access DOM elements and thus can only change the commandLink's "target" attribute, not it's VF-specific "rerender" property.

 

I hope I managed to describe what I am dealing with, and hopefully someone has a suggestion for me that might work.

 

Best regards,

Ivar

  • June 28, 2010
  • Like
  • 0