Variable value for Amount for Salesforce opportunity API - salesforce

I'm working on a Magento website. In that, after the customer is done with adding products to the cart he fills a form and once the form is submitted, form data along with product details like SKU, price is sent to Salesforce to create a new opportunity.
The API is working and the Data is going to salesforce, but the issue is that the same product can have different prices based on certain conditions.
the new amount going to salesforce but on the salesforce side, the new amount is not reflecting but the amount when the product is created for the first time is coming.
is there any way to make the amount a variable field so the new amount reflects?
below is an image of the opportunity and the JSON data I'm sending.
{"StageName":"New Opportunity","Name":"test","CloseDate":"2021-06-04","What_are_you_interested_in__c":"Purchase New Trailer","Product_JSON__c":"[{\"Name\":\"Large Trailers\",\"Sku\":\"large-trailers-rent\",\"Quantity\":1,\"Price\":\"1301.0400\"}]","Purchase_Delivery_Contact_Phone__c":"123","On_Site_Contact_Email__c":"test-12#test-12.com","Mailing_Street__c":"test-12","Delivery_Street__c":"","Qty__c":"1","X66969__c":0,"First_Name__c":"test-12","Last_Name__c":"test-12"}

This request looks weird. Vanilla Salesforce doesn't need hacks like a text field to hold serialised JSON in it (Product_JSON__c).
Where do you send it? Normal POST to something like services/data/v51.0/sobjects/Opportunity or some custom endpoint (it'd have "/apexrest" in the URL). Even if it goes to normal endpoint - I guess there's trigger that deserialises this Product_JSON__c and creates OpportunityLineItems out of it. You'll have to chat with developer responsible for that trigger, we can't tell what's going on in there.
In general yes, it's possible to have variable prices. You (or that developer) have to read up about OpportunityLineItem. There's ListPrice,UnitPrice,TotalPrice,Discount, lots of choices to do this right and report properly on the discounts! And there are tips like
Creating an OpportunityLineItem increments the Opportunity Amount
value by the TotalPrice of the OpportunityLineItem
There are ways to do it properly, insert header (Opportunity) and line items in one go, without such hacks. See
https://salesforce.stackexchange.com/questions/155422/using-the-rest-api-to-create-parent-and-child-records-in-a-single-http-request
https://salesforce.stackexchange.com/questions/274694/can-you-upsert-using-composite-sobject-tree
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_sobject_tree.htm

Related

WordPress : make categories automatically match according to external API Value

I'm managing a company website, where we have to display our products. We however do not want to handle the admin edit for this CPT, nor offer the ability to access to the form. But we have to read some product data form the admin edit page. All has to be created or updated via our CRM platform automatically.
For this matter, I already setup a CPT (wprc_pr) and registered 6 custom hierarchical terms: 1 generic for the types (wprc_pr_type) and 5 targeting each types available: wprc_pr_rb, wprc_pr_sp, wprc_pr_pe, wprc_pr_ce and wprc_pr_pr. All those taxonomies are required for filtering purposes (was the old way of working, maybe not the best, opened to suggestions here). We happen to come out with archive pages links looking like site.tld/generic/specific-parent/specific-child/ which is what is desired here.
I have a internal tool, nodeJS based, to batch create products from our CRM. The job is simple: get all products not yet pushed to the website, format a new post, push it to the WP REST API, wait for response, updated CRM data in consequence, and proceed to next product. Handle about 1600 products today on trialn each gone fine
The issue for now is that in order for me to put the correct terms to the new post, I have to compute for each product the generic type and specific type children.
I handled that by creating 6 files, one for each taxonomy. Each file is basically a giant JS object with the id from the CRM as a key, and the term id as a value. My script handles the category assertion like that:
wp_taxonomy = [jsTaxonomyMapper[crm_id1][crm_id2]] // or [] if not found
I have to say it is working pretty well, and that I could stop here. But I will have to take that computing to the wp_after_insert_post hook, in order to reaffect the post to the desired category on updated if something changed on the CRM.
Not quite difficult, but if I happen to add category on the CRM, I'll have to manually edit my mappers to add the new terms, and believe me that's a hassle.
Not waiting for a full solution here, but a way to work the thing. Maybe a way to computed those mappers and store their values in the options table maybe, or have a mapper class, I don't know at all.
Additional information:
Data from the CRM comes as integers (ids corresponding to a label) and the mappers today consist of 6 arrays (nested or not), about 600 total entries.
If you have something for me, or even suggestions to simplify the process, I'll go with it.
Thanks.
EDIT :
Went with another approach, see comment below.

Salesforce Screen flow search and display record information

I'm working on a screen flow. The idea is to have a lookup component the user can search a contact. Then I would like to display the information from the Contact (Account Name, Contact Name, Number Email) and I would like to be able to have the user update that information if needed. I just stomped on how it can be done. I know it should be able to be pulled from the record ID in some type of way and maybe use an Assignment to display the information. Can someone guide me on a next step or if anyone has an instructional video would be helpful.
Thanks
You wouldn't be able to display the looked up contact's fields on that screen as soon as you populate that field. That would be something only possible in code (aura component or lwc).
What you can do, however is -
Get Record element after that screen element. (Get Contact, where Id = lookupcomponent.recordId)
Then EITHER:
use the new Fields (BETA) option on another screen Fields (BETA)
(this method is easier, doesn't have as much control and is limited on fields, depending on data type, you can use)
add inputs one by one and set the default values Add Fields One By One
(this method allows more control)
Then, you will need an update element. If you used the Fields (BETA) you can just update the record variable. If you did the inputs one by one, you will need to update the contact and set fields individually.
Full Flow Example

Firestore Data Modelling ( Users and Problems)

I am working on a web app for doing certain problems. The database is firestore.
The feature I want to ask is that on a page, there will show {x}/{y},
where x is the number of problems the user completed, and y is the total number of problems, something like 6/10.
Sample image
My doubt is how to design data model to achieve this feature. I already have users collection and problems collection. My thought is choosing one of them, but feeling none of them is good practice:
A. Adding user_response field in each problem doc, which means if there are 1000 users, each problem needs to add 1000 users' responses. It is also hard for new users coming.
B. Quite like A but adding problems_response into user doc.
C. Adding a new collection repsonses which has problem_id, user_id fields.
I am new to NoSQL, thanks for your help.
I added the database structure in the following images:
database-1
database-2
database-3
database-4
database-5

Low resolution Email Preview in Salesforce for marketing cloud connect emails

Question about Marketing Cloud Connect - In case of Individual Email Result in Salesforce, an email preview is sent from MC to SF object along with a thumbnail preview of the email template (as base64 encoded image). This thumbnail has two problems.
a. isn’t clear enough for the sales agent to see what was sent to customer
b. can’t find what offer percentage was given to customer as the preview has ampscript value instead of actual value.
There is no way to change the default configs of MCC to increase the thumbnail size. To solve this and improve the image resolution, I’ve thought of below solutions. Is there any other possible way that you’ve done?
From customer send log, take ‘view_email_url’ and get the html using a visual force page and remove all the ‘https://click…xx.com/’ links to ensure click/ open counts aren’t impacted. Downside - # of api calls to make are higher
For every email, create a jpg preview of the email template and store it in MC and store this in SF in a custom object as ‘EmailName vs EmailPreviewUrl’. And, whenever a marketer creates a new email, they have to ensure that they create a jpg copy in MC and update associated record in Saleforce custom object. Downside - sales agent will not know what % of offer is given to customer (ps - % of offer is decided in MC automation based on raw order information we’ve about this customer). To manage this downside, we can send the offer details of each customer to SF using updateSingleSalesforceObject method everytime an email is sent. To do this, all the campaigns should be standardized to some extend.
Any other thoughts? is there any configs that I can flip to increase the image size?
To answer this question, we ended up creating a cloudpage code resource (similar to API) that returns the complete HTML of 'view_email_url' (aka view as web page) for a given email + Subscriber + datesent + BU. We used SSJS to query sendLog DE using these inputs to figure out the view_email_url value. To avoid counting view_email_url opens to tracking opens, we wrapped the open counter pixel inside a context variable - something like below.
%%[
IF _messagecontext != 'VAWP' THEN
]%%
<custom name="opencounter" type="tracking" />
%%[ ENDIF ]%%

Outputting Stripe plan name via plan-ID using AngularJS ng-model two-way data binding

I am outputting form inputs on the final page of a checkout field, titled "Review & checkout"... on this page I display the plan the customer picked and the personal info they provided so far.
I have no problem showing fields like Name or Email, as the value inputted is being shown, as Angular displays whatever was in the value="" field of the input.
To display the subscription plan that the customer picked, it's trickier.
The value field is already being utilized to tell stripe which plan the customer should be charged for.
How can I get around this problem?
I am able to display the stripe-id for the plan but it is not user-friendly. They are id's like trad-2-5, trad-2-6, trad-2-7... so what I want to do is display a custom title when trad-2-5 is selected, and so on...
Any help is greatly appreciated!!Thanks
There are a couple of ways you could do this.
The really silly answer is that you can just create a map of plan ids to human-readable descriptions in the Angular controller code, then display that. This might be enough for what you want, but it's also pretty hacky, and not a lot of fun to maintain.
The less silly answer depends on where these plan ids are coming from. If they are coming from an endpoint on your server, which gets them from Stripe's plans endpoint, then you could also pass along the display name of the plan from that endpoint. If the plan id's are hard coded somewhere, or whitelisted, then this may not make sense. However, that display name is what will appear on the customer's invoice, and credit card statement, so it'd be nice to make it match up with what they see on the checkout page.

Resources