Skip to main content
Grupo

Salesforce Developers Community

This Group is created for all Salesforce Users/Admins/Developers

I have added products and calculated quote using the below apex class:

public class CpqEditQuoteApi {

public static string editAPI(String quoteId, String productId, Integer quantity){

//get access token from custom setting

CPQ_Acess_Token__c ct = [Select name, Access_Token__c FROM CPQ_Acess_Token__c WHERE name = 'Access Token' LIMIT 1 ];

String Token = ct.Access_Token__c;

System.debug('Access token from custom setting ==> '+Token);

HttpRequest req = new HttpRequest();

req.setMethod('POST');

req.setEndpoint('https://<my instance>.my.salesforce.com/services/apexrest/SBQQ/ServiceRouter');

req.setHeader('Content-Type', 'application/json; charset=utf-8');

req.setHeader('Authorization', 'Bearer '+Token);

//set body with selected quoteid & productid

req.setBody('{"saver": "SBQQ.QuoteAPI.QuoteSaver", "model": "{\\\"record\\\":{\\\"attributes\\\":{\\\"type\\\":\\\"SBQQ__Quote__c\\\",\\\"url\\\":\\\"/services/data/v59.0/sobjects/SBQQ__Quote__c/' + productId + '\\\"},\\\"Name\\\":\\\"Q-00132\\\",\\\"Id\\\":\\\"' + quoteId + '\\\"},\\\"nextKey\\\":2,\\\"netTotal\\\":0.00,\\\"lineItems\\\":[{\\\"record\\\": {\\\"attributes\\\": {\\\"type\\\":\\\"SBQQ__QuoteLine__c\\\"},\\\"SBQQ__Product__c\\\": \\\"' + productId + '\\\",\\\"SBQQ__Quantity__c\\\":'+ quantity +' ,\\\"SBQQ__ConfigurationRequired__c\\\":true},\\\"productQuantityEditable\\\": true,\\\"productHasDimensions\\\": false,\\\"key\\\": 1,\\\"descriptionLocked\\\": false}],\\\"lineItemGroups\\\":[],\\\"customerTotal\\\":0.00}"}');

req.setTimeout(120000);

HttpResponse res = new Http().send(req);

System.debug(res.toString());

System.debug(res.getBody());

System.debug('res' + res);

System.debug('Response body: ' + res.getBody()); // debug response body

//Read Quote API

QuoteReader reader = new QuoteReader();

QuoteModel quoteModels = reader.read(quoteId);

System.debug('quoteModel: ' + quoteModels);

//Read Product

ProductReader reader1 = new ProductReader();

ProductModel product1 = reader1.read(productId,'01s2w00000N5qciAAB','USD');

System.debug('Product Model: '+product1);

//Add Product

List<ProductModel> productModels = new List<ProductModel>();

productModels.add(product1);

ProductAdder adder = new ProductAdder();

QuoteModel quoteWithProducts = adder.add(quoteModels, productModels, 0);

System.debug('Quote with Product: '+quoteWithProducts);

//Calculate quote API;

quoteModels.lineItems[0].record.SBQQ__Quantity__c = quantity;

QuoteCalculator calculator = new QuoteCalculator();

calculator.calculate(quoteModels, 'MyCallback');

//Update the quote with Response body

SBQQ__Quote__c quote = [SELECT Id, CPQ_API_Response__c FROM SBQQ__Quote__c WHERE Id =: quoteId];

quote.CPQ_API_Response__c = res.getBody();

update quote;

return res.getBody();

}

}

Now I want to add a bundle product with option how we can achieve this? What I need to change with my code to add bundle product with its options?

3 respuestas
0/9000
0/9000
0/9000

I'm trying to use the Analytics Download API to get a PNG of my dashboard, but I'm getting errors. If we can download Lightningdashboard from Analytics Download API?

1st The command I'm using:

https://[my_organization-dev].my.salesforce.com/analytics/download/dashboard/01Z5h000000BxkWEAS.png

Error: Received NOT_FOUND error from Pupparazzi. Error ID: 1980218671-91981 (-1458732327)The

2nd command I'm using:

https://[my_organization-dev].my.salesforce.com/analytics/download/lightningdashboard/01Z5h000000BxkWEAS.png

Error: Capture Exception

Invalid asset type.

 

When I use the analytical dashboard whose ID starts from 0F e.g. '0FK5h000001vRovGAE' I'm able to download the dashboard but I want to download my lightning dashboard from API.

I can download the dashboard image from the dashboard itself, but I'm looking for a way to do it through the API for automation purposes.

3 respuestas
  1. 19 ene 2024, 10:46

    Hi ,

     

    It doesn't seem to be compatible with the lightning dashboard.

    There is no description in the reference.

    Hi , It doesn't seem to be compatible with the lightning dashboard.There is no description in the reference.

0/9000
0/9000
0/9000

Hello,

I have built a approval process on case object. It is 3 Step Process. I want to capture the Approver Name and Comments in custom field from Case whenever it is approved by the respected user.

Can anyone help me find the solution.

@Salesforce Developers India@* Salesforce Developers *@Salesforce Administrators & Developers@Salesforce Developers Community 

2 respuestas
  1. Sumeet Negi (Eptura) Forum Ambassador
    9 mar 2023, 05:52
0/9000

Hello, I need help to cover the test coverage, until now it 52 percentage. #Salesforce Developer

@isTest 

public class UpdateAccountStatusSchedulerTest {

private static testMethod void testScheduler() {

        Test.startTest();

        List<id> accountIds = new List<id>();

        Account a = TestUtils.createAccount();

        accountIds.add(a.Id);

        Opportunity opty = TestUtils.createOpportunity(a);

        Opportunity opt1 = [select Id, AccountId from Opportunity where AccountId = :opty.AccountId]; 

        accountIds.add(opt1.AccountId);

        Contract crt = TestUtils.createContract(a);

        Contract c1 = [select Id, AccountId from Contract where AccountId = :crt.AccountId];

        accountIds.add(c1.AccountId);

        Task tk1 =  new task(whatid=a.Id,Priority='Normal',Priority__c='Normal',Subject='Dial',Createddate= system.now(),Status='Completed');

        insert tk1;

        Task tk = [select Id,AccountId,whatid from task where AccountId =: tk1.whatid ];{

            if(tk.AccountId != null && !accountIds.contains(tk.AccountId)) {

            accountIds.add(tk.AccountId);

        }

        }

        

         system.assertEquals(accountIds[0], tk.AccountId);

        Case c = new Case(Subject='TestCase', Status='Open', SuppliedName='Name', SuppliedCompany='Company',SuppliedPhone='1234567', SuppliedEmail='foo@example.com', 

                          Product__c='Qt', Platform__c='Windows XP',AccountId=a.id);

        insert c;

        Case c2 = [select Id,AccountId FROM Case where AccountId =: c.AccountId ];{

            if(c2.AccountId != null && !accountIds.contains(c2.AccountId)) {

            accountIds.add(c2.AccountId);

        }

        }

        system.assertEquals(accountIds[0], c2.AccountId);

        

       UpdateAccountStatusScheduler scheduler = new UpdateAccountStatusScheduler();

        scheduler.execute(null);

        Test.stopTest();

        system.assertEquals(3, accountIds.size());

        system.assertEquals(accountIds[0], opt1.AccountId);

        system.assertEquals(accountIds[0], c1.AccountId);

        } 

}

3 respuestas
  1. 7 ene 2023, 21:32

    To increase your test coverage, you can try the following:

    1. Add more test methods to your test class. Each test method should test a different code path or scenario.
    2. Make sure that your test methods are actually exercising the code you want to test. This means that you should be creating test data and calling methods or making assertions in your test methods.
    3. Make sure that your test methods are independent of each other. This means that each test method should set up its own test data and not rely on the data created by other test methods.
    4. Use the Test.loadData() method to insert test records into your org for your test methods to use. This can be more efficient than inserting records manually in your test methods.

    I hope this helps!

0/9000

Hello group members!

 

I warmly invite you to join the @* Salesforce Developers * community here on the Trailblazer Community. You are all very welcome!

 

@Hari Mittapalli @Sunanda Budati @Kamsala Vijay Kumar - just want to ensure you know of the other group! 

0/9000
0/9000