• SUCHARITA MONDAL
  • NEWBIE
  • 494 Points
  • Member since 2015


  • Chatter
    Feed
  • 16
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 102
    Replies
Hello everyone. I created a flow today using the flow builder flowId=30129000000ULTsAAO and added the flow to the lightning page layout. My question is there a way to instead of adding the flow to the page layout could you add a button to the page layout instead to execute the flow see the image I am gathering two pieces of information
User-added image 
Happy New Year everyone.
Need some assistance with my class.  Trying to get the SOQL queries outside the for loop if possible.  But in teh query I am using the Id as a filter.  Any thoughts? 
if( Trigger.isInsert ){
            List<Id> docIds = new List<Id>();
            List<String> parentIds = new List<String>();

            for( Attachment__c record : ( List<Attachment__c> ) Trigger.new ){
                Id docId = record.ContentDocumentId__c;
                    parentId = record.Parent_ID__c ;
                    Id recId = Id.valueOf(record.Parent_ID__c ); 
                    String parentObjectType = String.valueOf( recId.getSObjectType());
                        if( parentObjectType == 'Activity__c' ){
                           list<Activity__c> actparentId = [Select id,Project__r.Cust__c  from Activity__c WHERE Id =: parentId];   
                           for(Activity__c act :actparentId){
                                parentId = act.Project__r.Cust__c;
                            }
                        }
                        
                        if( parentObjectType == 'Project__c' ){
                           list<Project__c> projparentId = [Select Cust__c from Project__c WHERE Id =: parentId];   
                           for(Project__c proj :projparentId){
                                parentId = proj.Cust__c;
                            }
                        }
                        
                        if( docId != null ){    
                            docIds.add( docId );
                        }
            }

            List<ContentDocumentLink> linkList = [ SELECT Id, ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN: docIds ];
            if( !linkList.isEmpty() ){
                for( ContentDocumentLink link : linkList ){
                    List<ContentDocumentLink> links = this.linkMap.containsKey( link.ContentDocumentId )
                        ? this.linkMap.get( link.ContentDocumentId ) : new List<ContentDocumentLink>();
                    links.add( link );
                    this.linkMap.put( link.ContentDocumentId, links );
                }
            }
        
        }

 
can any one explain what is programming elements and how data abstraction can be imlemented in salesforce explain with the example?
Any user scenarios for data abstraction?

here apex code 
global with sharing class schedularCloseAllDealsMonthAgo implements Schedulable{
      global void execute(SchedulableContext sc) {  
            closeAllDealsMonthAgo closeDeals = new closeAllDealsMonthAgo(); 
            database.executebatch(closeDeals);
      }
      public static void schedulerMethod(){
            schedularCloseAllDealsMonthAgo sched = new schedularCloseAllDealsMonthAgo();
            string con_exp= '0 0 10 * * ?';
            System.schedule('schedularCloseAllDealsMonthAgo', con_exp, sched);
      }
}
This is code of test but not work for 100%
@isTest   
public class schedularCloseAllDealsMonthAgoTest {
    public static testMethod void testschedule() {
        Test.StartTest();
            schedularCloseAllDealsMonthAgo sched = new schedularCloseAllDealsMonthAgo();
            String CRON_EXP = '0 0 23 * * ?';
            System.schedule('schedularCloseAllDealsMonthAgo', CRON_EXP, sched);
        Test.stopTest();
    }
}
Hi All,

Im writing a test class for batch apex that will be scheduled to run on the first of each month.  Were testing it here, but i keep running into this error at line 25 "System.QueryException: List has no rows for assignment to SObject".  I dont know why that list would be blank.  Can anyone advise? thanks/
 
public class TouchSalesDatasTest {
	@isTest
    public static void Test() {
        Map<ID,Sales_Data__c> SDMap = new Map<ID,Sales_Data__c>();
        Account Acc = TestDataFactory.createAccount('TouchSalesDataTest EU ', 'desiredrecordtypeid', null, null, true);
        Account Dist = TestDataFactory.createAccount('TouchSalesDataTest Dist ', 'desiredrecordtypeid', null, null, true);
        for (Integer i = 0; i < 200; i++) {
            Sales_Data__c SD = new Sales_Data__c(End_User__c = Acc.ID,
                                                 Distributor__c = Dist.Id,
                                                 Amount__c = i,
                                                 Quantity__c = i,
                                                 Date__c = System.today().addDays(-25),
                                                 Product__c = 'desiredproductid');
            SDMap.put(SD.Id,SD);
        }
        insert SDMap.values();
        
        Decimal expectedValue = System.today().addDays(-25).daysBetween(System.today())/31;
        
        Test.startTest();
        TouchSalesDatas t = new TouchSalesDatas();
        Database.executeBatch(t);
        Test.stopTest();
        
        Sales_Data__c UpdatedTest = [SELECT ID,Name,Months_Ago__c FROM Sales_Data__c WHERE ID IN :SDMap.keySet() Limit 1];
        System.assertEquals(Math.round(expectedValue), UpdatedTest.Months_Ago__c);
    }
}

 
I entered a contact in the Name and Attendees field and now I want to be able to make sure that if I deleted a Contact from the name field it gets removed from the Invitees field and vise versa. To make this happen, I did an IF statement to check if the value of isParent == false OR isInvitee == false. This works for the isParent == false, but it doesn't seem to catch it if the isInvitee == false. Can anyone help me on why 'OR' is not working and have any suggestions on how to make this work? Thanks.

if (trigger.isUpdate){ List<EventRelation> erLst = [SELECT EventId, RelationId, isParent, isInvitee FROM EventRelation where EventId IN :sEvents ]; for(EventRelation sObj: erLst ){ if (sObj.IsParent == false || sObj.IsInvitee == false ){ delete sObj; } else{ sObj.IsParent = true; sObj.IsInvitee = true; UpdatedLst.add(sObj); update UpdatedLst; } } }
  • May 09, 2020
  • Like
  • 0
Hi all - we don't use accounts in my installation, yet the reports all need an Account or the Contacts don't show up.

It is easy enough to update all existing contacts with AcctID=Individual, but how can I set it up so any new Contact has default of Individual account?

Please don't say "make Account required field and make them pick Individual".. I want it to default.

Thank you!
Hello, we have a trigger on Lead that creates a Contact based on 2 fields from the Lead . After the Contact is inserted, we want to turn the Lead field that contains the name of the Contact to turn into a hyperlink with a link to that Contact record. I built a trigger, but it is not working, and I am not sure why not. Can someone please help. Here is the trigger:

trigger ContactsTrigger on Contact (after insert) {
     // add mobilephone to set and assign id variable
    Set<String> contactNumSet = new Set<String>();
    Id newConId;
    for (contact c : trigger.new){
        if (c.mobilephone != null){
            newConId = c.id;
            contactNumSet.add(c.mobilephone);
        }
    }
 //query related lead   
 List<Lead> refsToInvestigate = new List<Lead>();       
 List<Lead> refsToUpdate = new List<Lead>();  
 String nok1;
    refsToInvestigate = [select emergency_contact_phone__c from Lead where emergency_contact_phone__c = :contactNumSet];    
        for (Lead ref : refsToInvestigate){
                nok1 = ref.NextofKin__c; }
    
    for (Lead refer : refsToInvestigate){
                refer.nextofkin__c =  '<a href=https://centers--partial.lightning.force.com/'+newConId+'>'+nok1+ '</a>' ;
        refsToUpdate.add(refer);  } 
         update refsToUpdate;

}
global class AgeUpdate implements Database.Batchable<sObject> {

    global Database.QueryLocator start(Database.BatchableContext bc)

    {

    return Database.getQueryLocator([SELECT dateOfBirth__c,Id,Status FROM Lead WHERE Status = 'Unqualified' AND dateOfBirth__c = TODAY]);

   }

     global void execute(Database.BatchableContext bc, List<Lead> scope)

   {

      for(Lead l: scope)

        {

            l.Age__c = l.Current_Age__c;

        }

            update scope;
       
    }
    
     global void finish(Database.BatchableContext bc)
     {}

}
 
Hello,

I have created an apex class to count the number of textpost in a case but my code doesn't not iterate...
Could someone help?
Thanks
public class FeedItemTriggerHandler {
    public static void countFeedItem(List<FeedItem> lstFeed){ 
        set<id> relatedCasesIds = new set<id>();
        for(FeedItem fd : lstFeed) {
            if (fd.type =='TextPost')relatedCasesIds.add(fd.ParentId);
        }
        Map<Id, case> relatedCases = new Map<Id, case> ([Select id, caseNumber,All_Users_Feed_Count__c FROM case where id in: relatedCasesIds]);
       	List<case> casesToUpdate = new List<case>(); 
        
        integer count = 0;
        for(case c:relatedCases.values()) {
           for(FeedItem fd : lstFeed) {
               if (fd.type =='TextPost' && fd.Visibility =='AllUsers' && fd.ParentId == c.id) {
                   count+=1;
                   
               } 
       		 } 
            c.All_Users_Feed_Count__c = count;
            count = 0;
            casesToUpdate.add(c);
              
        }
        if(casesToUpdate.size() > 0) update casesToUpdate; 
    }
}

 
Hi guys,

I've created a custom screen flow and I want to add it to a community page, launched from a custom button on the Homepage. 
The flow guides users through creating a case. I am getting the following error when I add the component to the page: "Action failed: c:CustomCaseCommunityComponent$controller$init [flowData is not defined]"

This is my component. 

<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes,force:hasRecordId,force:lightningQuickActionWithoutHeader" access="global">

    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    <lightning:flow aura:id="flowData"/>
    
</aura:component>


({
init : function (component) {
var flow = component.find(flowData);
flow.startFlow(CaseFlow);
},
})
Hello All,

I am trying to write a trigger to update a parent object field when its child record is added/updated. I am quite new to Salesforce Apex and tried to read a few posts in the forum and still could not get it working. Any thoughts on this is appreciated. Thank you!

Example:
Parent Object: Sales_Event__c
Field to update: Cost_Item_Update__c
Child Object: Sales_Event_Cost_Item__c (Master-Detail(Sales Event))
Sales_Event_ID__c = Sales_Event__r.Id (I’m not too sure if there is proper way to get Sales_Event ID in Sales_Event_Cost_Item__c so I create a new formula field here which I think may not be necessary though..)
Fields to be CONCATENATED: Cost_Items__c and  Quantity__c
So I would like to get below in my Parent Object:
e.g. Sales Event A has 2 Cost items,
Cost_Item_Update__c = “Cost_Item one (Quantity__c), Cost_Item two (Quantity__c)”
But my Cost_Item_Update__c  even can’t get the Cost_Items__c (Cost_Item one, Cost_Item two iteration) right.. I am wondering if I map the objects incorrectly...
trigger TestSalesEventCostItemUpdate on Sales_Event_Cost_Item__c (after insert, after delete, after update) {

    list<id> parentIDstoUpdate = new list<id>();
    if(Trigger.isInsert||Trigger.isAfter||Trigger.isDelete ){
            for (Sales_Event_Cost_Item__c co : Trigger.new) {
                parentIDstoUpdate.add(co.Sales_Event__c);       
            } 
    }

    map<id,string>  mapParentIdtoString = new Map<ID,String>();
    string str;

    for (Sales_Event_Cost_Item__c co: [SELECT Sales_Event_ID__c, Cost_Items__c from Sales_Event_Cost_Item__c WHERE Sales_Event_ID__c =:parentIDstoUpdate ]){
        if(mapParentIdtoString.containsKey(co.Sales_Event_ID__c)){
            str = mapParentIdtoString.get(co.Sales_Event_ID__c);
            str = str + ';' + co.Cost_Items__c;  
            mapParentIdtoString.put(co.Sales_Event_ID__c,str);
        }else{
            mapParentIdtoString.put(co.Sales_Event_ID__c,co.Cost_Items__c);
        }
    }
    
    list<Sales_Event__c> recordstoUpdate = new list<Sales_Event__c>();
    for (Sales_Event__c p: [SELECT ID, Cost_Item_Update__c FROM Sales_Event__c WHERE id =:recordstoUpdate ]){ 
        p.Cost_Item_Update__c = mapParentIdtoString.get(p.id);
        recordstoUpdate.add(p);
    }

    if (recordstoUpdate != null && recordstoUpdate.size()>0){
        update recordstoUpdate;
    }
}
Good morning all. I have a trigger that creates new records related to opportunities.

I have everything working but my loop and i am stuck. I am very new to coding and would really appreciate some assistance.

This iwhat I have so far and everything works...except....
                            //while loop create record process                     	
              				decimal counter = 0;
              				while (counter < opportunityList.Quarters_Spanned_op__c)
                			{
                                
                			Open_Quarter__c oq           = new Open_Quarter__C();
                			Quarter_Number__c qn		 = new Quarter_Number__c();
                			oq.Amount_Per_Quarter_oq__c  = opportunityList.Amount_per_Quarter_op__c;
                			oq.Close_Date_oq__c          = opportunityList.CloseDate;
                			oq.Name            			 = opportunityList.Quarter_Created_op__c;
                			oq.Opportunity_Name_oq__c    = opportunityList.Id;
                			oq.Quarters_Spanned_oq__c    = opportunityList.Quarters_Spanned_op__c;

							createOpenQuarter.add(oq);
                			counter++;
          					
                            }//end while loop                                             
When I create each new record I need it to populate a field in that record with escalating quarter names. Right now it creates the right nimber of records but they all have the same quarter name in them which the starting quarter of the opp.

Now I have four custom formula fields in the opp that I can use.
  • One with the name for the quarter when the opp was created in this format: 2019-Q1 etc
  • One with the year the opp was started as a number "2019"
  • One with the starting quarter as a number (1-4)
  • One with the number of quarters the opp spanse based upon the created and close dates also expressed as a number.
I was told that I can loop the quarters within the year so that if an opp ovewrlaps years i can increment the rear number and reset the quarter to one and continue the loop for the same number of times as the quarters spanned (I already have that part)

But the rest is all very new to me. How do I build these nested loops with an output for each iteration that looks like this "2019-Q1" that I can use in creating my new records.

I am really stuck here so any help at all will be greatly appreciated.
Best regards,
Steve
 
Hi All.  Long Time admin but Very new to apex and developing.  I have a child object for accounts "sales data" which essentially is just transactional line items of purchases (related to the distributor, and the account).  So now I want to have a trigger on the sales data object that takes the sum of the amt in last 45 days by account then by distributor.  So that i can update the primary & secondary relationship on the account to indicate the distributor that is doing the most and second most sales for that account respectively.  below is what i have so far.  Please take a look and help out with getting thsi to run, and also how do i bulkify this??  Thanks guys!
 
trigger DistributorIDs on Sales_data__c (after insert, after update) {
       Date AfterDate = Date.today().addDays(-45);
       List <Account> AccountsList = new List<Account>();
    For (Sales_data__c Sd: Trigger.new) {
        AccountsList.add(Sd.End_user__r);
    } 
       Set<Account> DeDupSet = new Set<Account>();
       List<Account> DeDupAccounts = new List<Account>();
       DeDupSet.addAll(AccountsList);
       DeDupAccounts.addAll(DeDupSet);
    For (Account Acc: DeDupAccounts) {
        List<AggregateResult> Distributors = [SELECT Distributor__c, SUM(Amount__c) FROM Sales_Data__c 
                                    WHERE Date__c >= :AfterDate AND End_user__c = :Acc.Id
                                    GROUP BY Distributor__c ORDER BY SUM(Amount__c) LIMIT 2];
        ID FirstPosition = (ID)Distributors[0].get('expr0');
        ID SecondPosition = (ID)Distributors[1].get('expr1');
        Acc.Acct_Primary_Distributor__c = FirstPosition;
        Acc.Acct_Secondary_Distributor__c = SecondPosition;
    }
    update DeDupAccounts;
}

 
Hi everybody,

I am trying to access subquery field which is in a list.
ex: List<Account> newList = new List<Account>([Select Name,phone,(Select name,phone from Contacts)  from Account]);
In the above code the values can be accessed for account by using "newList.Name". But when i try to access contacts of that account i.e.(newList.Contacts.name).It is giving me error.

So,is there any way to access the subquery(Contacts) field values.

Thanks.
I have a trigger that creates records related the opportunity that fires the trigger.

I need to add a step that will delete any of these existing records if the close date is updated.

Each opp will have one or more of these related records.

How do i identify / list these records and delete them?

I think I have my conditionals all set up the way I need them. i just need to identify them and delete them.

Any suggestions out there?
Steve

Hi All,
Did anyone faced such error as below:

INVALID_TYPE: sObject type 'CaseComment' is not supported in describeCompactLayouts.

I'm getting above error in Lightning, while clicking on Case comment on Case record.

P.S. Any help/direction is appreciated.

Thanks,
Sucharita

 

here is the controller code..

({
    doClose : function(component, event, helper) {
        var recid = component.get("v.recordId");
        var urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({
            "url": "/"+recid
        });
        urlEvent.fire();
        
    },
    handleSubmit : function(component, event, helper) {
        component.find("recordEditForm").submit();
        
        var payload = event.getParams().response;
        debugger;
        console.log(payload.id);
    }
})

Hey..

We want to track the email and links that how many time email is opened and links are clicked and that to by using tracking pixel.
Could anybody help that how can we create tracking pixel in Salesforce it is as same as salesforce embeds when email is fired using email templates and tracks are updated which can be shown at HTML Email Status related list.

Thanks..

Hello,

We have some custom code that is used to create a case that works on standard apps but breaks when it is used with an app that has a Console view.

When attempting to save our record from this custom window, an error appears:

'No access to field ws. Either the field was removed from the entity or access to this field was removed.'

'ws' is not a field on our object, and I think that error message is just the result of bad URL parsing. 

We have an Apex function RequestAccount() that generates the URL, and this URL needs to be updated to work with Lightning Console apps, but we are having difficulty finding the instructions on how to do so for our case.

This is the current way we currently prepend the URL string:

String urlString = '/one/one.app#/n/RecordCreatePage?';

According to this article (https://help.salesforce.com/articleView?id=release-notes.rn_general_new_url_format_lex.htm&type=5&release=214) the one.app segment needs to be adjusted to something with "lightning", but for our particular case the syntax is not clear.

Can anyone provide assistance on the change we need to make to fix this operation on console apps?

Thanks
Chris Minotti
Hi,

I have a scenario where I need to paste one single value from a flow to an apex class and run a query and return the result back to the flow to be used as a picklist choice. The code below does not work sufficiently. Can anyone advice?

public class ProductArrangementCollection {
    @InvocableMethod(Label='Terms' description='Insert Terms value')    
    public static List<ID> FindProductArrangement(List<string> Terms) {
        List<ID> Ids = new List<ID>();
        Product_Arrangement__c c = [Select id from Product_Arrangement__c where Actual_start_date__c = 'Terms' limit 10];
        if(c != null) { 
            Ids.add(c.Id);
        }
        return Ids;
    }
}
Hi Every one,

when i am executing test class i am geeting the error like below can any one help me . 

Error message 
System.DmlException: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 1 records: 
Hello everyone.
I am not a Salesforce developer but have some basic knowledge on SOQL and Apex Triggers.  I need help from someone on an Apex trigger.  We'd like to update a checkbox field on Account object when there is a File that starts with "DA" that is added/attached to the specific account record.  is this doable?  any help will be greatly appreciated.  thank you.
I have custom object mycustobj__c
and in this object have custom field custfield__c  this null now
mycustobj__c contains 200+ records
requirment is to fill custfield__c such way that each record have serial no
ex- 1st record mm-01
      2nd record mm-02.

.......
and so on


Thanks for the input!....
Hi, I want to redefine and remove nested for loop and fix couple of issues with below code,

My Method:
------------
public void buildQueueInfo(List<Group> queues, Map<Id, List<GroupMember>> queueIdToMembersMap, List<User> allUsers, Map<Id, User> userMap) {

        for (Group queue : queues) {
            List<GroupMember> gmList = new List<GroupMember>();
            gmList = queueIdToMembersMap.get(queue.Id);
            List<User> nonUsers = new List<User>();

            for (User u : allUsers) {
                Boolean notAMember = true;
                if (gmList != null) {
                    for (GroupMember gm : gmList) {
                        if (u.Id == gm.UserOrGroupId) {
                            notAMember = false;
                        }
                    }
                }
                if (notAMember) {
                    nonUsers.add(u);
                }
            }

            populateQueueInfo(queue, gmList, nonUsers, userMap);
            //To Reduce heap size
            queues=null;
            //allUsers=null;
            gmList=null;
        }
        
    }


your help in this regrads would be greatly appreciates.

Thanks!!
Jagadeesh. M
Hi. I am writing a report on a custom object. 
I have an issue with creating the report 

mu records have quantity and status 
I want to get a summary of each record in different statuses. 
How it can be done? 

report on custom object
Hello everyone. I created a flow today using the flow builder flowId=30129000000ULTsAAO and added the flow to the lightning page layout. My question is there a way to instead of adding the flow to the page layout could you add a button to the page layout instead to execute the flow see the image I am gathering two pieces of information
User-added image 
Happy New Year everyone.
Need some assistance with my class.  Trying to get the SOQL queries outside the for loop if possible.  But in teh query I am using the Id as a filter.  Any thoughts? 
if( Trigger.isInsert ){
            List<Id> docIds = new List<Id>();
            List<String> parentIds = new List<String>();

            for( Attachment__c record : ( List<Attachment__c> ) Trigger.new ){
                Id docId = record.ContentDocumentId__c;
                    parentId = record.Parent_ID__c ;
                    Id recId = Id.valueOf(record.Parent_ID__c ); 
                    String parentObjectType = String.valueOf( recId.getSObjectType());
                        if( parentObjectType == 'Activity__c' ){
                           list<Activity__c> actparentId = [Select id,Project__r.Cust__c  from Activity__c WHERE Id =: parentId];   
                           for(Activity__c act :actparentId){
                                parentId = act.Project__r.Cust__c;
                            }
                        }
                        
                        if( parentObjectType == 'Project__c' ){
                           list<Project__c> projparentId = [Select Cust__c from Project__c WHERE Id =: parentId];   
                           for(Project__c proj :projparentId){
                                parentId = proj.Cust__c;
                            }
                        }
                        
                        if( docId != null ){    
                            docIds.add( docId );
                        }
            }

            List<ContentDocumentLink> linkList = [ SELECT Id, ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN: docIds ];
            if( !linkList.isEmpty() ){
                for( ContentDocumentLink link : linkList ){
                    List<ContentDocumentLink> links = this.linkMap.containsKey( link.ContentDocumentId )
                        ? this.linkMap.get( link.ContentDocumentId ) : new List<ContentDocumentLink>();
                    links.add( link );
                    this.linkMap.put( link.ContentDocumentId, links );
                }
            }
        
        }

 
Apex code 
this code not cover for 100%
global class closeAllDealsMonthAgo implements 
   Database.Batchable<SObject>, Database.Stateful{ 

   List<Opportunity> listRecords = new List<Opportunity>();
   global Database.QueryLocator start(Database.BatchableContext BC){
         String query = 'Select Id, Name, CloseDate,createdDate,StageName From Opportunity WHERE CloseDate=THIS_MONTH';
         return Database.getQueryLocator(query);
   }
   global void execute(Database.BatchableContext BC, List<SObject> scope){
      for(Opportunity obj : (Opportunity[]) scope){  
         if(Date.Today()>obj.CloseDate && (obj.StageName != 'Closed Won' || obj.StageName !='Closed Lost')){
            obj.StageName = 'Closed Lost';
            listRecords.add(obj);
         }
         if(Date.Today()>obj.createdDate.addMonths(1) && (obj.StageName != 'Closed Won' || obj.StageName !='Closed Lost')){
            obj.StageName = 'Closed Lost';
            obj.CloseDate= Date.today();
            listRecords.add(obj);
         }
      }
   }
   global void finish(Database.BatchableContext BC){
      if(!listRecords.isEmpty()){
         update listRecords;
      }
   }      
}
test code 
@isTest             
private class closeAllDealsMonthAgoTest {
    static testmethod void testbatch() {
        Integer count = 200;
        Account acc = new Account(Name='Test Account');
        insert acc;
        
        List<Opportunity> opps = new List<Opportunity>();
        for (integer i=0; i<count; i++){
            Opportunity opp = new Opportunity();
            opp.AccountId=acc.Id;
            opp.Name='My Opportunity '+i;
            opp.StageName='Qualification';
            opp.CloseDate= Date.today().addDays(-5);
            opps.add(opp);
        }
        insert opps;
        System.assertEquals(count, opps.size());
       
       Test.startTest();
           closeAllDealsMonthAgo obj = new  closeAllDealsMonthAgo();
           Database.executeBatch(obj);
       Test.stopTest();
      
         List<Opportunity> oppUpdatedList = [SELECT Id,StageName,CloseDate FROM Opportunity];
        for(Opportunity o : oppUpdatedList){
            if(Date.Today()>o.CloseDate && (o.StageName != 'Closed Won' || o.StageName !='Closed Lost')){
                o.StageName = 'Closed Lost';
                System.assertEquals('Closed Lost', o.StageName);    
            }
        }
    }
}
can any one explain what is programming elements and how data abstraction can be imlemented in salesforce explain with the example?
Any user scenarios for data abstraction?

here apex code 
global with sharing class schedularCloseAllDealsMonthAgo implements Schedulable{
      global void execute(SchedulableContext sc) {  
            closeAllDealsMonthAgo closeDeals = new closeAllDealsMonthAgo(); 
            database.executebatch(closeDeals);
      }
      public static void schedulerMethod(){
            schedularCloseAllDealsMonthAgo sched = new schedularCloseAllDealsMonthAgo();
            string con_exp= '0 0 10 * * ?';
            System.schedule('schedularCloseAllDealsMonthAgo', con_exp, sched);
      }
}
This is code of test but not work for 100%
@isTest   
public class schedularCloseAllDealsMonthAgoTest {
    public static testMethod void testschedule() {
        Test.StartTest();
            schedularCloseAllDealsMonthAgo sched = new schedularCloseAllDealsMonthAgo();
            String CRON_EXP = '0 0 23 * * ?';
            System.schedule('schedularCloseAllDealsMonthAgo', CRON_EXP, sched);
        Test.stopTest();
    }
}
I'm sure this is a very simple problem, but I'm still fairly new to saleforce and can't seem to find the solution. So I'm trying to compair new records when inserted with all existing records to ensure that the last name values are unique otherwise it won't post the new record. I'm sure that I will have to put this in a before insert trigger but I can seem to figure out how exactly to run the compairson. 

I'm getting the following error when I run a debug log on an update to an APEX Class, FATAL_ERROR|System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.Account_Owner_For_Jiva__c
The field is a formula text field that brings in the account owners email address. We use this to pass the email to our external system. I added the field the existing APEX Class like this:

 //json container for Account
    private class AccountCompany{
        private Id SalesforceID; //required
        private String Name; //required
        private String AccountOwner; //required
        private String PrimaryCountry; //required
        //private String EAGRelationshipID;
        private String UnicodeName;
        private String IndustrySectorID;
        private String ManufacturingTypeID;
       

        public AccountCompany(Sobject record)
        {
            Account account = (Account)record;

            this.SalesforceID = account.Id;
            this.Name = account.Name;
            this.PrimaryCountry = account.Primary_Country__c;
            this.AccountOwner = account.Account_Owner_For_Jiva__c;
            //this.EAGRelationshipID = EAGRelationshipID; //no related field in salesforce
            this.UnicodeName = account.Account_Name_Unicode__c;
            this.IndustrySectorID = account.Industry_Sector_ID__c;
            this.ManufacturingTypeID = account.Manufacturing_Type_ID__c;
            
        }
    }


The updated Class saves with no errors, but was not communicating correctly which is when I ran the code debug log. I saw where I need to add it to the query, but I don't see anything else in the class that includes the existing fields.

 

Hi All,

Im writing a test class for batch apex that will be scheduled to run on the first of each month.  Were testing it here, but i keep running into this error at line 25 "System.QueryException: List has no rows for assignment to SObject".  I dont know why that list would be blank.  Can anyone advise? thanks/
 
public class TouchSalesDatasTest {
	@isTest
    public static void Test() {
        Map<ID,Sales_Data__c> SDMap = new Map<ID,Sales_Data__c>();
        Account Acc = TestDataFactory.createAccount('TouchSalesDataTest EU ', 'desiredrecordtypeid', null, null, true);
        Account Dist = TestDataFactory.createAccount('TouchSalesDataTest Dist ', 'desiredrecordtypeid', null, null, true);
        for (Integer i = 0; i < 200; i++) {
            Sales_Data__c SD = new Sales_Data__c(End_User__c = Acc.ID,
                                                 Distributor__c = Dist.Id,
                                                 Amount__c = i,
                                                 Quantity__c = i,
                                                 Date__c = System.today().addDays(-25),
                                                 Product__c = 'desiredproductid');
            SDMap.put(SD.Id,SD);
        }
        insert SDMap.values();
        
        Decimal expectedValue = System.today().addDays(-25).daysBetween(System.today())/31;
        
        Test.startTest();
        TouchSalesDatas t = new TouchSalesDatas();
        Database.executeBatch(t);
        Test.stopTest();
        
        Sales_Data__c UpdatedTest = [SELECT ID,Name,Months_Ago__c FROM Sales_Data__c WHERE ID IN :SDMap.keySet() Limit 1];
        System.assertEquals(Math.round(expectedValue), UpdatedTest.Months_Ago__c);
    }
}

 

Hello, I have a requirement to create a trigger to not allow users to edit records if they are not the creator OR if they are not the owner. Owner can be a simple user or a QUEUE.
 

This is what I wrote until now... my code is not working.

 

trigger permissionToEditAdminTasks on SIG_Administrative_Task__c (after update) {
  
      //fetch the id of the creator of the record <start>
           Set<String> ownerIds = new Set<String>();
        for (SIG_Administrative_Task__c record : Trigger.New) {
            ownerIds.add(record.OwnerId);
             
        }
        
       
        
      // <end>
        
        List<Group> groups = [SELECT Id, (SELECT Id, UserOrGroupId FROM GroupMembers) FROM Group WHERE Id =: ownerIds];
        System.debug('####groups' + groups);    
        
          
        Map<String, Set<String>> memberIdsByGroupId = new Map<String, Set<String>>();
        
        //fetch the id's of the users from the the current owner queue  <start>
        for (Group groupRec : groups) {
            Set<String> memberIds = new Set<String>();
            for (GroupMember member : groupRec.GroupMembers) {
                memberIds.add(member.UserOrGroupId);
            }
               System.debug('####memberIds  ' + memberIds );   
        }
        // <end>
       

        for (SIG_Administrative_Task__c record : Trigger.New) {
            if (memberIdsByGroupId.get(record.OwnerId) != null && memberIdsByGroupId.get(record.OwnerId).contains(UserInfo.getUserId()))
            {
             
            }else{
                 record.addError('You have not permission for editing this record');
                  System.debug('record.OwnerId' + record.OwnerId);
            }
        }
    

}
I cannot edit the record no matter what, I don't know what is wrong in my code.. please help.
Spring 2020 release notes says that we can assign Tasks to queue.
I am able to assign task to any queue from task screen but it doesn't our problem of assigning task to queue using trigger or from process builder.

We have a requirement to create a new task and assigned to queue whenever any new case is created ?How can I achieve that?

Thanks,
Gaurav Seth