• Swayamprava
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 23
    Replies
Hi, I am creating an approval process in apex using meta data API. Approval process is getting created , but workflow action reference not able to get the field update. Getting an error - "
Attempt to de-reference a null object".

Below is the code :
public  with sharing class MetadataServiceCall2 {    
    public static void createApprovalProcess1(){
        
        //start creating approval process , 1st make a call out
        String restUrl = 'callout:ApexMDAPI/services/data/v42.0/limits';
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint(restUrl);
        req.setMethod('GET');
        HttpResponse res = h.send(req);
        
        //call the metadata service, 2nd part
        MetadataService.MetadataPort service = new MetadataService.MetadataPort();
        service.SessionHeader = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId = '{!$Credential.OAuthToken}';
        // MetadataService.MetadataPort ms = new MetadataService.createService();
        
        MetadataService.ApprovalProcess approvalProcess = new MetadataService.ApprovalProcess();
        approvalProcess.fullName = 'PDM__c.TestApproval14';
        approvalProcess.label = 'Test Approval14';
        
        MetadataService.ApprovalEntryCriteria entryCriteriaobj = new MetadataService.ApprovalEntryCriteria();
        
        entryCriteriaobj.criteriaItems = new List<MetadataService.FilterItem>();
        MetadataService.FilterItem criteria = new MetadataService.FilterItem();
        criteria.field='PDM__c.Workflow_Name__c';
        criteria.operation='equals';
        criteria.value='UCP:Development:Development:Movies & Minis:Makeover/Format_WF';         
        
        entryCriteriaobj.criteriaItems.add(criteria);
        entryCriteriaobj.booleanFilter='1';
        approvalProcess.entryCriteria =entryCriteriaobj;
        
        approvalProcess.active = false;
        approvalProcess.allowRecall = false;
        approvalProcess.showApprovalHistory = true;
        approvalProcess.recordEditability = 'AdminOnly';
        approvalProcess.finalApprovalRecordLock = false;
        approvalProcess.finalRejectionRecordLock = false;
        approvalProcess.showApprovalHistory = false;        
        
        MetadataService.ApprovalSubmitter submitter = new         MetadataService.ApprovalSubmitter();
        submitter.type_x = 'user';
        submitter.submitter = UserInfo.getUserName();
        
        MetadataService.WorkflowActionReference wfActionReference = new MetadataService.WorkflowActionReference();
        wfActionReference.name='Update_Status_value8';
        wfActionReference.type_x ='FieldUpdate';
        MetadataService.ApprovalAction initialAction = new  MetadataService.ApprovalAction();              
        initialAction.action.add(wfActionReference);
        
        //Add this action to approvalProcess
        approvalProcess.initialSubmissionActions=initialAction;   
        approvalProcess.allowedSubmitters = new List<MetadataService.ApprovalSubmitter> { submitter };
        List<MetadataService.SaveResult> results =service.createMetadata(new MetadataService.Metadata[] { approvalProcess });
        handleSaveResults(results[0]);
    }
    
    
   
    private static void handleSaveResults(MetadataService.SaveResult saveResult){
         
         if(saveResult==null || saveResult.success)
             return;
         // Construct error message and throw an exception
         List<String> messages = new List<String>();
         messages.add((saveResult.errors.size()==1 ? 'Error ' : 'Errors ') + 
                 'occured processing component ' + saveResult.fullName + '.');
        
         for(MetadataService.Error error : saveResult.errors)
             messages.add(error.message + ' (' + error.statusCode + ').' +( error.fields!=null && error.fields.size()>0 ? 
                     ' Fields ' + String.join(error.fields, ',') + '.' : '' ) );
         if(messages.size()>0)
             throw new MetadataServiceExamplesException(String.join(messages, ' '));
     }
    
    public class MetadataServiceExamplesException extends Exception { }
     
}



I am getting error  at below code :
MetadataService.ApprovalAction initialAction = new  MetadataService.ApprovalAction();              
        initialAction.action.add(wfActionReference);

Can anyone please let me know where I am wrong? Why I am getting null pointer error?
As per new summer release , Now the users who are creating site records are no more the record owners. So how to set a default record owner? I am no getting the way to do it. Can any one suggest me? Thanks in advance. 
What these mentors actually do? If You stuck in some places in your job, are they going to help you?
There is am quick action button. On click on this, it generates an PDF. After pdf generated, i am getting these two error msges on the record. There is no change in code. This issue is not coming in production, but is visible in sandbox. Recently I have activated the the new summer release features in my sandbox. Is it due to this?

User-added image
Hi I am not able to find the solution of the below issue.

I logged in to production , for a record i can see a different record page , while same same record my friend who is logged in using the same login credential, from his laptop, can see a different record page. 

Why i cannot see the same page?


 
1.As much I know , Rest API also use HTTP call out , So i want to know what more we do in REST that is not included in HTTP callout.

 
Requirement : I need to query all the opportunity and make a csv file and send it to one peoplesoft server using a webservice call.

I have written the batch apex. 

global class OpportunityBatch implements Database.Batchable<sObject>{

    //global declaration of variable which contains all Opportunity
    String query;
   
    // global method for query
    global Database.querylocator start(Database.BatchableContext BC){   
   
        query='select id,AccountId,Amount,CloseDate from Opportunity';
        return Database.getQueryLocator(query);     
    }
    //which called by scheduler class to start the execution.
    global void execute(Database.BatchableContext BC, List<Opportunity> scope){
      List<Opportunity> oppListToUpdate = new List<Opportunity>();
     
      string header = 'Record Id, AccountId , Amount, Close Date \n';   
      String finalstr = header ;
      for(Opportunity opp : scope){
          string recordString = opp.Id+','+opp.AccountId+','+opp.Amount+','+opp.closeDate+'\n';
          finalstr = finalstr +recordString;              
      }
      Blob csvBlob = Blob.valueOf(finalstr);
          
    }
    global void finish(Database.BatchableContext info){    
    }
}

I have to write a scheduler class . But I am not getting how to use the csvBlob in the webservise call.
The web service call will be in batch class or in scheduler class. 

thanks in advance.
Account Team Member :

Can I get an update on my Account Team member records add, edit or delete?
I want to call a webservice on change on my account Team. As we cannot write any trigger and if we are using only the standard functionality then how to achieve this??

If there are three apex jobs, and the requirement is after completion of one apex job automatically the second one should start. 

 

How we can achieve this.

on a detail page of opportunity  there is a picklist status with values a,b,c .

 

Question  1:

Opportunity has two related list  rl1, rl2

when  status value is 'a' rl1 should be visible. when status value is 'b'  rl2 should be visible.

 

Question 2:

On Opportunity  some other fields are there x, y z.

when  status value is 'a' x should be readonly. when status value is 'b'  yand z should be readonly.

Hi

I have a pageblock table on a Vf page with a scrollbar.

 

please anybody can help me to fix the header.

 

I know it is possible through java script. So if anybody  can share the javescript with me?

 

Hi, 

 I have a Vf page where i implemented a seach function. I have to display a list values as apageblock table. The limit for a list is 1000 records. When i tried to test for 1000 records. the list is displaying 1000 records but, it is taking too much time  to display the table.around 60  to65 seconds.

 

Is there any way by which i can reduce the loading time? 

 

HI,

 

Under Opportunity i have custom object Role__C.Here if i click on New Role one visual force page will dispaly.i am displaying one field.After entering some value i need save this value under opportunity.But i am getting error as URL No Longer Exists.

 

Can any one guide me...

 

Here is my code..

 

<apex:page controller="TestRole" >
<apex:form >
<apex:pageBlock > <apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>


</apex:pageBlockButtons>
client pin
<apex:inputField value="{!member1.Client_P_N__c}"/>
</apex:pageBlock>

</apex:form>
</apex:page>

 

apex class:

 

public class TestRole
{
public Opportunity opp{get;set;}
public TestRole(ApexPages.StandardSetController controller) {

}
public TestRole(ApexPages.StandardController controller) {
r = new Role__c();
}

Public Id I = ApexPages.CurrentPage().getParameters().get('id');
public Role__c r{ get; set;}
public TestRole()
{
}
public PageReference save() {
insert r;
PageReference customer = new PageReference('/'+ApexPages.CurrentPage().getParameters().get('oppid'));
customer.setRedirect(true);
return customer ;
}
}

 

Thanks...


Hi , I am sending two approval processes  though trigger.

 

When the Status__c of the Record is equal to 'Planning'  Send the 1st Approval process.

 

When Status__c="Pending Approval" send the second approval process.

 

If I want to go from Pending Approval state to again to Planning   I have to recall all the second Approval processes .

 

My code is :

 

 

trigger Submit_Approval_Process on Decision__c (after update) {

for(Decision__c thisdeci: Trigger.new){
Decision__c beforeUpdate = System.Trigger.oldMap.get(thisdeci.Id);
if(thisdeci.Status__c!=beforeUpdate.Status__c){
if( thisdeci.Status__c=='Planning' && thisdeci.Number_of_RACI_members__c >0){

List<Raci__c> allraci=new List<Raci__c>();
allraci=[select id,Name,NameofUser__c,decision__c,Ownerid,Approval_Status__c from Raci__c
where decision__c=:thisdeci.id ];

for(Raci__c r:allraci){
if(r.ownerid!=r.nameofuser__c){
Approval.ProcessSubmitRequest req=new Approval.ProcessSubmitRequest();
req.setComments('Submitting request for approval.');
req.setObjectId(r.id);
Approval.ProcessResult result = Approval.process(req);
System.assert(result.isSuccess());
}
}
}
}



if(thisdeci.Status__c!=beforeUpdate.Status__c){
if(thisdeci.Status__c=='Pending Approval'
&& thisdeci.Number_of_RACI_members__c >0 ){
List<Raci__c> allraci=new List<Raci__c>();
allraci=[select id,Name,Acknowledged__c,Informed__c,NameofUser__c,Approval_Status_on_Final_Decision__c,
decision__c,Approval_Status__c from Raci__c
where decision__c=:thisdeci.id ];

for(Raci__c r:allraci){
if(r.Informed__c==False && r.Approval_Status__c=='Approved/Accepted'){

Approval.ProcessSubmitRequest req1=new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(r.id);
Approval.ProcessResult result = Approval.process(req1);
System.assert(result.isSuccess());
}
}
}
}
}

}

 

Please help me on this, if anybody have an idea.

 

Hi,

  Can any body help me on this. I want to delete the chatterposts automatically with keyword 'Created' or 'Updated'.  This should be a trigger  on chatter feed or anything else? 

 

I have tried on Chatter teed Trigger::: But this is not working . When i created any new record the Chatter post "The Owner has created the Record." chatter post is still there.

 

My code---

 

Trigger delete_Records_with_Created on FeedItem (after insert) {

Feeditem thisf;

for(FeedItem f:Trigger.new){

   thisf=f;

}

String body_text=thisf.body;

if(body_text.contains('created')==true)

delete thisf;

}

 

Please Help me on this ASAP.

 

public class NewRelationship_controller{

public class De_Re_St_DC{------------------------------This is my wrapper class name,But my test method is 
public Boolean isSelected {get;set;}--not covering this class  so not able to cover any other line.
public Strategy__c Strategy {get;set;}
public Decision__c Decision {get;set;}
public RACI__c RACI {get;set;}
public Relationship__c Relation {get;set;}
public User userR {get;set;}
public Account Acc {get;set;}
public Contact con {get;set;}
}



public List<De_Re_St_DC> D_R_S_D{get;set;}
public List<De_Re_St_DC> D_R_S_D_Selected{get;set;}

public Id I = ApexPages.CurrentPage().getParameters().get('id');
public String RecID=I;
public String ObjID=RecID.subString(0,3);

public string searchText {get;set;}
public List<Decision__c> searchDResults {get;set;}
public List<Strategy__c> searchSResults {get;set;}
public List<Raci__c> searchRResults {get;set;}
public List<User> searchUResults {get;set;}
public List<Account> searchAResults {get;set;}
public List<Contact> searchCResults {get;set;}


public Decision__c allDesicion=new decision__c();



public Set<String> selDecisionNames {get;set;}
public Set<String> SelectIds {get;set;}
public Boolean hasSelDecision {get;set;}
public List<Relationship__c> relList1{get;set;}

public String DecID='a06';
public String StrID='a0G';
public String DecColID='a07';
public String UserIDs='005';
public String AccIDs='001';
public String ConIds='003';

public NewRelationship_controller(ApexPages.StandardSetController controller) {}
public NewRelationship_controller(ApexPages.StandardController controller) {}





public Relationship__c r{get;set;}

public NewRelationship_controller(){


r=new Relationship__c();
relList1= new List<Relationship__c>();




D_R_S_D=new List<De_Re_St_DC>();
D_R_S_D_Selected=new List<De_Re_St_DC>();

}




public void displayselected(){

//D_R_S_D_Selected.clear();
for(De_Re_St_DC Obj: D_R_S_D)
if(Obj.isSelected == true)
D_R_S_D_Selected.add(Obj);

}

 

-----------------------------There are more lines of code. 

}

 

 

In my Test class if i Write   -------De_Re_St_DC dr =new De_Re_St_DC();

the getting Error: Compile Error: Invalid type: De_Re_St_DC at line 393 column 26

 

 


Hi,

  I am facing problem in getting emails from tasks. I have written a Trigger which will create a task with "send e" checkbox ticked. If mannually i am creating a task then i am getting the email alerts but  the tasks created through Trigger are not sending any email alert. 

 

Please anybody can help me on this why this happened?

Hi , I am facing problem in having access level "Full Access".

Decision is the Parent object.
RACI is the Child object.

 

On a Decision i can add Different RACI records using a custom buttom "Add New Raci". This opens a Visual force page where i can add Raci records . Each record has a lookup to user i.e. "NameOfUser".

 

There is a Check box on Decision "Raci_Can_add_or_delete_ Other_Members__c." When the Checkbox it True the users added in the RACI on the relaed list Should able to delete other existing records.

 

For Add it is working fine . I have the issue with Delete records. The users have a custom standard profile. (with no "Modify all").

 

Trigger Code:

 

if(r.Approval_Status__c=='Approved/Accepted'
&& thisd.RACI_can_add_or_delete_Other_Members__c==True && r.OwnerId!=r.NameofUser__c ){

RACI__Share RACIShare = new RACI__Share();
RACIShare.ParentId = r.Id;
for(Raci__c rnum:rnumberswithoutnameofuser)
RACIShare.UserOrGroupId = rnum.NameofUser__c;
RACIShare.AccessLevel = 'All';
Insert RACIShare;

}


In the code it is accepting the 'All' but if i made the checkbox is true then the error message is :

 

Error:Apex trigger DecisionShareAndRaciShare caused an unexpected exception, contact your administrator: DecisionShareAndRaciShare: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_ACCESS_LEVEL, : []: Trigger.DecisionShareAndRaciShare: line 86, column 1

 

 

Because the AccessLevel for these user have : Readoly and Read/Write options. No Full Acess is there.

My question is how we can give the Full Access to the users.(we should not modify the profile).

My Issue:

    There is a Custom Object named "Decision__c". On the Decision record there should a inline visula force page. On this page a button should be there named "Add New Members". When this button is clicked, it should open users list and i can select one user and after selecting this this should be added to the Visual force page..Like this One by one users can be added on the Related list.

 

Hi How a image should be a clickable image and it should do some operation on background when ever it is clicked. and update another field on the same object . 

Hi, I am creating an approval process in apex using meta data API. Approval process is getting created , but workflow action reference not able to get the field update. Getting an error - "
Attempt to de-reference a null object".

Below is the code :
public  with sharing class MetadataServiceCall2 {    
    public static void createApprovalProcess1(){
        
        //start creating approval process , 1st make a call out
        String restUrl = 'callout:ApexMDAPI/services/data/v42.0/limits';
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint(restUrl);
        req.setMethod('GET');
        HttpResponse res = h.send(req);
        
        //call the metadata service, 2nd part
        MetadataService.MetadataPort service = new MetadataService.MetadataPort();
        service.SessionHeader = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId = '{!$Credential.OAuthToken}';
        // MetadataService.MetadataPort ms = new MetadataService.createService();
        
        MetadataService.ApprovalProcess approvalProcess = new MetadataService.ApprovalProcess();
        approvalProcess.fullName = 'PDM__c.TestApproval14';
        approvalProcess.label = 'Test Approval14';
        
        MetadataService.ApprovalEntryCriteria entryCriteriaobj = new MetadataService.ApprovalEntryCriteria();
        
        entryCriteriaobj.criteriaItems = new List<MetadataService.FilterItem>();
        MetadataService.FilterItem criteria = new MetadataService.FilterItem();
        criteria.field='PDM__c.Workflow_Name__c';
        criteria.operation='equals';
        criteria.value='UCP:Development:Development:Movies & Minis:Makeover/Format_WF';         
        
        entryCriteriaobj.criteriaItems.add(criteria);
        entryCriteriaobj.booleanFilter='1';
        approvalProcess.entryCriteria =entryCriteriaobj;
        
        approvalProcess.active = false;
        approvalProcess.allowRecall = false;
        approvalProcess.showApprovalHistory = true;
        approvalProcess.recordEditability = 'AdminOnly';
        approvalProcess.finalApprovalRecordLock = false;
        approvalProcess.finalRejectionRecordLock = false;
        approvalProcess.showApprovalHistory = false;        
        
        MetadataService.ApprovalSubmitter submitter = new         MetadataService.ApprovalSubmitter();
        submitter.type_x = 'user';
        submitter.submitter = UserInfo.getUserName();
        
        MetadataService.WorkflowActionReference wfActionReference = new MetadataService.WorkflowActionReference();
        wfActionReference.name='Update_Status_value8';
        wfActionReference.type_x ='FieldUpdate';
        MetadataService.ApprovalAction initialAction = new  MetadataService.ApprovalAction();              
        initialAction.action.add(wfActionReference);
        
        //Add this action to approvalProcess
        approvalProcess.initialSubmissionActions=initialAction;   
        approvalProcess.allowedSubmitters = new List<MetadataService.ApprovalSubmitter> { submitter };
        List<MetadataService.SaveResult> results =service.createMetadata(new MetadataService.Metadata[] { approvalProcess });
        handleSaveResults(results[0]);
    }
    
    
   
    private static void handleSaveResults(MetadataService.SaveResult saveResult){
         
         if(saveResult==null || saveResult.success)
             return;
         // Construct error message and throw an exception
         List<String> messages = new List<String>();
         messages.add((saveResult.errors.size()==1 ? 'Error ' : 'Errors ') + 
                 'occured processing component ' + saveResult.fullName + '.');
        
         for(MetadataService.Error error : saveResult.errors)
             messages.add(error.message + ' (' + error.statusCode + ').' +( error.fields!=null && error.fields.size()>0 ? 
                     ' Fields ' + String.join(error.fields, ',') + '.' : '' ) );
         if(messages.size()>0)
             throw new MetadataServiceExamplesException(String.join(messages, ' '));
     }
    
    public class MetadataServiceExamplesException extends Exception { }
     
}



I am getting error  at below code :
MetadataService.ApprovalAction initialAction = new  MetadataService.ApprovalAction();              
        initialAction.action.add(wfActionReference);

Can anyone please let me know where I am wrong? Why I am getting null pointer error?
As per new summer release , Now the users who are creating site records are no more the record owners. So how to set a default record owner? I am no getting the way to do it. Can any one suggest me? Thanks in advance. 
Hi I am not able to find the solution of the below issue.

I logged in to production , for a record i can see a different record page , while same same record my friend who is logged in using the same login credential, from his laptop, can see a different record page. 

Why i cannot see the same page?


 
Account Team Member :

Can I get an update on my Account Team member records add, edit or delete?
I want to call a webservice on change on my account Team. As we cannot write any trigger and if we are using only the standard functionality then how to achieve this??

on a detail page of opportunity  there is a picklist status with values a,b,c .

 

Question  1:

Opportunity has two related list  rl1, rl2

when  status value is 'a' rl1 should be visible. when status value is 'b'  rl2 should be visible.

 

Question 2:

On Opportunity  some other fields are there x, y z.

when  status value is 'a' x should be readonly. when status value is 'b'  yand z should be readonly.

Hi,

 

I have a requirement to post  some data from SFDC to Secure FTP Server. if anybody have the idea about this please let me know.

 

Thanks In Advance

 

regards

Somes

Hi

I have a pageblock table on a Vf page with a scrollbar.

 

please anybody can help me to fix the header.

 

I know it is possible through java script. So if anybody  can share the javescript with me?

 

Hi, 

 I have a Vf page where i implemented a seach function. I have to display a list values as apageblock table. The limit for a list is 1000 records. When i tried to test for 1000 records. the list is displaying 1000 records but, it is taking too much time  to display the table.around 60  to65 seconds.

 

Is there any way by which i can reduce the loading time? 

 

HI,

 

Under Opportunity i have custom object Role__C.Here if i click on New Role one visual force page will dispaly.i am displaying one field.After entering some value i need save this value under opportunity.But i am getting error as URL No Longer Exists.

 

Can any one guide me...

 

Here is my code..

 

<apex:page controller="TestRole" >
<apex:form >
<apex:pageBlock > <apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>


</apex:pageBlockButtons>
client pin
<apex:inputField value="{!member1.Client_P_N__c}"/>
</apex:pageBlock>

</apex:form>
</apex:page>

 

apex class:

 

public class TestRole
{
public Opportunity opp{get;set;}
public TestRole(ApexPages.StandardSetController controller) {

}
public TestRole(ApexPages.StandardController controller) {
r = new Role__c();
}

Public Id I = ApexPages.CurrentPage().getParameters().get('id');
public Role__c r{ get; set;}
public TestRole()
{
}
public PageReference save() {
insert r;
PageReference customer = new PageReference('/'+ApexPages.CurrentPage().getParameters().get('oppid'));
customer.setRedirect(true);
return customer ;
}
}

 

Thanks...


Hi,

  Can any body help me on this. I want to delete the chatterposts automatically with keyword 'Created' or 'Updated'.  This should be a trigger  on chatter feed or anything else? 

 

I have tried on Chatter teed Trigger::: But this is not working . When i created any new record the Chatter post "The Owner has created the Record." chatter post is still there.

 

My code---

 

Trigger delete_Records_with_Created on FeedItem (after insert) {

Feeditem thisf;

for(FeedItem f:Trigger.new){

   thisf=f;

}

String body_text=thisf.body;

if(body_text.contains('created')==true)

delete thisf;

}

 

Hello Everyone,

I am very new to Salesforce.com, I need to read and write a CSV file using Apex code.

Functionality wants to implement : Read some records using query and write into a excel file and
read a CSV file and insert records into database.
this should be using apex code.

Please help me :)

Thanks