You need to sign in to do that
Don't have an account?

Instance of string to instance of schema.sobjectfield in salesforce
hi,
i have a question can anyone please help.
how to convert instance of string to instance of schema.sobjectfield in salesforce.
Is there any method for it?
Please give a small example of the method.
Thanks
thanks for the reply.Above is the code:
public string[] selectedValue2{get;set;}
Contact c = new Contact();
for(Integer i=0;i<=headerXLS.size();i++)
{
for(Integer j=0;j<=selectedValue1.size();j++)
{
if (headerXLS[i] == selectedValue1[j])
{
c.selectedValue2[j] = inputvalues[i];
}
}
}
here selectedvalue2 is a value getting selected in listbox in visualforce page.
when i use this code im getting error saying that "Compile Error: Invalid field selectedValue2 for SObject Contact"
as c is an object instance and selectedvalue2 is a string.
what is the solution for this.
How do i use a string as Sobjectfield?
Thanks.
U can't pass the values like that.If you want to pass the value into a Particular field of contact then you can specify as
c.Field__c = inputValues[i];
Here can i know what is the datatype of inputValues[i].
inputvalues is a string array
String[] inputvalues = new String[]{};
and can i know what is field__c?
Here Field__c is a custom field in your contact object where you can store the values of Inputvalues[i] into it as
c.Field__c = inputValues[i];
I don't know what excatly you are trying to do.You can pass values like this also
if (headerXLS[i] == selectedValue1[j])
{
selectedValue2[i] = inputvalues[i];
}
But you can't pass values as c.selectedValue2[j] = inputvalues[i];
i will explain you what im trying to do.
My Requirement is something like i want to save value of 'inputvalues' which is a string array to objectname.fieldname
but my fieldname is coming from an another string array named selectedvalue2.
So i cant use both the options you gave me.
Can this be done through any other way like getGlobalDescribe() or something else?
c.put(selectedValue2[j], inputvalues[i]);
update c
c.put isnt working.Please provide other solution.
I wll explain my problem once again
Instead of the above code, i want it in the following way:
Here HeaderXLS and Inputvalues both are String Array.
But c.put isnt working.
HeaderXLS[j] has field names for a particular object.
I want
but even this isnt working.Please provide a solution for the problem.
Thanks.
what means c.put isn't working? Can you save code succesfully which means there is no grammar error?
yea.no syntax errors.
but i am not getting the output.
first try to debug print out c.put(XX), for checking it is correct text to put
if it is correct, try to debug c.XXfield and check the value
Next, if it is empty value, try to use generic sobject to create contact, something like sobject c= new Contact();