How to add contact from a rails app to salesforce using restforce gem? - salesforce

I am using restforce gem to connect to salesforce api. I have successfully connected to it and initialised the client using username/password like below
client = Restforce.new :username => 'foo',
:password => 'bar',
:security_token => 'security token',
:client_id => 'client_id',
:client_secret => 'client_secret'
I am able to create Account in saleforce using the command that is given in gem docs
client.create('Account', Name: 'Foobar Inc.')
Now i want to know how to create contacts? I tried
client.create('Contact', Email: 'demo#example.com')
but it returns false.

I tried
client.create!('Contact', Email: 'demo#example.com')
which showed me the error that LastName is a required field as specified in the comment.
So the solution is to specify LastName also like shown below:
client.create('Contact', Email: 'demo#example.com', LastName: 'Bar')
Thanks and Happy Coding.

Related

Why is my Rich Presence not shown in Discord?

I am using discord-rich-presence (which uses discord-rpc under the covers) to set my Rich Presence from my Electron app.
It authenticates and submits the activity and in the Discord DevTools I can see my request to set my activity:
const client = require('discord-rich-presence')(clientId);
client.updatePresence({
state: 'slithering',
details: 'Doing something',
startTimestamp: Date.now(),
largeImageKey: 'default',
smallImageKey: 'default',
instance: true,
joinSecret: 'redacted',
});
I am doing everything correctly and I can see my Rich Presence in other games so RP is definitely working. What am I doing wrong?
Can see it in other games:

Updating model with GraphQL Mutation

I have been having trouble figuring out how to update a User with graphQL. The functionality I'm currently aiming for is for the user to be able to update their account/profile information. I have some things set up for the user like a bio field for their profile, and a profile picture field that's set up to take a URL and display that as their profile picture.
I have no problems when it comes to creating using graphQL. A user can sign up, log in, make posts, etc without issue. I can also update the User in regards to other models, for example, a new post pushes to the users Post data just fine.
I have not been able to figure out how to update a user directly though. Essentially I can get around this by creating a new model for "profile pic" and pushing that to the User, but that seems like it's just extra steps that might slow things down, as well as shortchanging myself being able to learn something new.
This is the User model. I have omitted a few fields due to the exact block of code being large, but this includes the "image" and "bio" fields (the fields I would like to update) as well as the reference to the Post model which I mentioned above that functions appropriately.
User.js
const userSchema = new Schema(
{
username: {
type: String,
required: true,
unique: true,
trim: true
},
email: {
type: String,
required: true,
unique: true,
match: [/.+#.+\..+/, 'Must match an email address!']
},
password: {
type: String,
required: true,
minlength: 8
},
image: {
type: String
},
bio: {
type: String,
maxLength: 500
},
posts: [
{
type: Schema.Types.ObjectId,
ref: 'Post'
}
],
},
Below is the mutation in Explorer, including the variables and the result.
Profile Pic Resolver
addProfilePic: async (parent, { image }, context) => {
if (context.user) {
const updatedUser = await User.findOneAndUpdate(
{ _id: context.user._id },
{ image: image },
{ new: true, runValidators: true }
);
return updatedUser;
}
throw new AuthenticationError('You need to be logged in!');
},
typeDefs.js (relevant only)
type Mutation {
addProfilePic(_id: ID!, image: String!): Auth
}
I notice that in the Explorer page it returns "null" for user with a 200 status. I am led to believe that means that it's not able to even access the "image" field on the user to be able to update it. When compared to my other mutations in regards to users, this is set up very similarly and I'm not sure what the difference is.
I feel like I am missing something very basic here in regards to being able to update. I haven't been able to find an update mutation example that works. Could anyone assist? My main questions would be:
Why does the mutation return "null" for user?
How can I set up my resolver to appropriately update information on an already-created object?
Thank you to anyone who is able to take a look and assist, I will be closely watching this post for replies and will update any other code someone may need to be able to assist. I've been stuck in regards to updating information for a long time, but my site is getting to the point where it's nearly ready and I need to tackle this updating issue in order to progress. Thank you!
Quick Edit: I want to add that "Auth" is referenced. The appropriate authorization headers are in place to retrieve the data. Just wanted to add that in as I highly doubt authorization has anything to do with this!
I have solved this issue and would like to leave the answer here for anyone who may find it useful.
In the mutation typeDefs, I changed the "Auth" to "User",
type Mutation {
addProfilePic(_id: ID!, image: String!): User
}
and then in the mutation itself, took away the user field like such:
mutation addProfilePic($_id: ID!, $image: String!) {
addProfilePic(_id: $_id, image: $image) {
_id
username
image
}
}
This has allowed the user to update their profile photo information. Hope this helps!

Where do I get user and pass for email form api setup?

I am trying to get this form working in Nextjs using 'React Hook Form'. So far I think everything is okay, but I need to know where to get the 'user' and 'pass' for the API to send the information in the form.
It is probably a stupid question but when learning how to get forms to work, all tutorials just explain how to console log the information to display it as an alert, which is not very helpful when trying to do it properly and get it working.
Hope someone can help me out, thanks
import nodemailer from 'nodemailer'
export default async (req, res) => {
const {name, surname, companyName, email, numberOfEmployees, message, consentimiento } = req.body;
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: process.env.user,
pass: process.env.pass
}
})
Looks like you're using Gmail as your mailing service?
To get this working you'll probably need to set up an app password with your gmail account - https://support.google.com/mail/answer/185833?hl=en

how secure is context in react?

How secure is the context in react, I want to created a user from front end and set his indicial status to demo . later on when the user make a payment his status will change , bottom line is how secure this logic is could someone come and modify the initial set status to 'premium' ? so he could skip the payment part ?
const Signup = async (email: string, password: string, userType: string) => {
await createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
setDoc(doc(db, 'Data', userCredential.user.uid), {
user: userType,
verifiedEmail: false,
status: 'demo',
createdAt: Timestamp.now(),
});
As a rule of thumb and especially for single page applications which are rendered on the client side: Data from and (with)in clients can't and shouldn't be trusted as a security measurement.
So consider the context as "not secure" and always rely on proper permission management on the server side - so the worst thing which can happen is that your client may see the "premium" menus, but can't get anything out of it since the server denies any action.

MEAN-stack mongoose, where do functions go?

So I'm fairly new to the mean-stack and I'm using mean.js as a framework.
Using Yeoman I've made a new CRUD module called groups. In a group I want to be able to have an owner, the user who made the group, and a collection of members. According to the mongoose docs I gave the GroupSchema the following structure:
var GroupSchema = new Schema({
name: {
type: String,
default: '',
required: 'Please fill Group name',
trim: true
},
created: {
type: Date,
default: Date.now
},
user: {
type: Schema.ObjectId,
ref: 'User'
},
members: [{type: Schema.ObjectId, ref: 'Member'}]
});
Now, when a group is created the only member will be the owner. I've got the following app structure:
Project:
- app (server side code)
- controllers
- models
- routes
- public (client side code)
- modules
- groups
-controllers
Where do I put the method to add the current user to a certain group? My best guess is that the controller should take care of that, but is it the server or the client side controller?
I wouldn't set it on the client or trust the client. Your server side create function should ignore members completely and just push the current user onto the members array.

Resources