• Arpit Gupta 37
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 6
    Replies
Error: Compile Error: Invalid identifier ' '. Apex identifiers must start with an ASCII letter (a-z or A-Z) followed by any number of ASCII letters (a-z or A-Z), digits (0 - 9), '$', '_', or unicode characters from U+0080 to U+FFFE. at line 20 column 20

Objective:
To update account Field when an opportunity stage name is Closed won.This will happen when an opportunity is inserted and updated to Stagename: Closed won.

Below is the code


trigger updatecontact on opportunity (after insert,after update) {



map<id,opportunity> Mp=new map<id,opportunity>();
/*([select id,accountid from opportunity where stagename='Closed Won' and (id in : Trigger.new or id in: Trigger.oldMap.keySet())]);*/

for(opportunity Opp:Trigger.new)
{
if(Trigger.isUpdate)
{
if((Opp.stagename = 'Closed Won') && ((Trigger.oldMap.get(Opp.Id).stagename)!='Closed Won'))
{
Mp.put(Opp.id,Opp.accountid);
}

}
if(Trigger.isInsert)
{
if(Opp.stagename == 'Closed Won')
{
Mp.put(Opp.id,Opp.accountid);
}
}
}
set<Id> S= new set<Id>();
for(opportunity Op: Mp.values())
{
S.add(Op.accountid);
}
List<Account> Ac= [select Id,type from account where id in:S];
for(account Acc: Ac)
{
Acc.type='Customer - Direct';

}
Update Ac;
}
Original question:
I am facing an issue, I want to get the list of users in an email I am deactivating through Batch Apex.I am using the below code.

I am getting null for the string StrDeactiveUsrId, Kindly suggest

global class User_Deactivation_6_Months implements Database.Batchable<sObject>
{
   global  list<string> lstDeactiveUsr=new list<string>();
 

    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        //String query='SELECT Id,Lastlogindate,IsActive,profileid FROM User WHERE Lastlogindate <  LAST_n_MONTHS:24 and  profileid not in('00eA0000000Re9Y','005A0000001AfHE') and isactive= true';
        String query = 'SELECT Id,UserName,Lastlogindate,IsActive,profileid FROM User WHERE ISACTIVE=TRUE and Lastlogindate < LAST_n_MONTHS:24 and ProfileId NOT IN (\'00eA0000000Re9Y\',\'005A0000001AfHE\')';
        return Database.getQueryLocator(query);

    }

 

    global void execute(Database.BatchableContext BC, List<User> scope)

    {

        for ( User usr : scope)

        {
            
            usr.IsActive = False;
            lstDeactiveUsr.add(usr.UserName);
            /*if(a.profileid != '00eA0000000Re9Y' && a.profileid != '005A0000001AfHE')
            {
                 a.IsActive = False;
                 U1.add(a.id);
           }*/
           System.debug(usr.UserName);
        }

        update scope;

    } 

    global void finish(Database.BatchableContext BC)

    {
        String StrDeactiveUsrId;
        AsyncApexJob a = [Select Id, Status,ExtendedStatus,NumberOfErrors, JobItemsProcessed,TotalJobItems, CreatedBy.Email    from AsyncApexJob where Id =:BC.getJobId()];

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

        String[] toAddresses = new String[] {'arpitg@amgen.com','ARPI1310@GMAIL.COM'};
        /*'supriyos@amgen.com'};*/

        mail.setToAddresses(toAddresses);

        mail.setSubject('Compass License Management' + a.Status);
        for(string s: lstDeactiveUsr)
        {
            StrDeactiveUsrId+=s+',';
        }
        System.debug(StrDeactiveUsrId);

        mail.setPlainTextBody('records processed ' + a.TotalJobItems +   'with '+ a.NumberOfErrors + ' failures.' +'\n\n SFDC ID OF THE USER PROCESSED' + StrDeactiveUsrId );

        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        
    }

}
 
I want to understand the significance of Permission set ID ?
Do we need this field to update the existing permissionset or Name will be sufficient for that as PermissionSet Name itself a unique attribute.
Can you please help me to understand and answer below queries as well

query to create permissionset and query to update existing permissionset
Hi,

I need to add two date fields in FORMULAS and get the result in number.
(Progress Date + Approved Date )

Progress Date: Type as Date
Approved Date : Type as Date

Getting below error: 
Error: Incorrect parameter type for operator '+'. Expected Number, received Date

Please suggest
Scenario
I have one check box  based on checkbox i need to display remaining Feild Output text values.
This is my apex code how to check in Position object it is working or not.I just want to check after clicking new it must go to IT record type or Non IT Record type
public class c1{
    List <Position__c> pstn = new List<Position__c>();

    public List<Position__c> getpstn(){
        return pstn;
    }

    public PageReference ITReport_pstn(){
        pstn = [select Name__c ,Type__c, Industry__c,  Phone__c from Position__c where Type__c = 'IT Report'];
        return null;
    }

    public PageReference NonITReport_pstn(){
        pstn = [select Name__c , Type__c, Industry__c,Phone__c from Position__c where Type__c = 'NonIT Report'];
        return null;
    }
}
Hello,

Can someone help point out where the NullPointerException occurs? This class is invocable from a process that gets the Opportunity Line Item ID for created and updated records where Product End Date = null. 
 
public with sharing class invocable_productEndDate 
{
  
  /*Params to be passed from different process builder processes from varying objects. 
  None required, because each process will execute slightly different logic and use different params.*/
  public class productVariables 
  {
    @InvocableVariable
    public Id opptyLineItemId;
  }

  @InvocableMethod
  public static void productEndDate(List<productVariables>  Vars)
  {
    List<Id> oppLineItemIds = new List<Id>();
    List<OpportunityLineItem> oppLineItems = new List<OpportunityLineItem>();
    Map<Id, OpportunityLineItem> oliIdandOLI = new Map<Id, OpportunityLineItem>();
    Map<Id, Date> oliAndProductEndDate = new Map<Id, Date>();
    Set<Id> updateOLIIds = new Set<Id>();
    List<OpportunityLineItem> olisToUpdate = new List<OpportunityLineItem>();


    /*Loop through variable objects passed from process builder and assign Ids to lists. Because of SOQL
    governors, don't want to query inside loop, so list assignment works around that*/
    for (productVariables var : Vars)
    {
      if (var.opptyLineItemId != null)
      {
        oppLineItemIds.add(var.opptyLineItemId);
        system.debug('oppLineItemIds = ' + oppLineItemIds);
      }
    }

    oppLineItems = [SELECT Id, ServiceDate, Product_End_Date__c, PricebookEntry.Product2.FY16_Revenue_Type__c
          FROM OpportunityLineItem 
          WHERE Id IN : oppLineItemIds
          AND PricebookEntry.Product2.FY16_Revenue_Type__c = 'Recurring'];

    system.debug('oppLineItems = ' + oppLineItems);

    /*Product Term Months may be null, because Product End Date is not required on Salesforce ui when adding a product. Assume 12 months from ServiceDate and calculate months between.
    Default Product Date based on these assumptions - updates will re-calculate accordingly.*/
    for (OpportunityLineItem oli : oppLineItems)
    {
      oliIdandOLI.put(oli.Id, oli);
      Date tempProductEndDate = oli.ServiceDate.addYears(1).addDays(-1);
      oliAndProductEndDate.put(oli.Id, tempProductEndDate);
    }

    /*Line Item field values to update go in maps in this block*/
    if (!oliIdandOLI.isEmpty())
    {
      for (Id oliID : oliIdandOLI.keySet())
      {
        if (!oliAndProductEndDate.isEmpty())
        {
          oliIdandOLI.get(oliId).Product_End_Date__c = oliAndProductEndDate.get(oliId);
        }
      }
    }

    /*Don't want duplicates in list of line items to update, so loop through ordered set of Ids and add to update list only if the record is not already there.*/
    for (Id oliId : oliIdandOLI.keySet())
    {
      if (!updateOLIIds.contains(oliId))
      {
        olisToUpdate.add(oliIdandOLI.get(oliId));
        system.debug('olisToUpdate =  ' + olisToUpdate);
      }
      else
      {
        updateOLIIds.add(oliId);
        system.debug('updateOLIIds = ' + updateOLIIds);
      }
    }



Thank you,

Maggie
Here i am trying to append "Updated"  to all of my accounts but no luck. 


public class INFSimpleBatchExp implements Database.Batchable<sobject> {
  
    public Database.QueryLocator start(database.BatchableContext bc )
    {
        String query = 'select id, name from Account';
        return Database.getQueryLocator(query);
    }
   
    public void execute (Database.BatchableContext bc, List<Account> scope )
    {
      
        for(Account acc : scope)
        { 
          
            acc.name = acc.name + 'updated';
        }
    update scope;
    }
   
   
    public void finish(Database.BatchableContext bc)
    {
       
    }
}
----------------------------------------------------------------------------------------------------------------------

I am using following statemets in Developer console

INFSimpleBatchExp inF = new INFSimpleBatchExp();
Database.executeBatch(inF, 200);

Anyone kindly let me know where it went wrong?

wwwwwwThanks,
Prakki