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
Mahesh KGMahesh KG 

How to Attach a file to Account Object

Hi Team,

Can you please help me in attaching a file to the Account Object. 
i am able to create the account object with the below code i now need to attacha a file to the account object.

global with sharing class AccountManager {
    global static Account getAccountById() {
        RestRequest request = RestContext.request;
        // grab the caseId from the end of the URL
        String accountId = request.requestURI.substring(
        Account result =  [SELECT Name
                        FROM Account
                        WHERE Id = :accountId];
        return result;
    global static ID createAccount(String accountName,String accountOwner, String accountManager,String website,String companyCode,String atsOrHris, String accountSetUpFee,String accountStatus,String type,Decimal annualRevenue, Decimal annualAbRevenue, String revenueStream,String serviceLevelAgrmnt,String billingAddress,
    String shippingAddress,String billingStreet,String billingCity, String billingState,String billingZip,
                                   String billingCountry,
                                   String shippingStreet,String shippingCity, String shippingState,String shippingZip,
                                   String shippingCountry,String dunsNumber,String lineOfBus,String subType,String lastName) {
        Account restAcc = new Account(
                                      // need to test website url field Id
                                      Annual_AB_Revenue__c= annualAbRevenue,
                                      Revenue_Stream__c = revenueStream,
                                      ServiceLevelAgrmnt = serviceLevelAgrmnt,
                                      BillingCity= billingCity,
                                      ShippingCity= shippingCity,
        insert restAcc;
                                      // Account a = [select Id, Name from Account where Name = ''Shaik'];
                                       Contact c = new Contact();
                                       c.LastName = lastName;
                                       c.AccountId = restAcc.Id;
                                       insert c;
        return restAcc.Id;

    global static void deleteCase() {
        RestRequest request = RestContext.request;
        String caseId = request.requestURI.substring(
        Case thisCase = [SELECT Id FROM Case WHERE Id = :caseId];
        delete thisCase;
    global static ID upsertCase(String name,String parent, String accountMgr,String setUpFee,String vendorType,
                                   Decimal annualRevenue, Decimal annualAbRevenue, String revenueStream,
                                   String billingStreet,String billingCity, String billingState,String billingPostalCode,
                                   String billingCountry,
                                   String shippingStreet,String shippingCity, String shippingState,String shippingPostalCode,
                                   String shippingCountry) {
        Account restAccUpdate = new Account(
                                      Annual_AB_Revenue__c= annualAbRevenue,
                                      Revenue_Stream__c = revenueStream,
                                      BillingStreet=billingStreet,BillingCity= billingCity,BillingState=billingState,
                                      ShippingStreet=shippingStreet,ShippingCity= shippingCity,ShippingState=shippingState,
        // Match case by Id, if present.
        // Otherwise, create new case.
        upsert restAccUpdate;
        // Return the case ID.
        return restAccUpdate.Id;
    global static ID updateCaseFields() {
        RestRequest request = RestContext.request;
        String caseId = request.requestURI.substring(
        Account thisCase = [SELECT Id FROM Account WHERE Id = :caseId];
        // Deserialize the JSON string into name-value pairs
        Map<String, Object> params = (Map<String, Object>)JSON.deserializeUntyped(request.requestbody.tostring());
        // Iterate through each parameter field and value
        for(String fieldName : params.keySet()) {
            // Set the field and value on the Case sObject
            thisCase.put(fieldName, params.get(fieldName));
        update thisCase;
        return thisCase.Id;

Thanks and Regards
Khan AnasKhan Anas (Salesforce Developers) 
Hi Mahesh,

Greetings to you!

Please refer to the below links which might help you further with the above requirement.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Mahesh KGMahesh KG
Hi Khan,

i could not get much from the above links that you shared. Can you please help me more on this?

Thanks and Regards
Mahesh K G