• Siddharth Lakhotia
  • NEWBIE
  • 39 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 48
    Questions
  • 85
    Replies
Hi,

When I click on custom button  "Accept Ownerhsip" , it should change owner. 

Though the owner gets changed , but it gets refelted only after page is refreshed manually.

The logic of ownership change is implemented in Apex 
Hi,

I have an invoice module.

I want whenever invoices come from ERP system , it automatically sums up the value of Total Sum against a blanket no. and updates it on another object Invoice Details..

PS: I have already a trigger on Invoice details, sums up the value of Total Sum against a blanket no . , so whenever a sales rep selects a blanket no. against a project , the summed value of Total sum appears...

But sometimes invoice comes later in system , lets say after a month. In that case, I require whenever the invoice comes , it automatically updates the value on Invoice Details

How can it be done ? Do i need to write a trigger against it or a batch class will be required?
Hi,

I have a condition , where-in I am selecting a cushion no. , and the  amount corresponding to same cushion no. gets added.

So lets say, 

For Inquiry 1 , cushion no: 123 , Amount : 100
For inquiry 2  ,cushion no: 123 , Amount 200
For inquiry 3 , cushion no: 456 , Amount : 500

So, whenever, I choose, inquiry ( lookup on inquiry detail ) , the summed amount against cushion no. appears . so lets say , if I select cushion no. 123 , the amount comes to 300.

However, one problem that I face is , If a different invoice is again added , lets say If a user adds an invoice with cushion no. 123 , the sum gets added again, which is wrong. the first entry of cushion no. 123 sums up all the amount against cushion no. 123.

I want that if a cushion no entry is already selected, whenever a new entry against the same cushion no. is made , it should deleted the existing entry and just allow the new entry.

So , in future if there is an inqiury  with cushion no 123 and amount 400.

adding it , will show me only one entry and a total amont of 600.

Trigger against this logic is already made. I just need the deletion logic
Hi,

this query is showing an error : 

for(Project__c objProject : [SELECT Id,Name,(SELECT Id,Estimated_Value__c, Total_Actual_Sales__c 
                                            FROM Opportunities) FROM Project__c WHERE Id IN: set_Opportunity])

Opportunity is a child object to Project , and its a lookup relationship.

I am using this query in a trigger..  but getting below error

Didn't understand relationship 'Opportunities' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 14 column 33
Hi,

i need help in developing a trigger that calculates values from Parent Object Inquiry to child object Inquiry Details.

So every Inquiry record will have a field call  Cushion Number( this acts as a code) and Act Sales.

I need to capture information of sum of ActSales against a cushion number and store it in a child object field Actual Sales..

how can I achieve this ?

 
Hi ,

I have 2 objects Inquiry and Inquiry Details. 

On Inquiry I capture , 2 fields  : Cushion No. and Act. Sales 

Irrepsective of inquiry recrords, Cushion no. can be same . It acts like a code , and can have different Act. Sales against every inquiry.


so lets say
For Inquiry 1 , Cushion no : 123  , ActSales : 100

For Inquiry 2 , Cushion no : 123  , ActSales : 200

For Inquiry 3 , Cushion no : 123  , ActSales : 300

For Inquiry 4 , Cushion no : 456 , ActSales :  350

For Inquiry 5 , Cushion no : 456  , ActSales : 450

I have a lookup at inquiry details that looks up to the Inquiry object,

I need to pull in the blanket no. against the inquiry and sum of Act Sales against blanket number(Cushion No ; 123 Actual Sales :600, Cushion Number : 456 , Actual Sales : 800).

How can I achieve this logic via trigger.

I know the soql queries that can work for this.. But somehow having problem in cracking the logic for this one





 
Hi,

I have 2 objects Object A and Object B

Object B has a lookup to object A.

Object A has three fields  Aname , BNmber and ASales

Bnumber is a code and can have several values against it.

Bnumber 123        ASales 100

Bnumber 123        ASales 300

Bnumber 123        ASales 500

I need help in writting trigger on object B, that pulls sum of Asales against Bnumber ( 900 against 123 in this case) 

The sum of Asales against Bnumber should be stored in a field on Object B...

Post that I can rollup this object to Opportunity(master) and then the actual sales will appear on the opportunity
Hi,

I have 2 objects Object A and Object B

Object B has a lookup to object A.

Object A has three fields  Aname , BNmber and ASales

Bnumber is a code and can have several values against it.

Bnumber 123        ASales 100

Bnumber 123        ASales 300

Bnumber 123        ASales 500

I need help in writting trigger on object B, that pulls sum of Asales against Bnumber ( 900 against 123 in this case) 


The sum of Asales against Bnumber should be stored in a field on Object B.
Hi,

I have a field on Opportunity called Estimated Value. Its a blank text field. A user can come and enter the value in it

On opportunity products, I have a field called List Value 

I need help in writting a trigger to calculate list value of all the line items and rollup the sum to the estimated value field, if the field is not already filled. 

Can someone help me in writting one?
Hi,

I have written a trigger, where-in I am assigning Permission set to a user based on his roles.

if a user role name contains Sales Manager or Director, Permission set gets assigned to him at the time of Update and Insert.

When the userrole contains Executive , Permission Set gets Deleted automatically at the time of Update and Insert.

Can anyone help me in writting Test Class for the same.

 
Hi,

I have a situation , where-in I need to restrict the access to reports to specific Sales rep in salesforce.

However managers ( differed by roles ) can acesss. I need to give a permission set to users with manager roles.

How can I write an Apex trigger to assign permission set to get automatically assigned to a role or public group


 
Hi,

I have a scenerios, where in 1 account has several different Payment Terms(3 months, 6 months , 9 months)

Lets say

Account name : A ; Payment Terms : 3 months
Account name : A ; Payment Terms : 6 months
Account name : A ; Payment Terms : 9 months

However, 3 different records are created for the same in ERP System.

I require, when the data comes to the Salesforce, It should only maintain one record with Account A , and it maintains 3 enteries for payment terms, just a related list does.

Is this achievable ? If yes, Then How ?
Kindly explain


 
Hi,

I have a batch class running, which allocates sales rep based on the the zip code assigned.

My problem here is , It is running for one profile , but not running for other. .

Is there something in configuration , that I am missing ? Please advise 

 
Apex Trigger : 

trigger preventChangeOfAccountName on Order (before insert) {
    
    Map<String, String> mapSourceOrderIdToAccount = new Map<String, String>();
    
Profile p = [SELECT Id, Name FROM Profile WHERE Name LIKE 'Thailand%' OR Name LIKE 'System Administrator' LIMIT 1];
if(p.Id != UserInfo.getProfileId())
return;
    
for (Order obj : trigger.new){

        mapSourceOrderIdToAccount.put(obj.getCloneSourceId(), null);

    }

    for(Order objOrder : [Select id, AccountId from Order where id in : mapSourceOrderIdToAccount.keySet() Limit 5000]){

        mapSourceOrderIdToAccount.put(objOrder.id, objOrder.AccountId);

    }

     

    for (Order o : trigger.new){

       If  (o.isClone() && mapSourceOrderIdToAccount.get(o.getCloneSourceId()) <> o.AccountId)

       {

           o.addError('Account Name for Cloned records cant be changed');

       }

    }

}


Test Class : 

@isTest
public class preventChangeOfAccountNameTestClass {
    

    static testmethod void profileDetails(){
        
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
        
            User u = new User(Alias = 'standt', Email='standarduser@testorg.com', 
            EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', ProfileId = p.Id, 
            TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');
        
    }
    
    static testmethod void preventAccNameChange(){  
        
        

Account acc = new Account();
        acc.name='TestAccount1';
        insert acc;
Order ord = new Order();
           ord.AccountId = acc.Id;
           ord.EffectiveDate = System.Today();
          ord.EndDate = System.Today()+5;
        ord.Status = 'NA';
        ord.Offer_Status__c = 'Open';
       insert ord;
      
        try{
            
            Account objNewAc = new Account();
            objNewAc.Name = 'Test account record';
            insert objNewAc;

            Order objNewOrder = ord.clone(false, true);
            objNewOrder.AccountId= objNewAc.Id;
            insert objNewOrder;

        }
        catch(DMLexception e){
           Boolean expectedExceptionThrown =  e.getMessage().contains('Account Name for Cloned records cant be changed') ? true : false;
           System.AssertEquals(expectedExceptionThrown, true);
    }
}
}


However, It covers only 36% code.

 
Hi,

I need help in getting 100% code coverage for my trigger. Currently , I am able to acheve 75% code coverage.

Trigger:

trigger preventChangeOfAccountName on Order (before insert) {
    
    Map<String, String> mapSourceOrderIdToAccount = new Map<String, String>();

for (Order obj : trigger.new){

        mapSourceOrderIdToAccount.put(obj.getCloneSourceId(), null);

    }

    for(Order objOrder : [Select id, AccountId from Order where id in : mapSourceOrderIdToAccount.keySet() Limit 5000]){

        mapSourceOrderIdToAccount.put(objOrder.id, objOrder.AccountId);

    }

     

    for (Order o : trigger.new){

       If  (o.isClone() && mapSourceOrderIdToAccount.get(o.getCloneSourceId()) <> o.AccountId)

       {

           o.addError('Account Name for Cloned records cant be changed');

       }

    }

}


Test Class : 

@isTest(SeeAllData = false)
public class preventChangeOfAccountNameTestClass {

    static testmethod void preventAccNameChange(){

Account acc = new Account(name='TestAccount1');
        insert acc;
        Order ord = new Order(AccountId = acc.Id,
                              EffectiveDate = System.Today(),
                              EndDate = System.Today()+5,
                                 Status = 'NA',
                              Offer_Status__c = 'Open'
                              );
        insert ord;
        try{
            update ord;
        }
        catch(DMLexception e){
           System.assert(ApexPages.hasMessages(ApexPages.SEVERITY.ERROR));
    }
}
}


Test class is not able to cover for these 2 lines,

mapSourceOrderIdToAccount.put(objOrder.id, objOrder.AccountId);

o.addError('Account Name for Cloned records cant be changed');

can anybody tell me , how to do so...
 
 
@isTest(SeeAllData = false)
public class OwnerIdchangeTest {
    public static UserInformation__c userInfo;   
    
    static testmethod void OwnerIdChange()
    {
        userInfo = UserInformation__c.getOrgDefaults();
        Profile p = [SELECT Id FROM Profile WHERE Name='Indonesia - Local Admin'];
        User u = new User();
        u.Alias = 'standt';
        u.Email = 'standarduser@testorg.com';
        u.EmailEncodingKey = 'UTF-8';
        u.LastName = 'Testing';
        u.LanguageLocaleKey = 'en_US';
        u.LocaleSidKey = 'en_US';
        u.ProfileId = p.Id;
        u.TimeZoneSidKey = 'America/Los_Angeles';
        u.Username = 'standar123456duser@testorg.com';
        //u.Business_Unit__c = 'Weber';
        //u.Case_Owner__c = True;
      //  insert u;       
        
        
        u.Business_Unit__c = 'Weber';
        u.Case_Owner__c = True;

        
        UserInformation__c UInfo = new UserInformation__c();
        UInfo.Gypsum_User_Id__c = '0050k000000yLiy';
           UInfo.Weber_User_Id__c = '0050k000000yLiy';
        insert UInfo;
        
        
       List <UserInformation__c> userInfoUpdate = new List<UserInformation__c>([select Id,Weber_User_Id__c,Gypsum_User_Id__c from UserInformation__c where Id =: UInfo.Id]);
        
        Test.startTest();
        for(UserInformation__c UI : userInfoUpdate)
        {
            UI.Weber_User_Id__c = u.Id;
            
            userInfoUpdate.add(UI);
        }
        
            
        
        //u.Business_Unit__c = 'Weber';
        //u.Case_Owner__c = True;
        //update u;  
        update userInfoUpdate;  
        
        Test.stopTest();       
    }    
}

Hi,
I am getting error mentioned in subject line while running the test class. Any solution on this
Hi,

I am facing the error mentioned in subject line , when trying to create a test class for a trigger. can somenone tell me , how do I solve this error

@isTest(SeeAllData = false)
public class OwnerIdchangeTest {
    public static UserInformation__c userInfo;   
    
    static testmethod void OwnerIdChange()
    {
        userInfo = UserInformation__c.getOrgDefaults();
        Profile p = [SELECT Id FROM Profile WHERE Name='Indonesia - Local Admin'];
        User u = new User();
        u.Alias = 'standt';
        u.Email = 'standarduser@testorg.com';
        u.EmailEncodingKey = 'UTF-8';
        u.LastName = 'Testing';
        u.LanguageLocaleKey = 'en_US';
        u.LocaleSidKey = 'en_US';
        u.ProfileId = p.Id;
        u.TimeZoneSidKey = 'America/Los_Angeles';
        u.Username = 'standar123456duser@testorg.com';
        //u.Business_Unit__c = 'Weber';
        //u.Case_Owner__c = True;
      //  insert u;       
        
        
        u.Business_Unit__c = 'Weber';
        u.Case_Owner__c = True;

        
        UserInformation__c UInfo = new UserInformation__c();
        UInfo.Gypsum_User_Id__c = '0050k000000yLiy';
           UInfo.Weber_User_Id__c = '0050k000000yLiy';
        insert UInfo;
        
        
       List <UserInformation__c> userInfoUpdate = new List<UserInformation__c>([select Id,Weber_User_Id__c,Gypsum_User_Id__c from UserInformation__c where Id =: UInfo.Id]);
        
        Test.startTest();
        for(UserInformation__c UI : userInfoUpdate)
        {
            UI.Weber_User_Id__c = u.Id;
            
            userInfoUpdate.add(UI);
        }
        
            
        
        //u.Business_Unit__c = 'Weber';
        //u.Case_Owner__c = True;
        //update u;  
        update userInfoUpdate;  
        
        Test.stopTest();       
    }    
    /*static testmethod void ChangeOwnerId()
    {
        userInfo = UserInformation__c.getOrgDefaults();
        Profile p = [SELECT Id FROM Profile WHERE Name='Indonesia - Local Admin'];
        User u = new User();
        u.Alias = 'standt';
        u.Email = 'standarduser@testorg.com';
        u.EmailEncodingKey = 'UTF-8';
        u.LastName = 'Testing';
        u.LanguageLocaleKey = 'en_US';
        u.LocaleSidKey = 'en_US';
        u.ProfileId = p.Id;
        u.TimeZoneSidKey = 'America/Los_Angeles';
        u.Username = 'standar123456duser@testorg.com';
        //u.Business_Unit__c = 'Weber';
        //u.Case_Owner__c = True;
        insert u;
       List <User> userlst = new List<User>([select Id,Business_Unit__c,Case_Owner__c from User where Id =: u.Id]);
       List<User> lstUserUpdate = new List<User>();
        Test.startTest();
        for(User user: userlst)
        {
            user.Business_Unit__c = 'Gypsum';
            user.Case_Owner__c = True;
            user.Id = u.Id;
            lstUserUpdate.add(user);
        }
        //u.Business_Unit__c = 'Weber';
        //u.Case_Owner__c = True;
        //update u;  
        update lstUserUpdate;  
        Test.stopTest();
                
    }*/

}
Hi,

I want to write a trigger, which throws error message , when the accountname is changed from the cloned version of record.

I have tried writting code, somehow its not working

Can someone help

Please find the code below : 

trigger PreventChangeOfAccountName on Order (before update , after insert) {
    
    for (Order o : trigger.new){
        
       If  (o.isClone() && trigger.oldmap.get(o.Id).AccountId <> trigger.oldmap.get(o.Id).AccountId)
       {
           o.addError('Account Name for Cloned records cant be changed');
       }
    }
}  
HI,

I need to write an apex trigger, that restricts the account name field on the orders object to be changed, after the record has been cloned.

Can somebody help me with this
Hi,

This change pertains to the Orders object.

It has an account name lookup field on it. Once the order is validated or reduced, user gets the option to clone the record. 

The idea behind cloning is to create a duplicate offer copy under same account.

Hoeever, After cloning, user sometimes end up doing regression and change the account name. I am tryinf to put a validation rule , that helps me restrict the change , But i want it to work , once once the order is cloned.

Below is the validation rule written. Please propose changes if any?

AND( 
ISCLONE(), 
NOT(ISNEW()), 
PRIORVALUE(AccountId) <> "", 
ISCHANGED( AccountId) 
)

Do I need an Apex trigger for the same
Hi,

When I click on custom button  "Accept Ownerhsip" , it should change owner. 

Though the owner gets changed , but it gets refelted only after page is refreshed manually.

The logic of ownership change is implemented in Apex 
Hi,

I have an invoice module.

I want whenever invoices come from ERP system , it automatically sums up the value of Total Sum against a blanket no. and updates it on another object Invoice Details..

PS: I have already a trigger on Invoice details, sums up the value of Total Sum against a blanket no . , so whenever a sales rep selects a blanket no. against a project , the summed value of Total sum appears...

But sometimes invoice comes later in system , lets say after a month. In that case, I require whenever the invoice comes , it automatically updates the value on Invoice Details

How can it be done ? Do i need to write a trigger against it or a batch class will be required?
Hi,

this query is showing an error : 

for(Project__c objProject : [SELECT Id,Name,(SELECT Id,Estimated_Value__c, Total_Actual_Sales__c 
                                            FROM Opportunities) FROM Project__c WHERE Id IN: set_Opportunity])

Opportunity is a child object to Project , and its a lookup relationship.

I am using this query in a trigger..  but getting below error

Didn't understand relationship 'Opportunities' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 14 column 33
Hi,

i need help in developing a trigger that calculates values from Parent Object Inquiry to child object Inquiry Details.

So every Inquiry record will have a field call  Cushion Number( this acts as a code) and Act Sales.

I need to capture information of sum of ActSales against a cushion number and store it in a child object field Actual Sales..

how can I achieve this ?

 
Hi ,

I have 2 objects Inquiry and Inquiry Details. 

On Inquiry I capture , 2 fields  : Cushion No. and Act. Sales 

Irrepsective of inquiry recrords, Cushion no. can be same . It acts like a code , and can have different Act. Sales against every inquiry.


so lets say
For Inquiry 1 , Cushion no : 123  , ActSales : 100

For Inquiry 2 , Cushion no : 123  , ActSales : 200

For Inquiry 3 , Cushion no : 123  , ActSales : 300

For Inquiry 4 , Cushion no : 456 , ActSales :  350

For Inquiry 5 , Cushion no : 456  , ActSales : 450

I have a lookup at inquiry details that looks up to the Inquiry object,

I need to pull in the blanket no. against the inquiry and sum of Act Sales against blanket number(Cushion No ; 123 Actual Sales :600, Cushion Number : 456 , Actual Sales : 800).

How can I achieve this logic via trigger.

I know the soql queries that can work for this.. But somehow having problem in cracking the logic for this one