function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Alejandro ValcarcelAlejandro Valcarcel 

json response after sf.Create.contact

Hi, I'm new to SF, Python and Flask. Wich are the tools I'm using to build up a little web UI for registering (creating anew contact on SF). I found Simple-Salesforce and works pretty well for me. So, right now I have this code wich is working perfectly so far:
 
# User Registration
@app.route('/register', methods=['GET', 'POST'])
def register():
    form = RegisterForm(request.form)
    if request.method == 'POST' and form.validate():
        FirstName = request.form['FirstName']
        LastName = request.form['LastName']
        AccountId = request.form['AccountId']
        Birthdate = request.form['Birthdate']
        #password = sha256_crypt.encrypt(str(form.password.data))
        Home_Endpoint__c = request.form['Home_Endpoint__c']

        # Execute query
        sf.Contact.create({'LastName':LastName,'FirstName':FirstName,'AccountId':AccountId, 'Birthdate':Birthdate, 'Home_Endpoint__c':Home_Endpoint__c, 'Test_User__c':1 })
        
        flash('You are now registered', 'success')

    return render_template('register.html', form=form)


What I need is to catch/read the SF Dictionary JSON response with the new created Id as shown on the simple-salesforce examples section:
 
Record Management

To create a new ‘Contact’ in Salesforce:

sf.Contact.create({'LastName':'Smith','Email':'example@example.com'})

This will return a dictionary such as {u'errors': [], u'id': u'003e0000003GuNXAA0', u'success': True}
So I can keep working with the new registered member on other further processes.

I will appreciate if someone gives me a hand on this.
Neetu_BansalNeetu_Bansal
Hello Alejandro,

The syntax for the callback function is:
function callback(Error error, Array results, Object event) { // ... }
For more details, please refer to Salesforce documentation:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_remote_objects_using_create.htm

If it helps you, please mark it as best answer.

Thanks,
Neetu
Alejandro ValcarcelAlejandro Valcarcel
Neetu,

You are suggesting a JS function but I was looking for a Python code solution. Fortunately I already solved this. Thank you anyway.