+ Start a Discussion
kamal_Raokamal_Rao 

how to insert owner field in new record in salesforce

HI,
    

   I am trying to creating new record sorce is coming out of the BOX using rest what i am creating new record that record owner also come out ofthe box that is also salesforce org.
hear my problem is insert owner field in new record.
Ankit AroraAnkit Arora
You can do that by using ownerId record. But it should be  a salesforce user. So first you've to fetch the user based on your out of the box value and then use it for ownerId.
kamal_Raokamal_Rao
Tnq ankit ,

but inserting time showing error like this variable dosn't exist.....
 
 User-added image
@HTTPPOST
        global static void creatingRating(string srating, id cuserid )
        {
        
           string email=RestContext.request.params.get('email');
           system.debug('-------------------'+srating );
            system.debug('-------------------'+cuserid );
           ID cby=RestContext.request.params.get('uid');
                rating__c rec=new rating__c();
                rec.rating__C=srating;
                //res.ownerId=cuserid;
                insert rec;
Ankit AroraAnkit Arora
Ohh! I thought you are talking about native object. If it is custom then let me know if it helps : https://developer.salesforce.com/forums?id=906F00000008vNoIAI
Avidev9Avidev9
I think that line should be 

rec.OwnerId

you are doing res.OwnerId
Ankit AroraAnkit Arora
Good catch. May be it will solve the problem, but I think I was also stuck with the same problem once where I was not able to update/access ownerId and that problem is with the custom objects.

Let's hope it works for him.