I want to get my visualforce page apex code through rest API. I tried metadata API like /services/data/v41.0/sobjects/{sobjectName}/describe/layouts and I am able to access fields information but I want to access apex code of the page where define all fields and triggers.
Any guidance would be appreciated. Thanks
You can get the body of Apex classes (that aren't part of managed packages) from a query on the ApexClass standard object:
curl \
-H 'X-PrettyPrint: 1' \
-H 'Authorization: Bearer <session-id>' \
https://ap4.salesforce.com/services/data/v43.0/tooling/query?q=SELECT+Body+FROM+ApexClass+LIMIT+1
Visualforce pages can be retrieved similarly through a query on the ApexPage standard object to retrieve the Markup:
curl \
-H 'X-PrettyPrint: 1' \
-H 'Authorization: Bearer <session-id>' \
https://ap4.salesforce.com/services/data/v43.0/tooling/query?q=SELECT+Markup+FROM+ApexPage+LIMIT+1
For more information on available standard fields and objects to query, check out the Object Reference
You have to make 2 api calls i.e. first to get vf page code and second to get controller code.
IF testing on workbench, use end point url as:
/services/data/v43.0/tooling/query?q=select+id,ControllerKey,Markup+from+apexpage+where+name='<pagename>'
Response will give you controller name in ControllerKey node.
Now, next call Apex class using end point as:
/services/data/v43.0/tooling/query?q=select+id,body,name+from+apexclass+where+name='<ControllerKey value>'
If apex class is used as extensions then you have to parse the markup from first response to get the class name.
Let me know if you need more detail.
Related
I have an assignment.
I need to send to different contacts the participants associated with it using visualforce template in pdf format.
I know how send email to different recipients, but i dont know how to send with different text. When I do SOQL in my controller I have List of List (Contacts and Participants) but how send to different contacts with different text body i dont know
Visualforce email template can't have an apex controller like say a vf page. BUT it can include a vf component - and that component can have controller and accept parameters!
It's bit trickier than usual because you'd need to move some logic to getter but it's doable. Make a component, pass to it "related to.Id" or something and it'll work
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_email_templates_with_apex.htm
https://salesforce.stackexchange.com/q/245930/799
There's my ancient answer https://salesforce.stackexchange.com/q/4303/799 if you're still stuck, overcomplicated for what you need but hey, gives some ideas.
Remember that each such email + component + controller will count to limit of soqls. If it uses 1 query (gimme participants for this contact id) - that's max 100 emails in single transaction.
I have relational DB and a file info to post in it.
DB provides 3 entities holding ForeignKey in some attributes.
Entities are:
File, WorkFile and WorkFileStage
My issue is, when I post info of specific file, I must post on those endpoints, but e.g. WorkFile holds attribute file = ForeignKey(File) - it's an id filed. Which makes me POST all the File data, then GET it for acquring IDs, then POST on WorkFile with those IDs.
THIS IS A LOT OF POSTINGGETINGITERATINGANDPROMISING (as my request are done with axios on react).
What I've tried, is for POST data construct object with just a file=file_name, then search it in the DB on the Django side and serialize.save(). But POST requires pk rather than str for foreignKeys.
With this though process I ended up with:
axios.post().then(axios.get().then(axios.post(then))))
Is there any easy/good practice way of doing it?
Django's POST view can accept whatever you want. As for querying your models via related model properties, check the official documentation: https://docs.djangoproject.com/en/3.1/topics/db/queries/#lookups-that-span-relationships
In your case it should be something like this:
def my_post_view(request, file_name):
try:
work_file = WorkFile.objects.get(file__name=file_name)
except WorkFile.DoesNotExist:
raise Http404
...
where file_name is passed as a part of your endpoint URL.
If I want to display many posts in my web application but every post have its own type and I want to display each type in single page so, What's the best method to do that? Is put all all posts in one url and use query string to filter the posts upon the type and display it in the page?
For example : axios.get('/posts?type =sport')
Or I have to put every single type in separate Url
For example: axios.get('/posts/sport')
Also one more question please?
use one reducer to manage every posts or create one reducer for each post type?
you can add a dynamic route to every new type.
Ex:
'/transaction' -> component-1
'/transaction/:type' -> component-any (multiple)
welcome to Stackoverflow!
I can imagine you have a web API of some sort serving a URL /posts. You want to consume that endpoint from your web application, and you are using axios to do that. I can assume you are using JSON to return that data. Correct me if I'm wrong.
Now that the basic information is "clear", what data you serve from the endpoint, and how it is requested from the client is up to you. Do you want to ask the server what types are there first, and then do one AJAX request per type? Ok. Do you want to serve all posts independent of their type? Ok. Do you want to accept POST data in your controller so you can filter the results before returning a response? Ok.
If you are looking for a more specific answer, you must give more details, or specify more. But I hope I could be of help.
Edit: complete answer.
If you want to filter the results, you have to send some additional data in your POST request, in this case, your post type. In axios, this could be done like this:
axios.post('https://example.com/posts', {
type: 'sports'
}).then((data) => {
console.log(data);
});
You can obviously get the "type" value from a select input, other variable, even the current router page. I don't know your exact setup, but you can always come back and ask ;)
THEN, in your API controller you have to get that POST parameter type, and use it to filter the results. Again, I don't know your exact setup, but for MySQL if would be a WHERE statement in your query, or similar.
I have a Dart application that's getting data from a custom Google endpoint. I'm using discoveryapis_generator to generate the client library. I would like to issue a query like the following:
import endpoints_api.dart as EndpointsApi;
api = new EndpointsApi.MyApi();
api.photos.list(api.Photo.post_id == "post1");
endpoints_api.dart is the client library generated by discoveryapis_generator generate.dart. MyApi is my custom endpoints API, and photos is one of its services. I think Photo is an endpoints model class which has an instance property post_id.
Issuing the request results in an error to the effect that Photo has no static getter "post_id". This is close to how to the syntax of a query in the Python API, so it was the only way I could think of to specify it here.
I don't know what else might be helpful in describing my request. Hopefully it is self-evident. There's an active enhancement described here, but it seems to refer to limiting the fields, rather than items, in the response.
Update:
Poking around in the client library, I found the source for the list methods. It certainly looks like query parameters are supported. But it seems to me that it's not entirely correct. The formal parameter list contains the query parameters specified in the API surrounded by braces:
async.Future<PhotoCollection> list({core.String postId, core.String regionId}) {...
But in the method body, there's the following:
if (regionId != null) {
_queryParams["region_id"] = [regionId];
Are the brackets in [regionId] to extract region from the parameter list?
I pulled the braces out of the parameter list. Since I only ever expect to query by postId, that's the only parameter:
async.Future<PhotoCollection> list(core.String postId) {...
Voila. I can now add a parameter to the query by just specifying its value in the call:
api.photos.list("post1");
If you wrap the parameters of a method in curly braces, you make them optional.
So you can still use your method with the given signature. You just have to add the name of the parameter you want to pass:
api.photos.list(postId: "post1");
I'm attempting to upload a photo to Facebook via the Graph API on a test user account for my app. With just the url, link, name parameters present, the upload works fine returning a valid photo id.
However, if I use the additional tags parameter, I end up with the following error returned:
{
"error": {
"message": "(#100) param tags must be an array.",
"type": "OAuthException",
"code": 100
}
}
I've tried to provide the value for tags in almost every possible way I can think of, as I know the Graph API isn't straightforward (even the parameter url which is used to upload a photo from a URL isn't listed under the photo Graph API method);
A single user id
tags=100003919104407
Multiple CS'd user ids
tags=100003919104407,100003919104408,100003919104409
Array with ids not as integers
tags=[100003919104407, 100003919104404,100003919104405]
Array with ids as strings
tags=["100003919104407", "100003919104404","100003919104405"]
Array containing objects, as per the Facebook Graph API documentation
tags=[{"id":"100003919104407"},{"id":"100003919104404"},{"id":"100003919104405"}]
If someone could tell me the right format/another parameter through which to pass user ids in order to have them tagged in a photo, I'd be very grateful.
Try this
It should be in this format
[{"to":"100003919104407","x":0,"y":0},
{"to":"100003919104408","x":10,"y":10},
{"to":"100003919104409","x":20,"y":20}]
or
[{"tag_uid":"100003919104407","x":0,"y":0},
{"tag_uid":"100003919104408","x":10,"y":10},
{"tag_uid":"100003919104409","x":20,"y":20}]
Where did you get your information from? Have you check the tags section?
Create
You can create a tag on the photo by issuing an HTTP POST request to
the tags connection, PHOTO_ID/tags.
Note: This feature is intended to help users tag their friends in real
photos. You should not use this feature to encourage users to tag
their friends if their friends are not actually in that photo, or to
tag friends in composite photos. If your app is found to be
encouraging this behavior, your usage of this feature may be disabled.
You can specify which user to tag using two methods: in the URL path
as PHOTO_ID/tags/USER_ID, or in a URL parameter as
PHOTO_ID/tags?to=USER_ID. To add several tags at once, you can specify
a tags property which contains an array of tags like so
PHOTO_ID/tags?tags=[{"id":"1234"}, {"id":"12345"}]. Currently, you
cannot tag a Page in a photo using this API.
There's also an example.
the X and Y value of array need to be %, not in pixels
Example 1 (wrong)
img:(640,480) xy:(320,240)
[{tag_uid:user_id,x:320,y:240}] <- wrong, because 320 > 100%
Example 2 (right)
img:(640,480) xy:(320,240) px:(320,240) < %
[{tag_uid:user_id,x:50,y:50}] <- right, because 50 < 100%