• Jeevana Priyanka B
  • NEWBIE
  • 5 Points
  • Member since 2018


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 8
    Replies

I am getting the bellow error message while checking the Apex web service challenge not sure why and even created a new playground but no luck any help is greatly appreciated below is the code.

Error message in Trailhead: "Executing the 'AccountManager' method failed. Either the service isn't configured with the correct urlMapping, is not global, does not have the proper method name or does not return the requested account and all of its contacts."

Apex class:
@RestResource(urlMapping='/Accounts/*/Contacts')
global with sharing class AccountManager{

   @HttpGet
    global static Account getAccount(){
        RestRequest request = RestContext.request;
        String accId = request.requestURI.substringBetween('/Accounts/','/Contacts');
        Account acc = [SELECT Id, Name,(SELECT Id, Name FROM Contacts) FROM Account WHERE Id =: accId LIMIT 1];
        return acc;
}
  
}
Apex test class:
@isTest
private class AccountManagerTest{
    @isTest
     static void testGetAccount(){
        Id recordId = createTestRecord();
         
        Contact con = new Contact(LastName = 'Con', AccountId = recordId);
        insert con;
        Contact con1 = new Contact(LastName = 'Con1', AccountId = recordId);
        insert con1; 
                
        RestRequest request = new RestRequest();
        request.requestURI = 'https://XXXX.salesforce.com/services/apexrest/Accounts/'+recordId+'/Contacts';
        request.httpMethod = 'GET';
        restContext.request = request;
        
        Account thisAcc = AccountManager.getAccount();        
    } 
    static Id createTestRecord(){
        Account acc = new Account(Name = 'Test Acc');
        insert acc;
        return acc.Id;
    }
}

Thank you in advance.
How to refresh a lightning web component when a record is edited.

For Eg: If I have lightning web component (Account details) on Contact when I edit a contact how does the LWC will get refreshed.

Any help is greatly appreciated.

I am new to Aura components and LWC, I am trying to create a Custom component
for eg I have 2 objects Account and Case I have custom component when a search for an account that account should update on the account name of the case details and retrieve few fields of the Account. Please advise how I can do it using Aura Component.

 

Currently I am able to get the Accounts using Lightning RecordEditForm.

Thank you in advance.

Task[] restoreTaskOwner = new Task[0];
for(Task task : [SELECT Id, OwnerId, CustonField__c FROM Task Where WhatId IN :changedOwnerIds AND IsClosed = FALSE AND CustonField__c<> null]){
if (task.OwnerId <> tak.CustonField__c) {
                task.OwnerId = task.CustonField__c;
                restoreTaskOwner.add(tsk); } }
Apex class: 
Task
Public class taskTrigger{
public static void Task(){
        for(Task t: (List<Task>) Trigger.new){
             t.Custom_ownerText_field__c = t.OwnerId;
}
}
}
Case
public class caseClass{
    public static void syncTaskOwner( Map<Id, SObject> oldParents, Map<Id, SObject> newParents ){
            Set<Id> changedOwnerIds = new Set<Id>();
            // Identify all Parents that have a changed Owner
            for( SObject parent : newParents.values() ){
                SObject oldParent = oldParents.get((Id)parent.get('Id'));
                
                if( parent.get('OwnerId') <> oldParent.get('OwnerId') ){
                    changedOwnerIds.add((Id)parent.get('Id'));
                }
            }
            
            // Find all the tasks (repeat for Events if required) that are not closed for the parent records that had new Owners
            List<Task> restoreTaskOwner = new List<Task>();
            
            // revert the owner on the found tasks
            for(Task tsk : [SELECT Id, OwnerId, Custom_ownerText_field__c  FROM Task Where WhatId IN :changedOwnerIds AND IsClosed = FALSE AND Last_Assigned_User__c <> null]){
                System.debug('tsk.OwnerId..' + tsk.OwnerId);
                System.debug('tsk.Custom_ownerText_field__c ..' + tsk.Last_Assigned_User__c);
                if (tsk.OwnerId <> tsk.Custom_ownerText_field__c ) {
                    tsk.OwnerId = tsk.Custom_ownerText_field__c ;
                    restoreTaskOwner.add(tsk);
                }
            }
            if(!restoreTaskOwner.isEmpty())
            update restoreTaskOwner;
        }
}

I have created 2 different test classes both has 0% code coverage.
Test Class
Test Class 1:
@isTest
public class TestClass1{
    @isTest
    static void TestM1(){
        Account acc = new Account(Name = 'Test Acc');
        Insert acc;
        Case ca = new Case(Name__c= 'Test', origin = 'web', Status = 'New');
        Insert ca;
        Task ta = new Task();
        ta.Type = 'Email';
        ta.Status = 'New';
        ta.Description = 'Test SA';
        ta.OwnerId = userinfo.getUserId();
        ta.WhatId = ca.Id;
        ta.Custom_ownerText_field__c = userinfo.getUserId();
        Insert ta;
        
        Profile p = [SELECT Id FROM profile WHERE Name = 'System Administrator'];
        User u = new User(ProfileId = p.Id , Alias = 'Test', Username = 'Test', Email='Test@Test.com', EmailEncodingKey = 'UTF-8', LastName= 'Test', 
                          LanguageLocaleKey = 'en_US', LocaleSidKey = 'en_US', TimeZoneSidKey='America/Los_Angeles');
        ta.ownerId = u.Id;
        update ta;
        ca.ownerId = u.Id;
        update ca;
    }
}
Test Class 2:

@isTest
public class TestClass2{
@TestSetup
    static void setup(){
        Account newAcct = new Account(
            Name = 'Test'
        );
        insert newAcct;
        
        Case newCase = new Case(
            Subject = 'test'
            , Status = 'new'
        );
        insert newCase;
        
        Task newTsk = new Task(
            //WhatId = newAcct.Id
            WhatId = newCase.Id
            , Subject = 'Test'
        );
        insert newTsk;
    }
    
    @IsTest
    static void syncTaskOwnerTest(){
        Task[] existingTasks = [
            SELECT Id, OwnerId, Custom_ownerText_field__c , WhatId
            FROM Task
            Where IsClosed = FALSE AND Custom_ownerText_field__c <> null
        ];
        System.assert( existingTasks.size() == 1, existingTasks );
        System.assertEquals( existingTasks[0].Custom_ownerText_field__c , UserInfo.getUserId() );
        System.assertEquals( existingTasks[0].Custom_ownerText_field__c , existingTasks[0].OwnerId );
        
        User[] usr = [SELECT Id FROM User WHERE IsActive = true AND Id != :UserInfo.getUserId() LIMIT 1];
        
        Test.startTest();
        update new Case(
            Id = existingTasks[0].WhatId
            , OwnerId = usr[0].Id
        );
        Test.stopTest();
        
        existingTasks = [
            SELECT Id, OwnerId, Custom_ownerText_field__c , WhatId
            FROM Task
        ];
        Account acct = [SELECT Id, OwnerId FROM Account LIMIT 1];
        system.assertEquals( usr[0].Id, acct.OwnerId );
        System.assert( existingTasks.size() == 1, existingTasks );
        System.assertEquals( existingTasks[0].Custom_ownerText_field__c , UserInfo.getUserId() );
        System.assertEquals( existingTasks[0].Custom_ownerText_field__c , existingTasks[0].OwnerId );
    }
}

Plese let me know if you have any questions.

Thank you in advance!

I have PDF File and i want that PDF file to be shown on every record and must be able to edit.

for example: Assume i have custom button related to evrey custom object record when rep clicks on that button it should open that pdf page and user must be able to save and edit the pdf file related to that record how can achieve this in salesforce Lightning.

I am new to custom developing. any help is greatly appreciated.

Thank you!

On changing the Owner filed from Queue to user it should the status of a custom object.

I am using the process builder with the below formula
AND(

ISCHANGED([Custon_Object].OwnerId),

OR(
[Custon_Object].OwnerId = $User.Id,
AND( LEFT(PRIORVALUE([Custon_Object].OwnerId),3) = '00G', LEFT([Custon_Object].OwnerId,3) = '005' )
)

)

I am getting the following error while activating it.
Your changes are saved, but you can't activate this process until you resolve the following errors.
The formula expression is invalid: Formula result is data type (Boolean), incompatible with expected data type (Text).
The formula expression is invalid: Formula result is data type (Boolean), incompatible with expected data type (Text).

Please help, Thank you in advance
 

I am new to Aura components and LWC, I am trying to create a Custom component
for eg I have 2 objects Account and Case I have custom component when a search for an account that account should update on the account name of the case details and retrieve few fields of the Account. Please advise how I can do it using Aura Component.

 

Currently I am able to get the Accounts using Lightning RecordEditForm.

Thank you in advance.

Apex class: 
Task
Public class taskTrigger{
public static void Task(){
        for(Task t: (List<Task>) Trigger.new){
             t.Custom_ownerText_field__c = t.OwnerId;
}
}
}
Case
public class caseClass{
    public static void syncTaskOwner( Map<Id, SObject> oldParents, Map<Id, SObject> newParents ){
            Set<Id> changedOwnerIds = new Set<Id>();
            // Identify all Parents that have a changed Owner
            for( SObject parent : newParents.values() ){
                SObject oldParent = oldParents.get((Id)parent.get('Id'));
                
                if( parent.get('OwnerId') <> oldParent.get('OwnerId') ){
                    changedOwnerIds.add((Id)parent.get('Id'));
                }
            }
            
            // Find all the tasks (repeat for Events if required) that are not closed for the parent records that had new Owners
            List<Task> restoreTaskOwner = new List<Task>();
            
            // revert the owner on the found tasks
            for(Task tsk : [SELECT Id, OwnerId, Custom_ownerText_field__c  FROM Task Where WhatId IN :changedOwnerIds AND IsClosed = FALSE AND Last_Assigned_User__c <> null]){
                System.debug('tsk.OwnerId..' + tsk.OwnerId);
                System.debug('tsk.Custom_ownerText_field__c ..' + tsk.Last_Assigned_User__c);
                if (tsk.OwnerId <> tsk.Custom_ownerText_field__c ) {
                    tsk.OwnerId = tsk.Custom_ownerText_field__c ;
                    restoreTaskOwner.add(tsk);
                }
            }
            if(!restoreTaskOwner.isEmpty())
            update restoreTaskOwner;
        }
}

I have created 2 different test classes both has 0% code coverage.
Test Class
Test Class 1:
@isTest
public class TestClass1{
    @isTest
    static void TestM1(){
        Account acc = new Account(Name = 'Test Acc');
        Insert acc;
        Case ca = new Case(Name__c= 'Test', origin = 'web', Status = 'New');
        Insert ca;
        Task ta = new Task();
        ta.Type = 'Email';
        ta.Status = 'New';
        ta.Description = 'Test SA';
        ta.OwnerId = userinfo.getUserId();
        ta.WhatId = ca.Id;
        ta.Custom_ownerText_field__c = userinfo.getUserId();
        Insert ta;
        
        Profile p = [SELECT Id FROM profile WHERE Name = 'System Administrator'];
        User u = new User(ProfileId = p.Id , Alias = 'Test', Username = 'Test', Email='Test@Test.com', EmailEncodingKey = 'UTF-8', LastName= 'Test', 
                          LanguageLocaleKey = 'en_US', LocaleSidKey = 'en_US', TimeZoneSidKey='America/Los_Angeles');
        ta.ownerId = u.Id;
        update ta;
        ca.ownerId = u.Id;
        update ca;
    }
}
Test Class 2:

@isTest
public class TestClass2{
@TestSetup
    static void setup(){
        Account newAcct = new Account(
            Name = 'Test'
        );
        insert newAcct;
        
        Case newCase = new Case(
            Subject = 'test'
            , Status = 'new'
        );
        insert newCase;
        
        Task newTsk = new Task(
            //WhatId = newAcct.Id
            WhatId = newCase.Id
            , Subject = 'Test'
        );
        insert newTsk;
    }
    
    @IsTest
    static void syncTaskOwnerTest(){
        Task[] existingTasks = [
            SELECT Id, OwnerId, Custom_ownerText_field__c , WhatId
            FROM Task
            Where IsClosed = FALSE AND Custom_ownerText_field__c <> null
        ];
        System.assert( existingTasks.size() == 1, existingTasks );
        System.assertEquals( existingTasks[0].Custom_ownerText_field__c , UserInfo.getUserId() );
        System.assertEquals( existingTasks[0].Custom_ownerText_field__c , existingTasks[0].OwnerId );
        
        User[] usr = [SELECT Id FROM User WHERE IsActive = true AND Id != :UserInfo.getUserId() LIMIT 1];
        
        Test.startTest();
        update new Case(
            Id = existingTasks[0].WhatId
            , OwnerId = usr[0].Id
        );
        Test.stopTest();
        
        existingTasks = [
            SELECT Id, OwnerId, Custom_ownerText_field__c , WhatId
            FROM Task
        ];
        Account acct = [SELECT Id, OwnerId FROM Account LIMIT 1];
        system.assertEquals( usr[0].Id, acct.OwnerId );
        System.assert( existingTasks.size() == 1, existingTasks );
        System.assertEquals( existingTasks[0].Custom_ownerText_field__c , UserInfo.getUserId() );
        System.assertEquals( existingTasks[0].Custom_ownerText_field__c , existingTasks[0].OwnerId );
    }
}

Plese let me know if you have any questions.

Thank you in advance!

I have PDF File and i want that PDF file to be shown on every record and must be able to edit.

for example: Assume i have custom button related to evrey custom object record when rep clicks on that button it should open that pdf page and user must be able to save and edit the pdf file related to that record how can achieve this in salesforce Lightning.

I am new to custom developing. any help is greatly appreciated.

Thank you!

Hello,

 

I am wrote this really simple trigger to stop the changing of the ownership of open activities.  Whenever account owner changes in SF, it changes all of the open activitiy owners of tasks to the new owner of the account.   We don't want that to happen.  Here's my code:

 

 

trigger StopTaskOwnerChange on Task (before update) {

    List<Task> updateTask = new List<Task>();
    
        for(Task t : trigger.new){
            if(t.ownerId != t.CreatedById)
                updateTask.add(t);
        }
        
        for(Task t : updateTask){
        t.ownerId = t.CreatedById;
        }

 


I am thinking this problem with this is probably has to do with timing of the execution of the trigger.  I know salesforce automatically changes all of the activity ownership automatically, and I am wondering if I'm firing my trigger before salesforce automatically changes the Owners so it looks the owner is not changing.