You need to sign in to do that
Don't have an account?
How to get values into a list
public void save()
{
for (Integer j = 0; j < selectcategory.size(); j++)
{
for (Integer i = 0; i< selectlayout.size(); i++)
{
system.debug('valuedata'+selectlayout[i].label1);
str = '<widgetnode><widget Name='+ selectcategory[j].label +'><Imag='+ selectlayout[i].Image1 +' Field='+ selectlayout[i].label1 +' result='+ selectlayout[i].value +'/></widget></widgetnode>' ;
system.debug('stringgg'+str);
}
}
}
widgetpro.Displayed_Widgets__c = str;
}
I'm getting only last value into str......but in debug I can get all the values.....How should I come out of this
What if you change your string assignment to str = str + '<widgetnode...
In your current code, you're replacing str on every pass through your loop.
Also note that you're not creating valid XML, since your attributes aren't properly quoted. Instead of:
'<widget name=' + foo + '>'
You need to use:
'<widget name="' + foo + '">'
(Hopefully you can see the addition of a quote (") inside the strings before and after foo.)
All Answers
Hi,
Try the below code snippet.
List<String> lstStr = new List<String>();
public void save()
{
for (Integer j = 0; j < selectcategory.size(); j++)
{
for (Integer i = 0; i< selectlayout.size(); i++)
{
system.debug('valuedata'+selectlayout[i].label1);
str = '<widgetnode><widget Name='+ selectcategory[j].label +'><Imag='+ selectlayout[i].Image1 +' Field='+ selectlayout[i].label1 +' result='+ selectlayout[i].value +'/></widget></widgetnode>' ;
system.debug('stringgg'+str);
lstStr.add(str);
}
}
}
for(Integer i =o;i<lstStr.size();i++){
widgetpro.Displayed_Widgets__c = lstStr[i].str;
}
}
Mark it as resolved if it helps you.
Sanj
Hi Sanjdev,
Thanks for ur quick reply........I'm getting error like this don't know why....please help me
Initial term of field expression must be a concrete SObject:
widgetpro.Displayed_Widgets__c = lstStr[i].str;
and getting error when i used
widgetpro.Displayed_Widgets__c = lstStr[i];
System.DmlException: Insert failed. First exception on row 0; first error: STRING_TOO_LONG, Displayed Widgets: data value too large: null<widget Name=Social Network><Imag=null Field=Widget Name result=tyh/></widget><widget Name=Social Network><Imag=http://t2.gstatic.com/images?q=tbn:ANd9GcQPw1U3ihkGF2nkOzBC8EHA-2A8U58q8Bf9tQxaB1t-QhpsP__9 Field=Iframe Code result=fghfgjh/></widget><widget Name=Google Maps><Imag=null Field=Widget Name ................& so on
How should I get rid of this.......
I think the String you try to insert is too long for the field. Go into the field description and look whats the maximum size of chars which are allowed in the field.
What if you change your string assignment to str = str + '<widgetnode...
In your current code, you're replacing str on every pass through your loop.
Also note that you're not creating valid XML, since your attributes aren't properly quoted. Instead of:
'<widget name=' + foo + '>'
You need to use:
'<widget name="' + foo + '">'
(Hopefully you can see the addition of a quote (") inside the strings before and after foo.)
Thanks Tom....It helped me a lot