• ayu sharma dev
  • NEWBIE
  • 384 Points
  • Member since 2018
  • Salesforce Developer


  • Chatter
    Feed
  • 12
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 78
    Replies
I want to write a trigger to update field in opportunity(email field) when there is a change in contact  e mail field
relations: lookup from account to contact.  Lookup from account to opportunity.  
  Nb: no relation from contact to opportunity
Hi there,

New to writing SOQL scripts using Workbench. So there is a customer object called Affiliation (NU__Affiliation__r) that has a lookup relationship to the Account object.

SELECT Name,
       NU__Account__c,
       NU__ParentAccount__c
       Account.Name
FROM NU__Affiliation__c 


When I run the above script it's throwing the following error. I'm trying to access the parent Account fields. 

MALFORMED_QUERY: only aggregate expressions use field aliasing 

I also tried this script:

SELECT AccountNumber,Id,

(SELECT Name,NU__Account__c,NU__IsPrimary__c

FROM NU__Affiliation__r)

FROM Account

And I got this error:

INVALID_TYPE:
FROM NU__Affiliation__r)
^
ERROR at Row:5:Column:6
Didn't understand relationship 'NU__Affiliation__r' 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.


Would very much appreciate any help!

Regards,
Wil
Hi Friends,
I  tried to run a simple hello world using the code below

string tempvar = 'Enter_your_name_here';
System.debug('Hello World!');
System.debug('My name is ' + tempvar);

The output after SFDX: Execute Anonymous Apex with Editor Contents
is showing the same code I have written without any value assignments

Below is the return from the execution
48.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO
Execute Anonymous: // Use .apex files to store anonymous Apex.
Execute Anonymous: // You can execute anonymous Apex in VS Code by selecting the
Execute Anonymous: //     apex text and running the command:
Execute Anonymous: //     SFDX: Execute Anonymous Apex with Currently Selected Text
Execute Anonymous: // You can also execute the entire file by running the command:
Execute Anonymous: //     SFDX: Execute Anonymous Apex with Editor Contents
Execute Anonymous: 
Execute Anonymous: string tempvar = 'Enter_your_name_here';
Execute Anonymous: System.debug('Hello World!');
Execute Anonymous: System.debug('My name is ' + tempvar);
00:14:41.21 (21039896)|USER_INFO|[EXTERNAL]|00555000004hwoa|test-qphxury38ylx@example.com|(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)|GMT-07:00
00:14:41.21 (21078526)|EXECUTION_STARTED
00:14:41.21 (21085467)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
00:14:41.21 (21721820)|USER_DEBUG|[9]|DEBUG|Hello World!
00:14:41.21 (21776425)|USER_DEBUG|[10]|DEBUG|My name is Enter_your_name_here
00:14:41.21 (21858188)|CUMULATIVE_LIMIT_USAGE
00:14:41.21 (21858188)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100

Can anybody show some light, what I'm missing?
Would someone be able to help me write test code for this trigger:
trigger ReferralCreateContact on Lead (after insert) {
    if (trigger.isinsert){
        if (trigger.isafter){
    for (lead ld : trigger.new){
        if (ld.nextofkin__c !=null && ld.Emergency_Contact_Phone__c !=null){
            String first;
            String last;
            
            String s = ld.NextofKin__c;
            String [] lines = s.split(' ');
            first = lines[0];
            last = lines[1];
            
            List<Contact> contactToInsert = new List<contact>();
            Contact newContact = new Contact();
            newContact.RecordTypeId='0121N000001HoR7QAK';
            newContact.related_referral__c = ld.id;
            newContact.firstname = first;
            newContact.lastname = last;
            newContact.MobilePhone=ld.Emergency_Contact_Phone__c;
            newContact.recordtypeid= '0122g0000005rSbAAI';
            newContact.ownerid = ld.ownerid;
            
            contactToInsert.add(newContact);
              insert contactToInsert;       
        }
    }
    }
    }

}
I have a requirement to create a custom field called Average_Utility__c  on a parent object - Property__c that will show average sum of the child object records - Utility__c. 
  
I tried to create a trigger and a class that uses aggregate AVG function to fetch the records of amount_paid field from Utility__c.

But my problem is I don't know how to make it to recalculate Average_Utility__c  amount every time when new utility record is created. 

This is my code:         
public class AvgUtility {
public static void avgUtility (list<property__c> propList)   
        
        { 
      //   list <property__c> propList=new List<property__c>();
          
       
       
        list<property__c> PropertyList=[select id,name, Average_Utility__c from property__c]; 
                    
        for(property__c prop :PropertyList)
            
        {
            if (prop.Average_Utility__c==null || prop.Average_Utility__c!=null)
            { 
      AggregateResult[] groupedResults  = [SELECT Property__r.ID, AVG(Amount_Paid__c)  FROM Utility__c GROUP BY Property__r.ID];

         for (AggregateResult ar : groupedResults){
                prop.id =(id)ar.get ('Property__c');
                 prop.Average_Utility__c=(decimal)ar.get(('expr0'));
                propList.add(prop);
            }
         }            
         }
        insert propList;
        }
}


Trigger Class
trigger AvgUtilityTrigger on Utility__c (after insert) {
    
    for (Utility__c ut:trigger.new)
    {
        AvgUtility.avgUtility();
    }
        
   }

I will appreciate any advice!  
Hi,
I am trying to use ToolingAPI to fetch Pagelayout informations. As I am using lightning, so I have created
1.connected app:
Connected App
2.Auth Provider:
Auth Provider3.Named Credential:
Named CredentialPlease find below the the code snippet:
Global with sharing class DocGeneration {
    @AuraEnabled 
    public static String Callout(){;
        String resbody;
        Http http = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint('callout:Tooling_API/services/data/v35.0/tooling/query/?q=Select+Id+from+Layout');  
        req.setMethod('GET');
        req.setHeader('Content-Type', 'application/json;charset=UTF-8');
        system.debug('req:' + req);
        HttpResponse res = new HttpResponse();
        res = http.send(req);
        resbody= res.getBody();
        system.debug('res:' + resbody);
        return resbody; 
    }
}
When I am calling this method from annonymous Apex in developer console, It is returning the status as 200 but HTTPResponse has no body.
User-added image
Am I doing anything wrong? Please help.
Hi Everyone,

I Have a Custom setting with 3 Fields :
1.State 2. Products 3. UserID(to make Contact Owner)
I want to change the Contact Owner based on this custom setting values of State and Product.
For Ex : if State is NY and Product is Adidas  - Contact Owner should be User A 
If State is NY and Product is Nike - Contact Owner should be User B.

I have written below code but it is working only based on the State, what I want is to check the condition for Product as well along with State :

trigger ContactOwnerCustomSetting on Contact (before insert,before update) {
Map<string,ContactOwner__c> mpcons = ContactOwner__c.getAll();
for(Contact con:trigger.new){
ContactOwner__c co =ContactOwner__c.getValues(con.State__c);
con.ownerid = co.User__c;
}
}
  • March 20, 2020
  • Like
  • 0
Hello,
I am familiar with updaing a Parent record with a field from a child but not sure how to update the parent with a vlaue from each child.
There is a comment__c field on each Task__c record.
If there are 3 task associated to the Parent(export__c) I need the comment field on the Parent to house the comment from each child
For example:
task 1 comment = test for price
task 2 comment = ask for quote
task 3 comment = sending invoice

The commen ton the parent needs to look llike
test for price
ask for quote
sending invoice

No sure how to grab the values and then force a line break between each.
The relationship between the 2 objects is a lookup.

I would like to add this method into an existing class 

Thanks,
P


 
Hello!

Help me with this issue - when adding an Opportunity Product to Opportunity we need the Quantity field to be prepopulated with a value "1".

Is there anyway, maybe a visualforce page, how to do this?
Can someone help- i need to rewrite the below trigger, with the same effects, but with remove all SOQL queries from inside the for loop:

trigger CdlUpdateDischarge on ContentDocumentLink (after insert) {
    Set <string> setlinkedid = new set<string>();
    for (ContentDocumentLink cd : trigger.new){
            setlinkedid.add(cd.linkedentityid);
        List<Discharge__c> disList = [select id from discharge__c where id=:setlinkedid];
        List<contentdocumentlink> cdl = [SELECT ContentDocumentId
                                     FROM ContentDocumentLink 
                                     WHERE LinkedEntityId in (select id from discharge__c where id=:setlinkedid)];
        try{
        if (cdl.size() > 0 && cdl.size() < 2){
            for (Discharge__c dis : disList){
            dis.Referrals_Status__c = 'Documents Uploaded';
            }
            update disList;
        }    
        }catch(exception e){
            system.debug(e);
        }
        
    }
    
}
I want to do something like this. How can it be possible , Please let me know :
for(Account acc2:[select id from account limit 1])
{
    //sObject s = new Account();
    Vehicle__c vt=new Vehicle__c();
    vt=(Sobject)acc2;
    insert vt;
    System.debug('sobject '+vt);
}

I don't want to do it like this :
for(Account acc2:[select id from account limit 1])
{
    
    Vehicle__c vt=new Vehicle__c();
    vt=acc2.name;
    insert vt;
    System.debug('sobject '+vt);
}

Here we are assigning the variables one by one. I have 157 fields how can I assign all of them in one go. Please help me this is bit urgent!!.

 
Hi Everyone, 

I'm having an issue with code coverage when I'm attempting to import a change set into production. For some reason no matter what I do, my coverage is always at 0% and gives me a fatal error even though my sandbox is showing 100 percent. Here is my code below! Any help would be appreciated. 


Public class AutoConvertLead
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
        LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
        for(id currentlead: LeadIds){
                Database.LeadConvert Leadconvert = new Database.LeadConvert();
                Leadconvert.setLeadId(currentlead);
                Leadconvert.setOwnerId(Userinfo.getUserId());
                Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
                MassLeadconvert.add(Leadconvert);
        }
        List<ID> LeadAccounts      = new List<ID>();
        List<ID> LeadOpportunities = new List<ID>();
        if (!MassLeadconvert.isEmpty()) {
            for(Database.leadconvert acc : MassLeadConvert){
                Database.LeadConvertResult art = database.convertlead(acc); 
                LeadAccounts.add(art.getAccountId());
                LeadOpportunities.add(art.getOpportunityId());
        }
            List<Account> LeadAccountsupdate = [Select ID, name, npe01__One2OneContact__c,(Select FirstName, Lastname, AccountId, ID  from Contacts Limit 1) From Account Where ID in :LeadAccounts];
            System.debug(LeadAccountsupdate.size());
            for(Account acc: LeadAccountsupdate){
                System.debug(acc.contacts[0]);
                acc.name = acc.contacts[0].firstname + ' ' + acc.contacts[0].lastname + ' Household';
                acc.npe01__One2OneContact__c = acc.contacts[0].id;
                update acc;
            }
            List<Opportunity> LeadOpportunitiesupdate = [Select ID, Name, npsp__Primary_Contact__c, Pick_up__c, Type_of_Good__c, Closedate, account.npe01__One2OneContact__r.name From Opportunity Where ID in :LeadOpportunities];
            for(Opportunity opp: LeadOpportunitiesupdate){
                String[] multi = opp.Type_of_Good__c.split(';');
                String   rcc   = string.valueof(opp.CloseDate);
                opp.name = opp.account.npe01__One2OneContact__r.name + ' / ' + opp.Pick_up__c + ' / ' + multi + ' / ' + rcc; 
                opp.npsp__Primary_Contact__c =  opp.account.npe01__One2OneContact__c;
                update opp;  
    }
}
}
}
Here below is my test class



@isTest
public class AutoConvertLeadTest {

 static testMethod void validateAutoConvertLead() {
     Test.startTest();
     Lead testLead      = new lead();
     testLead.firstname = 'qasx';
     testLead.LastName  = 'Bucker';
     testLead.Company   =  'Not Applicable';
     testLead.LeadSource = 'Web';
     testLead.Pick_up_or_Drop_off__c = 'Pick Up';
     testLead.Type_of_Good__c = 'Meat';
     testLead.OwnerId   = Userinfo.getUserId();
     testLead.Status    = 'Convert Automation';
     insert testLead;

        test.stopTest();

 }
}
Hello,
I am new to salesforce rest and soap api, I am trying to get the session Id from Salesfroce so I can use it for other restservices. I am able to do this using the Soap api but it requires token along with username ana password.
Is there any way I can get session Id only using username and password.
I don't want to create a connected app as my app is for every org, so i get to create it on all the orgs, which certainly I dont want.
Please suggest a Solution.
trigger TaxCalaculation on OrderItem (before insert,before update) {
    
    product2 a;
    //List<orderItem> a=[select product2.family from orderItem where product2id IN :Trigger.newMap.keySet()];
    //List<OrderItem> li=new List<OrderItem>();
    for(OrderItem o:Trigger.new)
    {
         a=[select family from product2 where id= :o.Product2Id];
        //o=[select Product2.family from orderItem where product2id= :Trigger.new.product2id];
                  
        //o=[select product2.family from orderItem where product2Id IN :Trigger.new];
        
        if(a.family=='Electronics')
       {
           o.taxRate__c=0.02;
       }
        
        else if(a.family=='FootWear')
       {
           o.taxRate__c=0.05;
       }
        
        else if(a.family=='Clothing')
       {
           o.taxRate__c=0.07;
       }
        
        o.finalRate__c=o.UnitPrice*o.Quantity*o.taxRate__c;
        
         system.debug(o.taxRate__c);
         system.debug(a.Family);
        System.debug(o.finalRate__c);

    }

}
Hi All,

I have developed a trigger for contact on update. as soon as contact update am calling below class from tigger and passing contact id. I am new to write test class for call outs. Can someone help to create test class for below method.
Thanks in adcance. 
public class Helper {
    public static String api_end_point = 'URL';
    
    @future (callout=true)
    public static void afterUpdateContact(String contact_id){
        String post_body = '{"data": {"contactId":"' + contact_id + '"}}';
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint(api_end_point);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        request.setBody(post_body);
        HttpResponse response = http.send(request);
        
        if (response.getStatusCode() != 201)
        {
            System.debug('The status code returned was not expected: ' + response.getStatusCode() + ' ' + response.getStatus());
        }
        else
        {
            System.debug(response.getBody());
        }
        
    }
    
    
}
I want to write a trigger to update field in opportunity(email field) when there is a change in contact  e mail field
relations: lookup from account to contact.  Lookup from account to opportunity.  
  Nb: no relation from contact to opportunity
Hi there,

New to writing SOQL scripts using Workbench. So there is a customer object called Affiliation (NU__Affiliation__r) that has a lookup relationship to the Account object.

SELECT Name,
       NU__Account__c,
       NU__ParentAccount__c
       Account.Name
FROM NU__Affiliation__c 


When I run the above script it's throwing the following error. I'm trying to access the parent Account fields. 

MALFORMED_QUERY: only aggregate expressions use field aliasing 

I also tried this script:

SELECT AccountNumber,Id,

(SELECT Name,NU__Account__c,NU__IsPrimary__c

FROM NU__Affiliation__r)

FROM Account

And I got this error:

INVALID_TYPE:
FROM NU__Affiliation__r)
^
ERROR at Row:5:Column:6
Didn't understand relationship 'NU__Affiliation__r' 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.


Would very much appreciate any help!

Regards,
Wil

Hello everyone,

I have this validation rule which stops users to put the project on hold and presents them the error if their profile is not Admin or billing. which works great. 

This is the formula. 

if(
(Date_of_Hold__c < LatestHold__c &&
(ISPICKVAL(accorto__Status__c, 'On Hold') ||
Date_of_Hold__c < LatestHold__c &&
ISPICKVAL(accorto__Progress__c, 'On Hold'))),

if(
$Profile.Name == 'System Administrator' ||
$Profile.Name == 'Zuora Billing Team',
false,
true),
false)

The problem is now those users not able to update project which is already on hold. 

what I really want is to make sure, 1st, they cannot put the project on hold, 2nd,  if the project is already on hold they should be able to make changes to all other fields except the status field.

which is currently not happening and they getting an error that the project is on hold even making changes to other fields.

Any idea how can I able to modify this validation rule? thank you. 

I am trying to create a before-insert trigger on EmailMessage, so that when a user logs an email from the Outlook Integration, I can set the RelatedToId field based on the email sender (FromAddress).

What I am finding in my testing, however, is that both FromAddress and ValidatedFromAddress are NULL on insert! Perhaps due to how the Outlook Integration inserts email records - perhaps it follows up the insert with an update to populate the FromAddress field.

Unfortunately, I must put my logic in the before-insert - you are only allowed to set RelatedToId on insert.

(1) Do any of you have more details around the behavior of the Outlook Integration and the From fields that might help me?

(2) Can anyone see another solution to be able to programmatically set the RelatedToId for tracked emails, based on the sender, other than my approach of the before-insert trigger on EmailMessage?

I have considered moving my logic to an after insert, and trying to delete the original email and recreate it with all the right information, but that seems extreme and I am concerned about the impact the changing id (due to delete and create new) will have on the Outlook Integration.

Thanks to all for any help you can provide!
Scott Kostojohn
Hello, Please me on this requirement.

Count Account with Different Industry(on account picklist fields is there)(e,g. For Industry Electronics we have 3 Accounts) using Map.

plz help me i am new in apex collection.
When an account is inserted or updated,check whether any opportunity is linked to it or not,if not then create one whose name is ‘First Opportunity -<Account Name>’
Hi All,
          I have created a test class for a class but its failing and giving me error:- System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out.
my class is given below:-

global without sharing class ZoomService {
    @Future(callout=true)
    public static void createWebinar(String requestBody, String userId, Id sessionId){
        SessionTriggerHelper.runTrigger = false;
        String requestEndpoint =ZoomJWTAuthentication.getZoomCredentials().rie__Zoom_URL__c + 'users/'+userId+'/webinars';
        String requestMethod = 'POST';
        
        httpResponse res = ZoomCalloutService.postCallout(requestMethod, requestEndpoint, requestBody);
        CreateWebinarJSONParser cwp = CreateWebinarJSONParser.parse(res.getBody());
        Session__c ss = [Select id, rie__Zoom_URL__c, rie__Meeting_ID__c, 
                         rie__Meeting_Password__c, rie__Session_Type__c
                         from Session__c 
                         where Id =: sessionId];
        ss.rie__Zoom_URL__c = cwp.join_url;
        ss.rie__Meeting_ID__c = String.valueOf(cwp.Id);
        ss.rie__Meeting_Password__c = cwp.password;
        ss.rie__Session_Type__c = 'Webinar';
        update ss; 
        
        //System.debug(res.getStatusCode());
    }
    
    @Future(callout=true)
    public static void createUser(String requestBody){
        String requestEndpoint = ZoomJWTAuthentication.getZoomCredentials().rie__Zoom_URL__c + 'users';
        String requestMethod = 'POST';
        Map<String, Object> reqMap = new Map<String, Object>();
        reqMap.put('action', 'create');
        Map<String, Object> userInfo = new Map<String, Object>();
        userInfo.put('email', 'absinghrathore127@gmail.com');
        userInfo.put('type', '1');
        userInfo.put('first_name', 'abhimanyu');
        userInfo.put('last_name', 'singh');
        reqMap.put('user_info', userInfo);
        String  reqBody = JSON.serialize(reqMap);
        
        httpResponse res = ZoomCalloutService.postCallout(requestMethod, requestEndpoint, reqBody);
        System.debug(res.getStatus());
        System.debug(res.getBody());
    }
    
    @Future(callout=true)
    public static void listUsers( String emailId, Id zoomUserRecordId){
        String requestEndpoint = ZoomJWTAuthentication.getZoomCredentials().rie__Zoom_URL__c + 'users';
        String requestMethod = 'GET';
        
        httpResponse res = ZoomCalloutService.getCallout(requestMethod, requestEndpoint);
        if(res.getStatusCode() == 200){
            GetUsersJSONParser gu = GetUsersJSONParser.parse(res.getBody());
            List<GetUsersJSONParser.users>  userList= gu.users;
            String userId = '';
            if(!userList.isEmpty()){
                for(GetUsersJSONParser.users u : userList){
                    if(u.email != Null && u.email == emailId){
                       userId = u.id;
                       break; 
                    }
                }
                rie__Zoom_User__c zoomUser = [Select id from rie__Zoom_User__c where Id =: zoomUserRecordId];
                if(userId != Null){
                    zoomUser.rie__User_Id__c = userId;
                }
                update zoomUser;
            }
            
        }
        
    }
    
    //@Future(callout=true)
    webservice static String getMeetingRecording(String meetingId, Id recId){
        String requestEndpoint = ZoomJWTAuthentication.getZoomCredentials().rie__Zoom_URL__c + 'meetings/'+meetingId+'/recordings';
        String requestMethod = 'GET';
        
        httpResponse res = ZoomCalloutService.getCallout(requestMethod, requestEndpoint);
        if(res.getStatusCode() == 200){
            GetRecordingJSONParser getRecordingJSONParser = GetRecordingJSONParser.parse(res.getBody());
            Session__c ss = [Select id, rie__Zoom_URL__c, rie__Meeting_ID__c, 
                             rie__Zoom_Recording_URL__c
                             from Session__c 
                             where Id =: recId];
            ss.rie__Zoom_Recording_URL__c = getRecordingJSONParser.share_url;
            update ss;
            return 'Success';  
        }else{
            return 'There is no recording for this meeting ';
        }
    }
    
}
my test class is given below:-
@isTest
private class ZoomServiceTest {
    public static Integer RESPONSE_CODE = 200;
    private class Mock implements HttpCalloutMock {
        
        public HTTPResponse respond(HTTPRequest req) {
            
            HTTPResponse res = new HTTPResponse();
            
            res.setStatusCode(200);
            res.setBody('{"topic": "Test Webinar","type": 5,"start_time": "2020-04-20T06:59:00Z","duration": 60,"timezone": "America/Los_Angeles","password": "avfhfgh","agenda": "Test Webinar","recurrence": {"type": 1,"repeat_interval": 1,"end_date_time": "2020-04-20T06:59:00Z"},"settings": {"host_video": true,"panelists_video": true,"practice_session": true,"hd_video": true,"approval_type": 0,"registration_type": "integer",'+
                        +'"audio": "both","auto_recording": "none","enforce_login": false,"enforce_login_domains": "","alternative_hosts": "","close_registration": true,"show_share_button": true,"allow_multiple_devices": false,"registrants_email_notification": true}}');
            
            return res;
        }
    }
    
    
    static testmethod void createWebinarTest() {
        
        Test.setMock(HttpCalloutMock.class, new Mock());
        Test.startTest();
        
        rie__Event__c evt = new rie__Event__c();
        insert evt;
        
        Session__c ss = new Session__c();
        ss.name = 'Test webinar'; 
        ss.rie__Event__c = evt.Id;
        insert ss;
        
         ZoomService.createWebinar('','',ss.Id);
        //ZoomService.createUser(res);
       ZoomService.listUsers('',ss.id);
        ZoomService.getMeetingRecording('',ss.id);
        Test.stopTest();
    }
}
Can anyone help me with this error?
Hi Friends,
I  tried to run a simple hello world using the code below

string tempvar = 'Enter_your_name_here';
System.debug('Hello World!');
System.debug('My name is ' + tempvar);

The output after SFDX: Execute Anonymous Apex with Editor Contents
is showing the same code I have written without any value assignments

Below is the return from the execution
48.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO
Execute Anonymous: // Use .apex files to store anonymous Apex.
Execute Anonymous: // You can execute anonymous Apex in VS Code by selecting the
Execute Anonymous: //     apex text and running the command:
Execute Anonymous: //     SFDX: Execute Anonymous Apex with Currently Selected Text
Execute Anonymous: // You can also execute the entire file by running the command:
Execute Anonymous: //     SFDX: Execute Anonymous Apex with Editor Contents
Execute Anonymous: 
Execute Anonymous: string tempvar = 'Enter_your_name_here';
Execute Anonymous: System.debug('Hello World!');
Execute Anonymous: System.debug('My name is ' + tempvar);
00:14:41.21 (21039896)|USER_INFO|[EXTERNAL]|00555000004hwoa|test-qphxury38ylx@example.com|(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)|GMT-07:00
00:14:41.21 (21078526)|EXECUTION_STARTED
00:14:41.21 (21085467)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
00:14:41.21 (21721820)|USER_DEBUG|[9]|DEBUG|Hello World!
00:14:41.21 (21776425)|USER_DEBUG|[10]|DEBUG|My name is Enter_your_name_here
00:14:41.21 (21858188)|CUMULATIVE_LIMIT_USAGE
00:14:41.21 (21858188)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100

Can anybody show some light, what I'm missing?
Hi, 

Below code is working when bulk updates are make it is failing can you suggest me what might be the issue in below code. 
public class OpportunityProductPurchased{
    
    @InvocableMethod
    public static void OpplineProdPurch(List<ID> OppId){
    String[] stringList = new String[0];

    list<opportunitylineitem> oplnlst = new list<opportunitylineitem>([select id, name,f_Entitlement_Product_Description__c from opportunitylineitem where opportunityid = :OppId and isdeleted = false and product2.family like '%Subscription%']);
    list<opportunity> opplst = new list<opportunity>();

    for(opportunity opp :[select id, Products_Purchased__c from opportunity where id = :OppId]){
    for(opportunitylineitem opl : oplnlst){
     
        If (opl.f_Entitlement_Product_Description__c!=NULL){
            stringlist.add(opl.f_Entitlement_Product_Description__c);
        
        } 
    }
//Using join method to concatenate f_Entitlement_Product_Description__c field of all the opp line item records
     String allproducts = String.join(stringList, '\n'); 
     opp.Products_Purchased__c = allproducts.remove('null');
     opplst.add(opp);
    }

    if(opplst.size() > 0){
      update opplst;
    }       
  }
}

Thanks
Sam
  • March 24, 2020
  • Like
  • 0
Hello everybody,

I need to set up the following process:

- In a textarea custom field of Object x, a user should be able to copy-paste a kind of Server list (kind of XX12yA;XX12yB;XX12yC;XX12yD)

- Once pasted in the text custom field and Saved, the data (server list) should be processed in order to retrieve infos (as an example for a Server: IP Address, Application involved, version, updates...) stored in another Object y which does not has any lookup to the first Object x. 

- Those retrieved infos are then to be displayed in another custom field of the Object x to which the textarea belong to, for further customer treatment.
 
Has someone already created such a process ?
 
Thanks  for your ideas !