• Bhanu K N
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hi,
I am trying to update a record via API request, I have added everything as needed but I always end up getting a 404 error.
User-added imageI am getting the Object ID value from here:
User-added imageAny help is highly appreciated. 

Thank you. 
Hi all, 
I have created an apex class to simply fetch an account record based on ID and update its summary.
When I run the code from the Developer console > Debug > open execute anonymous window, it works as expected. But the same code in Apex class is not working.

I know the formatting of my class is correct because, In the same arrangement, the code to create a record works as expected when the class is triggered by the webhook linked to an external application. I even tried writing a separate class for updating, no luck.

The codes are quite simple really. Reference codes in the Apex documentation. 
 
@RestResource(urlMapping='/api/Webhooks/pushDetailsdemo/*')
global with sharing class webhook {
    @HttpPost
    global static void createRecord(){
        try{

 //To add records: This part Works fine whenever the class is triggered via webhook

            Account[] accts = new List<Account>();
            for(Integer i=0;i<1;i++) {
    	         Account a = new Account(Name='Created from VS Apex class=101');
    	         accts.add(a);
            }
            insert accts; 
           
//To update record: This part of the code works as expected when run from debug console. But, Not when the Apex class is triggered. 
        
            Account[] Update_accts = new List<Account>();
            List<Account> conList = [Select Name, AccountNumber from Account];
            for(Account act : conList) {
                if (act.AccountNumber == 'ABCD101') {
                    act.Name = 'New description: Updated from APEX CLASS';
  
                    Update_accts.add(act);
                  }
             }
        update Update_accts;

        } catch(Exception e){
            System.debug('Exception:'+e.getMessage());

        }

    }

}
Am I missing something here? Any assistance is appreciated. Looking forward to hearing from the community! (Excuse my clumsiness as I'm very new to salesforce).

Thank you 
Bhanu
 
Hi,
I am trying to update a record via API request, I have added everything as needed but I always end up getting a 404 error.
User-added imageI am getting the Object ID value from here:
User-added imageAny help is highly appreciated. 

Thank you. 
Hi all, 
I have created an apex class to simply fetch an account record based on ID and update its summary.
When I run the code from the Developer console > Debug > open execute anonymous window, it works as expected. But the same code in Apex class is not working.

I know the formatting of my class is correct because, In the same arrangement, the code to create a record works as expected when the class is triggered by the webhook linked to an external application. I even tried writing a separate class for updating, no luck.

The codes are quite simple really. Reference codes in the Apex documentation. 
 
@RestResource(urlMapping='/api/Webhooks/pushDetailsdemo/*')
global with sharing class webhook {
    @HttpPost
    global static void createRecord(){
        try{

 //To add records: This part Works fine whenever the class is triggered via webhook

            Account[] accts = new List<Account>();
            for(Integer i=0;i<1;i++) {
    	         Account a = new Account(Name='Created from VS Apex class=101');
    	         accts.add(a);
            }
            insert accts; 
           
//To update record: This part of the code works as expected when run from debug console. But, Not when the Apex class is triggered. 
        
            Account[] Update_accts = new List<Account>();
            List<Account> conList = [Select Name, AccountNumber from Account];
            for(Account act : conList) {
                if (act.AccountNumber == 'ABCD101') {
                    act.Name = 'New description: Updated from APEX CLASS';
  
                    Update_accts.add(act);
                  }
             }
        update Update_accts;

        } catch(Exception e){
            System.debug('Exception:'+e.getMessage());

        }

    }

}
Am I missing something here? Any assistance is appreciated. Looking forward to hearing from the community! (Excuse my clumsiness as I'm very new to salesforce).

Thank you 
Bhanu