• Amr Mohsen
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 14
    Replies
Hello, 
I've a field in cases called type which is picklist field and I want to copy the value from this field to CaseRecordType my code is 
public class casePatcherController {
    public PageReference UpdateCases(){
        List<Case> cList = [SELECT Type, Sub_Type__c FROM Case];
        for(Case c:cList ){
            Recordtype rec = [SELECT id,Name FROM RecordType Where Name=:c.Type];
            If(rec!=null){
                c.RecordType = rec;
            }
        }
        update cList;
        return null;
    }
}

But I get this error :

List has no rows for assignment to SObject
Error is in expression '{!UpdateCases}' in component <apex:commandButton> in page casepatcher: Class.casePatcherController.UpdateCases: line 5, column 1

I need help please.
Hello, 
I've created a custom controller like below 
public class newTaskForTypeController {
    public TaskForTypes__c typeOfTask;
    public string SelectedTaskId { get; set; }
    public TaskForTypes__c getTaskTypes(){
        if(typeOfTask == null) return new TaskForTypes__c();
        return typeOfTask;
    }
    
    //First page which will contain name 
    public PageReference step1(){
        return Page.Tasks_For_Types1;
    }
    
    //Second page which will contain Sub type name and 
    public PageReference step2(){
        return Page.Tasks_For_Types2;
    } 
    
    //Cancel the operation
    public PageReference cancel(){
        //Navigate to first page
        PageReference tft1 = new ApexPages.StandardController(typeOfTask).view();
        tft1.setRedirect(true);
        return tft1;
    }
    
    //Save method
    public PageReference save(){
        if(typeOfTask == null) typeOfTask = new TaskForTypes__c();
        insert typeOfTask;
        PageReference tft1 = new ApexPages.StandardController(typeOfTask).view();
        tft1.setRedirect(true);
        return null;
    }
    
    //Get cuurent tasks
    public List<TaskForTypes__c> getTypeTasks(){
        List<TaskForTypes__c> tsks = [SELECT Subject__c, Task_Description__c FROM TaskForTypes__c WHERE Sub_Type_Name__c =: typeOfTask.Sub_Type_Name__c];
        return tsks;
    }
    
    //Delete Task from List
    public void DeleteTask()
    {
        // if for any reason we are missing the reference 
        if (SelectedTaskId == null) {
            
            return;
        }
        
        // find the account record within the collection
        TaskForTypes__c tobeDeleted = null;
        for(TaskForTypes__c a : getTypeTasks())
            if (a.Id == SelectedTaskId) {
                tobeDeleted = a;
                break;
            }
        
        //if account record found delete it
        if (tobeDeleted != null) {
            Delete tobeDeleted;
        }
        
        //refresh the data
        getTypeTasks();
    }  
    
    public List<TaskForTypes__c> getUniqueTypes(){
        List<TaskForTypes__c> types = [SELECT Sub_Type_Name__c FROM TaskForTypes__c];
        return types; 
    }
}

and my VF page code is 
<apex:page controller="newTaskForTypeController" tabStyle="TaskForTypes__c" >
    <script>
    function confirmCancel() {
        var isCancel = confirm("Are you sure you wish to cancel?");
        if (isCancel) return true; 
        return false;
    } 
    </script>
    <apex:sectionHeader title="Add New Task Assignment For Types Rule"/>
    <apex:form >
        <apex:pageBlock title="Rule Name" mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save & Next" />
                <apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection >
                   <apex:inputField id="subtype" value="{!typeOfTask.Sub_Type_Name__c}" required="true" />
                
            </apex:pageBlockSection>
         
        </apex:pageBlock>
    </apex:form>  
</apex:page>

I got an error "Unknown property 'newTaskForTypeController.typeOfTask'".

any help please 
Hello, 
I've created apex class like below:
public class newTaskForTypeController {
    TaskForTypes__c taskType;
    
    public TaskForTypes__c getTaskType(){
        if(taskType == null) return new TaskForTypes__c();
        return taskType;
    }
    //First page which will contain name 
    public PageReference step1(){
        return Page.Tasks_For_Types1;
    }
    
    //Second page which will contain Sub type name and 
    public PageReference step2(){
        return Page.Tasks_For_Types2;
    }
    
    //Cancel the operation
    public PageReference cancel(){
        //Navigate to first page
        PageReference tft1 = new ApexPages.StandardController(taskType).view();
        tft1.setRedirect(true);
        return tft1;
    }
    
    //Save method
    public PageReference save(){
        insert taskType;
        PageReference tft1 = new ApexPages.StandardController(taskType).view();
        tft1.setRedirect(true);
        return tft1;
    }
}

And VF page code is :
<apex:page standardController="newTaskForTypeController" tabStyle="TaskForTypes__c" >
    <script>
    function confirmCancel() {
        var isCancel = confirm("Are you sure you wish to cancel?");
        if (isCancel) return true; 
        return false;
    } 
    </script>
    <apex:sectionHeader title="Add New Task Assignment For Types Rule"/>
    <apex:form>
        <apex:pageBlock title="Rule Name" mode="edit">
            <apex:pageBlockButtons>
            <apex:commandButton action="{!step2}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>  
</apex:page>

Why I get this error message ==>> "newTaskForTypeController does not exist" ??
Hello, 
I want to create and embed VF page iniside Case page to display all similar cases which have the same type and subtype for current case, but I want to send Type and sub stype as parameters to embed VF page to display similar cases based on those parameters? 
I need help please.
Hello, 
I'm trying to update values in case when a task is created inside it, I want to update string value 'Case Status' and increase numeric field by one

My Code is 
 
trigger CreatTask on Task (after insert) {
 
    List<Case>  cList = new List<Case>();
    for(Task t: Trigger.new) {
        If(t.whatId.getsObjectType() == Case.sObjectType){
            Case c = new Case();
            c.Id = t.whatId;
            if(t.Status == 'Opened'){
            c.Status = 'In Progress';
            c.Open_Tasks__c = Integer.valueOf(c.Open_Tasks__c) + 1;
            cList.add(c); 
            }
          
        }
    }
    
    if(!cList.isEmpty())
        update cList;
    
}

But i got error 

caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.OnTaskAdded: line 6, column 1
Hello, 
Can I create .net pages and link it to salesforce environment?  I want to create a page like visualforce page but with .net code behind , is that possible ? 
Hello, 
I need to change Case status After adding task to that case 

My Code is 
trigger OnTaskAdded on Task (before insert) {
    try{
        Task insertedTask = trigger.new[0];
        Case caseToUpdate = insertedTask.What;
        caseToUpdate.Status = 'In Progress';
        update caseToUpdate;
    }catch(DmlException e) {
        
        System.debug('An unexpected error has occurred: ' + e.getMessage());
        
    }
}

But I get the following error when I try to add new task

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger OnTaskAdded caused an unexpected exception, contact your administrator: OnTaskAdded: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.OnTaskAdded: line 6, column 1


I need help please.
Hello , 
I want to create an Apex trigger when I create a task, It updates a field in related case , and also when I close that task , It also modified that field, and since the related object for the task may be either opportunity or case, I don't know how to do that.
I need help please.

Thank you so much.
Hello, 
I'm new to salesforce development , I'm wondring if I can use apex code in existing page such cases, leads and so on ? Or Apex code only for custom visulforce page ? and  if it possible how can I do this ?
Hello,
I've a schema called ESCALATION  which has fields [Type, Subtype, EscalationTime] and acts as Many To many relationship between TYPE schema ans SUBTYPE schema, I created custom lookup field which contains all TYPE data in Cases page . I want to create another lookup field that displays SUBTYPE based on relationship.

If I represent it in SQL statement it will be : "SELECT SubType FROM ESCALATION  WHERE Type = ' Types lookup field value'" 
Hello, 
I want to create visualforce page for my custom schema, 
I created a page but I can't edit data that entered through that page, I created a tab for custom object to display my page but actually It shows only mandatory fields only based ob schema structure, and when I try to create a visualforce tabs I can't edit my data.
I need to know how to created visualforce page for custom schema and then display this page in a tab and be able to edit data.
Really I need help, I'm .net developer and struggling to develop in salesforce.
Thanks in advance 
Hello, 
I've a field in cases called type which is picklist field and I want to copy the value from this field to CaseRecordType my code is 
public class casePatcherController {
    public PageReference UpdateCases(){
        List<Case> cList = [SELECT Type, Sub_Type__c FROM Case];
        for(Case c:cList ){
            Recordtype rec = [SELECT id,Name FROM RecordType Where Name=:c.Type];
            If(rec!=null){
                c.RecordType = rec;
            }
        }
        update cList;
        return null;
    }
}

But I get this error :

List has no rows for assignment to SObject
Error is in expression '{!UpdateCases}' in component <apex:commandButton> in page casepatcher: Class.casePatcherController.UpdateCases: line 5, column 1

I need help please.
Hello, 
I've created apex class like below:
public class newTaskForTypeController {
    TaskForTypes__c taskType;
    
    public TaskForTypes__c getTaskType(){
        if(taskType == null) return new TaskForTypes__c();
        return taskType;
    }
    //First page which will contain name 
    public PageReference step1(){
        return Page.Tasks_For_Types1;
    }
    
    //Second page which will contain Sub type name and 
    public PageReference step2(){
        return Page.Tasks_For_Types2;
    }
    
    //Cancel the operation
    public PageReference cancel(){
        //Navigate to first page
        PageReference tft1 = new ApexPages.StandardController(taskType).view();
        tft1.setRedirect(true);
        return tft1;
    }
    
    //Save method
    public PageReference save(){
        insert taskType;
        PageReference tft1 = new ApexPages.StandardController(taskType).view();
        tft1.setRedirect(true);
        return tft1;
    }
}

And VF page code is :
<apex:page standardController="newTaskForTypeController" tabStyle="TaskForTypes__c" >
    <script>
    function confirmCancel() {
        var isCancel = confirm("Are you sure you wish to cancel?");
        if (isCancel) return true; 
        return false;
    } 
    </script>
    <apex:sectionHeader title="Add New Task Assignment For Types Rule"/>
    <apex:form>
        <apex:pageBlock title="Rule Name" mode="edit">
            <apex:pageBlockButtons>
            <apex:commandButton action="{!step2}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>  
</apex:page>

Why I get this error message ==>> "newTaskForTypeController does not exist" ??
Hello, 
I want to create and embed VF page iniside Case page to display all similar cases which have the same type and subtype for current case, but I want to send Type and sub stype as parameters to embed VF page to display similar cases based on those parameters? 
I need help please.
Hello, 
I need to change Case status After adding task to that case 

My Code is 
trigger OnTaskAdded on Task (before insert) {
    try{
        Task insertedTask = trigger.new[0];
        Case caseToUpdate = insertedTask.What;
        caseToUpdate.Status = 'In Progress';
        update caseToUpdate;
    }catch(DmlException e) {
        
        System.debug('An unexpected error has occurred: ' + e.getMessage());
        
    }
}

But I get the following error when I try to add new task

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger OnTaskAdded caused an unexpected exception, contact your administrator: OnTaskAdded: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.OnTaskAdded: line 6, column 1


I need help please.
Hello,
I've a schema called ESCALATION  which has fields [Type, Subtype, EscalationTime] and acts as Many To many relationship between TYPE schema ans SUBTYPE schema, I created custom lookup field which contains all TYPE data in Cases page . I want to create another lookup field that displays SUBTYPE based on relationship.

If I represent it in SQL statement it will be : "SELECT SubType FROM ESCALATION  WHERE Type = ' Types lookup field value'"